{"version":3,"file":"request-user-approval.cjs","sourceRoot":"","sources":["../../../src/methods/hooks/request-user-approval.ts"],"names":[],"mappings":";;;AACA,gDAA+C;AAG/C,iDAA6E;AAS7E;;;;;;;;;;;GAWG;AACH,QAAQ,CAAC,CAAC,iCAAiC,CAAC,EAC1C,IAAI,EACJ,WAAW,EAAE,EAAE,EAAE,EAAE,GACO;IAC1B,MAAM,IAAA,aAAG,EAAC,IAAA,oBAAY,EAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAEtC,2EAA2E;IAC3E,mDAAmD;IACnD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAA,cAAI,EAAC,wBAAgB,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,IAAA,aAAG,EAAC,IAAA,sBAAc,GAAE,CAAC,CAAC;IAE5B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,oCAAoC,CAAC,OAAwB;IAC3E,OAAO,KAAK,EACV,GAAG,IAA0D,EAC7D,EAAE;QACF,OAAO,MAAM,OAAO,CAClB,iCAAiC,EACjC,GAAG,IAAI,CACR,CAAC,SAAS,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC;AATD,oFASC","sourcesContent":["import type { SagaIterator } from 'redux-saga';\nimport { put, take } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { resolveInterface, setInterface, closeInterface } from '../../store';\n\ntype RequestUserApprovalParams = {\n  type: string;\n  requestData: {\n    id: string;\n  };\n};\n\n/**\n * Show a dialog to the user. This will wait for `resolveUserInterface` to be\n * dispatched before returning.\n *\n * @param opts - The options for the request.\n * @param opts.type - The type of dialog to show.\n * @param opts.requestData - The data to display in the dialog.\n * @param opts.requestData.id - The ID of the interface.\n * @yields Sets the dialog in the store, waits for the user to resolve the\n * dialog, and closes the dialog.\n * @returns The result of the dialog.\n */\nfunction* requestUserApprovalImplementation({\n  type,\n  requestData: { id },\n}: RequestUserApprovalParams): SagaIterator<unknown> {\n  yield put(setInterface({ type, id }));\n\n  // We use `take` to wait for `resolveUserInterface` to be dispatched, which\n  // indicates that the user has resolved the dialog.\n  const { payload } = yield take(resolveInterface.type);\n  yield put(closeInterface());\n\n  return payload;\n}\n\n/**\n * Get the implementation of the `requestUserApproval` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `requestUserApproval` hook.\n */\nexport function getRequestUserApprovalImplementation(runSaga: RunSagaFunction) {\n  return async (\n    ...args: Parameters<typeof requestUserApprovalImplementation>\n  ) => {\n    return await runSaga(\n      requestUserApprovalImplementation,\n      ...args,\n    ).toPromise();\n  };\n}\n"]}