@oneblink/apps-react 8.10.1 → 8.11.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,11 +26,7 @@ function DownloadableFiles({ formSubmissionResult, divider, layout, }) {
|
|
26
26
|
filename: submissionPDFFileName,
|
27
27
|
signedUrl: formSubmissionResult.downloadSubmissionPdfUrl,
|
28
28
|
contentType: 'application/pdf',
|
29
|
-
}, className: "cypress-receipt-download-pdf-button" })), [
|
30
|
-
formSubmissionResult.downloadSubmissionPdfUrl,
|
31
|
-
formSubmissionResult.definition,
|
32
|
-
submissionPDFFileName,
|
33
|
-
]);
|
29
|
+
}, className: "cypress-receipt-download-pdf-button" })), [formSubmissionResult.downloadSubmissionPdfUrl, submissionPDFFileName]);
|
34
30
|
if (!formSubmissionResult.attachmentsAccessToken && !pdfFileNode) {
|
35
31
|
return null;
|
36
32
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/downloadable-files/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAEL,mBAAmB,EACnB,WAAW,GACZ,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,cAAc,EAAc,MAAM,kBAAkB,CAAA;AAE7D,SAAS,iBAAiB,CAAC,EACzB,oBAAoB,EACpB,OAAO,EACP,MAAM,GAYP;IACC,MAAM,qBAAqB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QAC/C,MAAM,cAAc,GAClB,MAAA,MAAA,oBAAoB,CAAC,UAAU,CAAC,qBAAqB,0CAAE,gBAAgB,0CACnE,WAAW,CAAA;QACjB,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO,YAAY,CAAA;QACrB,CAAC;QAED,OAAO,mBAAmB,CAAC,sCAAsC,CAC/D,cAAc,EACd;YACE,kBAAkB,EAChB,oBAAoB,CAAC,gCAAgC;YACvD,IAAI,EAAE,oBAAoB,CAAC,UAAU;YACrC,UAAU,EAAE,oBAAoB,CAAC,UAAU;YAC3C,YAAY,EAAE,oBAAoB,CAAC,YAAY,IAAI,EAAE;YACrD,mBAAmB,EAAE,oBAAoB,CAAC,mBAAmB,IAAI,EAAE;YACnE,UAAU,EAAE,oBAAoB,CAAC,UAAU,IAAI,SAAS;YACxD,WAAW,EAAE,WAAW,CAAC,cAAc,EAAE,IAAI,SAAS;YACtD,IAAI,EAAE,MAAA,oBAAoB,CAAC,cAAc,0CAAE,IAAI;YAC/C,SAAS,EAAE,MAAA,oBAAoB,CAAC,cAAc,0CAAE,SAAS;YACzD,iBAAiB,EACf,MAAA,oBAAoB,CAAC,cAAc,0CAAE,iBAAiB;SACzD,CACF,CAAC,IAAI,CAAA;IACR,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAA;IAE1B,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAC/B,GAAG,EAAE,CACH,CAAC,oBAAoB,CAAC,wBAAwB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAC3D,oBAAC,iBAAiB,IAChB,UAAU,EAAE;YACV,QAAQ,EAAE,qBAAqB;YAC/B,SAAS,EAAE,oBAAoB,CAAC,wBAAwB;YACxD,WAAW,EAAE,iBAAiB;SAC/B,EACD,SAAS,EAAC,qCAAqC,GAC/C,CACH,EACH
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/downloadable-files/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAEL,mBAAmB,EACnB,WAAW,GACZ,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,uBAAuB,CAAA;AAC9B,OAA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wBAAwB;YACxD,WAAW,EAAE,iBAAiB;SAC/B,EACD,SAAS,EAAC,qCAAqC,GAC/C,CACH,EACH,CAAC,oBAAoB,CAAC,wBAAwB,EAAE,qBAAqB,CAAC,CACvE,CAAA;IAED,IAAI,CAAC,oBAAoB,CAAC,sBAAsB,IAAI,CAAC,WAAW,EAAE,CAAC;QACjE,OAAO,IAAI,CAAA;IACb,CAAC;IAED,OAAO,CACL,6BAAK,SAAS,EAAC,gCAAgC;QAC7C,oBAAC,cAAc,IAAC,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,MAAM;YACrC,OAAO,IAAI,4BAAI,SAAS,EAAC,SAAS,GAAG;YACrC,WAAW,IAAI,CAAC,oBAAoB,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAC7D,oBAAC,cAAc,QAAE,WAAW,CAAkB,CAC/C,CAAC,CAAC,CAAC,CACF,oBAAC,yBAAyB,IACxB,oBAAoB,EAAE,oBAAoB,EAC1C,WAAW,EAAE,WAAW,GACxB,CACH,CACc,CACb,CACP,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport {\n submissionService,\n localisationService,\n authService,\n} from '@oneblink/apps'\nimport {\n OnlyPDFDisplay,\n LoadAndDisplayAttachments,\n SingleFileDisplay,\n} from './resource-components'\nimport { LayoutProvider, LayoutType } from './LayoutProvider'\n\nfunction DownloadableFiles({\n formSubmissionResult,\n divider,\n layout,\n}: {\n /** The form submission with the pdf and/or attachments config on it. */\n formSubmissionResult: submissionService.FormSubmissionResult\n /** Whether to render a divider above the content. */\n divider?: boolean\n /**\n * The layout to use for the downloadable files. Options are `GRID` and\n * `LIST`. Defaults to `GRID`. `GRID` will render files next to each other at\n * some screen sizes. `LIST` will always render each file on a new line.\n */\n layout?: LayoutType\n}) {\n const submissionPDFFileName = React.useMemo(() => {\n const customFileName =\n formSubmissionResult.definition.postSubmissionReceipt?.allowPDFDownload\n ?.pdfFileName\n if (!customFileName) {\n return 'Submission'\n }\n\n return localisationService.replaceInjectablesWithSubmissionValues(\n customFileName,\n {\n previousApprovalId:\n formSubmissionResult.previousFormSubmissionApprovalId,\n form: formSubmissionResult.definition,\n submission: formSubmissionResult.submission,\n submissionId: formSubmissionResult.submissionId || '',\n submissionTimestamp: formSubmissionResult.submissionTimestamp || '',\n externalId: formSubmissionResult.externalId || undefined,\n userProfile: authService.getUserProfile() || undefined,\n task: formSubmissionResult.taskCompletion?.task,\n taskGroup: formSubmissionResult.taskCompletion?.taskGroup,\n taskGroupInstance:\n formSubmissionResult.taskCompletion?.taskGroupInstance,\n },\n ).text\n }, [formSubmissionResult])\n\n const pdfFileNode = React.useMemo(\n () =>\n !formSubmissionResult.downloadSubmissionPdfUrl ? undefined : (\n <SingleFileDisplay\n attachment={{\n filename: submissionPDFFileName,\n signedUrl: formSubmissionResult.downloadSubmissionPdfUrl,\n contentType: 'application/pdf',\n }}\n className=\"cypress-receipt-download-pdf-button\"\n />\n ),\n [formSubmissionResult.downloadSubmissionPdfUrl, submissionPDFFileName],\n )\n\n if (!formSubmissionResult.attachmentsAccessToken && !pdfFileNode) {\n return null\n }\n\n return (\n <div className=\"ob-downloadable-files__wrapper\">\n <LayoutProvider layout={layout ?? 'GRID'}>\n {divider && <hr className=\"divider\" />}\n {pdfFileNode && !formSubmissionResult.attachmentsAccessToken ? (\n <OnlyPDFDisplay>{pdfFileNode}</OnlyPDFDisplay>\n ) : (\n <LoadAndDisplayAttachments\n formSubmissionResult={formSubmissionResult}\n pdfFileNode={pdfFileNode}\n />\n )}\n </LayoutProvider>\n </div>\n )\n}\n\n/**\n * Component for rendering post-submission downloadable files such as PDFs and\n * attachments. The only thing required is the `formSubmissionResult`.\n *\n * It is also recommended to import the `css` from this library as well.\n *\n * ```js\n * import { DownloadableFiles } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n * ```\n *\n * #### Example\n *\n * ```tsx\n * import React from 'react'\n * import ReactDOM from 'react-dom'\n * import { DownloadableFiles } from '@oneblink/apps-react'\n * import '@oneblink/apps-react/dist/styles.css'\n *\n * function SubmissionContainer() {\n *\n * const [state, setState] = useState(null)\n *\n * const handleSubmit = React.useCallback(async () => {\n * ...\n * setState(result)\n * }, [])\n *\n * return (\n * <div>\n * ...\n * {state && (\n * <DownloadableFiles formSubmissionResult={state} />\n * )}\n * </div>\n * )\n * }\n *\n * function App() {\n * return (\n * <IsOfflineContextProvider>\n * <SubmissionContainer />\n * </IsOfflineContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport default React.memo(DownloadableFiles)\n"]}
|
package/dist/hooks/useDrafts.js
CHANGED
@@ -51,7 +51,7 @@ isDraftsEnabled,
|
|
51
51
|
children, }) {
|
52
52
|
const isMounted = useIsMounted();
|
53
53
|
const isOffline = useIsOffline();
|
54
|
-
const {
|
54
|
+
const { isUsingFormsKey } = useAuth();
|
55
55
|
const [syncState, setSyncState] = React.useState({
|
56
56
|
lastSyncTime: null,
|
57
57
|
isSyncing: false,
|
@@ -64,7 +64,7 @@ children, }) {
|
|
64
64
|
}));
|
65
65
|
}, []);
|
66
66
|
const syncDrafts = React.useCallback(async (abortSignal) => {
|
67
|
-
if (!isDraftsEnabled ||
|
67
|
+
if (!isDraftsEnabled || isUsingFormsKey) {
|
68
68
|
return;
|
69
69
|
}
|
70
70
|
if (isMounted.current) {
|
@@ -92,7 +92,7 @@ children, }) {
|
|
92
92
|
syncError: newError,
|
93
93
|
});
|
94
94
|
}
|
95
|
-
}, [formsAppId, isDraftsEnabled,
|
95
|
+
}, [formsAppId, isDraftsEnabled, isMounted, isUsingFormsKey]);
|
96
96
|
const [drafts, setDrafts] = React.useState(null);
|
97
97
|
const deleteDraft = React.useCallback((draftId) => {
|
98
98
|
return draftService.deleteDraft(draftId, formsAppId);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useDrafts.js","sourceRoot":"","sources":["../../src/hooks/useDrafts.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAyBzC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,CACvC,SAAS,CACV,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,qBAAqB,CAAC;AACpC,yEAAyE;AACzE,UAAU;AACV;;;GAGG;AACH,eAAe;AACf,kCAAkC;AAClC,QAAQ,GAKT;IACC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,EAAE,
|
1
|
+
{"version":3,"file":"useDrafts.js","sourceRoot":"","sources":["../../src/hooks/useDrafts.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAyBzC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,CACvC,SAAS,CACV,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,UAAU,qBAAqB,CAAC;AACpC,yEAAyE;AACzE,UAAU;AACV;;;GAGG;AACH,eAAe;A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A;YACvB,8BAA8B,EAAE,CAAA;YAChC,wBAAwB,EAAE,CAAA;QAC5B,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA;YAC7C,UAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;YAClC,OAAO,GAAG,EAAE;gBACV,eAAe,CAAC,KAAK,EAAE,CAAA;YACzB,CAAC,CAAA;QACH,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAA;IAE3B,OAAO,CACL,oBAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,QAAQ,CAA0B,CAC1E,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;IAC7C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,4FAA4F,CAC7F,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import * as React from 'react'\nimport { draftService, submissionService } from '@oneblink/apps'\nimport useAuth from './useAuth'\nimport useIsMounted from './useIsMounted'\nimport useIsOffline from './useIsOffline'\n\n/** The value returned from `useDrafts()` hook */\nexport type DraftsContextValue = {\n /** `true` if drafts are currently loading for the first time. */\n isLoading: boolean\n /** The incomplete submissions that were saved for later */\n drafts: draftService.LocalFormSubmissionDraft[]\n /** `true` drafts are syncing with other devices */\n isSyncing: boolean\n /**\n * The date when the sync process last completed successfully, will be `null`\n * until it has completed the first time.\n */\n lastSyncTime: Date | null\n /** A function to trigger syncing of the drafts */\n syncDrafts: (abortSignal: AbortSignal | undefined) => Promise<void>\n /** An Error object if syncing drafts fails */\n syncError: Error | null\n /** A function to clear Error object from syncing drafts */\n clearSyncError: () => void\n /** A function to remove a draft */\n deleteDraft: (formSubmissionDraftId: string) => Promise<void>\n}\n\nconst DraftsContext = React.createContext<DraftsContextValue | undefined>(\n undefined,\n)\n\n/**\n * React Component that provides the context for the `useDrafts()` hook to be\n * used by components further down your component tree. **It should only be\n * included in your component tree once and ideally at the root of the\n * application.**\n *\n * #### Example\n *\n * ```jsx\n * import * as React from 'react'\n * import { DraftsContextProvider, useDrafts } from '@oneblink/apps-react'\n *\n * function Component() {\n * const draftsContext = useDrafts()\n * // use drafts here\n * }\n *\n * function App() {\n * return (\n * <DraftsContextProvider>\n * <Component />\n * </DraftsContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function DraftsContextProvider({\n /** The identifier for the forms app associated with the user's drafts */\n formsAppId,\n /**\n * `true` if drafts are enabled, otherwise `false`. Can be used for account\n * tier validation.\n */\n isDraftsEnabled,\n /** Your application components */\n children,\n}: {\n formsAppId: number\n isDraftsEnabled: boolean\n children: React.ReactNode\n}) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n const { isUsingFormsKey } = useAuth()\n\n const [syncState, setSyncState] = React.useState<{\n lastSyncTime: Date | null\n isSyncing: boolean\n syncError: Error | null\n }>({\n lastSyncTime: null,\n isSyncing: false,\n syncError: null,\n })\n const clearSyncError = React.useCallback(() => {\n setSyncState((currentState) => ({\n ...currentState,\n syncError: null,\n }))\n }, [])\n const syncDrafts = React.useCallback(\n async (abortSignal: AbortSignal | undefined) => {\n if (!isDraftsEnabled || isUsingFormsKey) {\n return\n }\n\n if (isMounted.current) {\n setSyncState((currentState) => ({\n ...currentState,\n isSyncing: true,\n syncError: null,\n }))\n }\n\n let newError = null\n\n try {\n await draftService.syncDrafts({\n formsAppId,\n throwError: true,\n abortSignal,\n })\n } catch (error) {\n newError = error as Error\n }\n\n if (isMounted.current) {\n setSyncState({\n lastSyncTime: new Date(),\n isSyncing: false,\n syncError: newError,\n })\n }\n },\n [formsAppId, isDraftsEnabled, isMounted, isUsingFormsKey],\n )\n\n const [drafts, setDrafts] = React.useState<\n draftService.LocalFormSubmissionDraft[] | null\n >(null)\n\n const deleteDraft = React.useCallback(\n (draftId) => {\n return draftService.deleteDraft(draftId, formsAppId)\n },\n [formsAppId],\n )\n\n const value = React.useMemo<DraftsContextValue>(\n () => ({\n // Sync\n syncDrafts,\n isSyncing: syncState.isSyncing,\n syncError: syncState.syncError,\n lastSyncTime: syncState.lastSyncTime,\n clearSyncError,\n // Load\n isLoading: !drafts,\n drafts: drafts || [],\n // Delete,\n deleteDraft,\n }),\n [\n syncDrafts,\n syncState.isSyncing,\n syncState.syncError,\n syncState.lastSyncTime,\n clearSyncError,\n drafts,\n deleteDraft,\n ],\n )\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const unregisterPendingQueueListener =\n submissionService.registerPendingQueueListener(() =>\n syncDrafts(undefined),\n )\n const unregisterDraftsListener =\n draftService.registerDraftsListener(setDrafts)\n return () => {\n abortController.abort()\n unregisterPendingQueueListener()\n unregisterDraftsListener()\n }\n }, [syncDrafts])\n\n React.useEffect(() => {\n if (!isOffline) {\n const abortController = new AbortController()\n syncDrafts(abortController.signal)\n return () => {\n abortController.abort()\n }\n }\n }, [isOffline, syncDrafts])\n\n return (\n <DraftsContext.Provider value={value}>{children}</DraftsContext.Provider>\n )\n}\n\n/**\n * React hook to get the context value for Drafts. Will throw an Error if used\n * outside of the `<DraftsContextProvider />` component.\n *\n * @returns\n * @group Hooks\n */\nexport default function useDrafts(): DraftsContextValue {\n const value = React.useContext(DraftsContext)\n if (!value) {\n throw new Error(\n `\"useDrafts\" hook was used outside of the \"<DraftsContextProvider />\" component's children.`,\n )\n }\n return value\n}\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@oneblink/apps-react",
|
3
3
|
"description": "Helper functions for OneBlink apps in ReactJS.",
|
4
|
-
"version": "8.
|
4
|
+
"version": "8.11.0-beta.1",
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
6
6
|
"bugs": {
|
7
7
|
"url": "https://github.com/oneblink/apps-react/issues"
|
@@ -48,7 +48,7 @@
|
|
48
48
|
"@mui/lab": "^5.0.0-alpha.152",
|
49
49
|
"@mui/material": "^5.15.6",
|
50
50
|
"@mui/x-date-pickers": "^6.20.2",
|
51
|
-
"@oneblink/apps": "^23.
|
51
|
+
"@oneblink/apps": "^23.4.0-beta.1",
|
52
52
|
"@oneblink/release-cli": "^3.4.0-beta.1",
|
53
53
|
"@oneblink/types": "github:oneblink/types",
|
54
54
|
"@types/blueimp-load-image": "^5.16.6",
|