@oneblink/apps-react 4.0.0-beta.6 → 4.0.0-beta.7
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.
- package/dist/OneBlinkAutoSaveForm.d.ts +1 -0
- package/dist/OneBlinkAutoSaveForm.js +1 -0
- package/dist/OneBlinkAutoSaveForm.js.map +1 -1
- package/dist/OneBlinkForm.d.ts +2 -0
- package/dist/OneBlinkForm.js +2 -0
- package/dist/OneBlinkForm.js.map +1 -1
- package/dist/OneBlinkReadOnlyForm.d.ts +1 -0
- package/dist/OneBlinkReadOnlyForm.js +1 -0
- package/dist/OneBlinkReadOnlyForm.js.map +1 -1
- package/dist/PaymentReceipt.d.ts +4 -0
- package/dist/PaymentReceipt.js +4 -0
- package/dist/PaymentReceipt.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreColumnsButton.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreColumnsButton.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreColumnsButton.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreDownloadButton.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreDownloadButton.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreDownloadButton.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreProvider.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreProvider.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreProvider.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreRefreshButton.d.ts +5 -0
- package/dist/components/formStore/OneBlinkFormStoreRefreshButton.js +5 -0
- package/dist/components/formStore/OneBlinkFormStoreRefreshButton.js.map +1 -1
- package/dist/components/formStore/OneBlinkFormStoreTable.d.ts +4 -0
- package/dist/components/formStore/OneBlinkFormStoreTable.js +4 -0
- package/dist/components/formStore/OneBlinkFormStoreTable.js.map +1 -1
- package/dist/components/pickers/V4CompatibleDatePicker.d.ts +5 -0
- package/dist/components/pickers/V4CompatibleDatePicker.js +5 -0
- package/dist/components/pickers/V4CompatibleDatePicker.js.map +1 -1
- package/dist/components/pickers/V4CompatibleDateTimePicker.d.ts +5 -0
- package/dist/components/pickers/V4CompatibleDateTimePicker.js +5 -0
- package/dist/components/pickers/V4CompatibleDateTimePicker.js.map +1 -1
- package/dist/components/pickers/V4CompatibleTimePicker.d.ts +5 -0
- package/dist/components/pickers/V4CompatibleTimePicker.js +5 -0
- package/dist/components/pickers/V4CompatibleTimePicker.js.map +1 -1
- package/dist/components/renderer/ProgressBar.d.ts +5 -0
- package/dist/components/renderer/ProgressBar.js +5 -0
- package/dist/components/renderer/ProgressBar.js.map +1 -1
- package/dist/hooks/useAuth.d.ts +3 -1
- package/dist/hooks/useAuth.js +3 -1
- package/dist/hooks/useAuth.js.map +1 -1
- package/dist/hooks/useBooleanState.d.ts +1 -0
- package/dist/hooks/useBooleanState.js +1 -0
- package/dist/hooks/useBooleanState.js.map +1 -1
- package/dist/hooks/useClickOutsideElement.d.ts +1 -0
- package/dist/hooks/useClickOutsideElement.js +1 -0
- package/dist/hooks/useClickOutsideElement.js.map +1 -1
- package/dist/hooks/useDrafts.d.ts +3 -1
- package/dist/hooks/useDrafts.js +3 -1
- package/dist/hooks/useDrafts.js.map +1 -1
- package/dist/hooks/useFormSubmissionAutoSaveState.d.ts +1 -0
- package/dist/hooks/useFormSubmissionAutoSaveState.js +1 -0
- package/dist/hooks/useFormSubmissionAutoSaveState.js.map +1 -1
- package/dist/hooks/useFormSubmissionState.d.ts +1 -0
- package/dist/hooks/useFormSubmissionState.js +1 -0
- package/dist/hooks/useFormSubmissionState.js.map +1 -1
- package/dist/hooks/useIsMounted.d.ts +1 -0
- package/dist/hooks/useIsMounted.js +1 -0
- package/dist/hooks/useIsMounted.js.map +1 -1
- package/dist/hooks/useIsOffline.d.ts +5 -0
- package/dist/hooks/useIsOffline.js +5 -0
- package/dist/hooks/useIsOffline.js.map +1 -1
- package/dist/hooks/useLoadDataState.d.ts +2 -0
- package/dist/hooks/useLoadDataState.js +2 -0
- package/dist/hooks/useLoadDataState.js.map +1 -1
- package/dist/hooks/useLogin.d.ts +4 -2
- package/dist/hooks/useLogin.js +1 -0
- package/dist/hooks/useLogin.js.map +1 -1
- package/dist/hooks/useNullableState.d.ts +2 -0
- package/dist/hooks/useNullableState.js +2 -0
- package/dist/hooks/useNullableState.js.map +1 -1
- package/dist/hooks/usePendingSubmissions.d.ts +9 -1
- package/dist/hooks/usePendingSubmissions.js +17 -14
- package/dist/hooks/usePendingSubmissions.js.map +1 -1
- package/dist/hooks/useSignUp.d.ts +5 -0
- package/dist/hooks/useSignUp.js +5 -0
- package/dist/hooks/useSignUp.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
@@ -8,16 +8,7 @@ const defaultState = {
|
|
8
8
|
loadError: null,
|
9
9
|
pendingSubmissions: [],
|
10
10
|
};
|
11
|
-
const PendingSubmissionsContext = React.createContext(
|
12
|
-
...defaultState,
|
13
|
-
reloadPendingSubmissions: () => { },
|
14
|
-
processPendingQueue: () => { },
|
15
|
-
deletePendingSubmission: () => { },
|
16
|
-
isProcessingPendingQueue: false,
|
17
|
-
isShowingFailedNotification: false,
|
18
|
-
hideFailedNotification: () => { },
|
19
|
-
isShowingSuccessNotification: false,
|
20
|
-
});
|
11
|
+
const PendingSubmissionsContext = React.createContext(undefined);
|
21
12
|
/**
|
22
13
|
* React Component that provides the context for the `usePendingSubmissions()`
|
23
14
|
* hook to be used by components further down your component tree. **It should
|
@@ -28,7 +19,10 @@ const PendingSubmissionsContext = React.createContext({
|
|
28
19
|
*
|
29
20
|
* ```jsx
|
30
21
|
* import * as React from 'react'
|
31
|
-
* import {
|
22
|
+
* import {
|
23
|
+
* PendingSubmissionsContextProvider,
|
24
|
+
* usePendingSubmissions,
|
25
|
+
* } from '@oneblink/apps-react'
|
32
26
|
*
|
33
27
|
* function Component() {
|
34
28
|
* const pendingSubmissionsContext = usePendingSubmissions()
|
@@ -56,12 +50,15 @@ const PendingSubmissionsContext = React.createContext({
|
|
56
50
|
* @returns
|
57
51
|
* @group Components
|
58
52
|
*/
|
59
|
-
export function PendingSubmissionsContextProvider({ isPendingQueueEnabled, successNotificationTimeoutMs =
|
53
|
+
export function PendingSubmissionsContextProvider({ isPendingQueueEnabled, successNotificationTimeoutMs = 5000, children, }) {
|
60
54
|
const isMounted = useIsMounted();
|
61
55
|
const isOffline = useIsOffline();
|
62
56
|
// Using a number as state so we can reset the timer used to close
|
63
57
|
// the snack bar each time a pending queue item is processed
|
64
58
|
const [submittedNotificationCount, setSubmittedNotificationCount] = React.useState(0);
|
59
|
+
const hideSuccessNotification = React.useCallback(() => {
|
60
|
+
setSubmittedNotificationCount(0);
|
61
|
+
}, []);
|
65
62
|
const [isShowingFailedNotification, showFailedNotification, hideFailedNotification,] = useBooleanState(false);
|
66
63
|
const [isProcessingPendingQueue, setIsProcessingPendingQueue] = React.useState(false);
|
67
64
|
const [state, setState] = React.useState(defaultState);
|
@@ -147,13 +144,17 @@ export function PendingSubmissionsContextProvider({ isPendingQueueEnabled, succe
|
|
147
144
|
React.useEffect(() => {
|
148
145
|
if (submittedNotificationCount > 0) {
|
149
146
|
const timeoutId = setTimeout(() => {
|
150
|
-
|
147
|
+
hideSuccessNotification();
|
151
148
|
}, successNotificationTimeoutMs);
|
152
149
|
return () => {
|
153
150
|
clearTimeout(timeoutId);
|
154
151
|
};
|
155
152
|
}
|
156
|
-
}, [
|
153
|
+
}, [
|
154
|
+
hideSuccessNotification,
|
155
|
+
submittedNotificationCount,
|
156
|
+
successNotificationTimeoutMs,
|
157
|
+
]);
|
157
158
|
const value = React.useMemo(() => ({
|
158
159
|
...state,
|
159
160
|
isShowingFailedNotification,
|
@@ -163,6 +164,7 @@ export function PendingSubmissionsContextProvider({ isPendingQueueEnabled, succe
|
|
163
164
|
reloadPendingSubmissions,
|
164
165
|
deletePendingSubmission: submissionService.deletePendingQueueSubmission,
|
165
166
|
isShowingSuccessNotification: submittedNotificationCount > 0,
|
167
|
+
hideSuccessNotification,
|
166
168
|
}), [
|
167
169
|
state,
|
168
170
|
isShowingFailedNotification,
|
@@ -171,6 +173,7 @@ export function PendingSubmissionsContextProvider({ isPendingQueueEnabled, succe
|
|
171
173
|
processPendingQueue,
|
172
174
|
reloadPendingSubmissions,
|
173
175
|
submittedNotificationCount,
|
176
|
+
hideSuccessNotification,
|
174
177
|
]);
|
175
178
|
return (React.createElement(PendingSubmissionsContext.Provider, { value: value }, children));
|
176
179
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usePendingSubmissions.js","sourceRoot":"","sources":["../../src/hooks/usePendingSubmissions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAgCzC,MAAM,YAAY,GAAG;IACnB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,IAAI;IACf,kBAAkB,EAAE,EAAE;CACvB,CAAA;AAED,MAAM,yBAAyB,GAC7B,KAAK,CAAC,aAAa,CAAiC;IAClD,GAAG,YAAY;IACf,wBAAwB,EAAE,GAAG,EAAE,GAAE,CAAC;IAClC,mBAAmB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC7B,uBAAuB,EAAE,GAAG,EAAE,GAAE,CAAC;IACjC,wBAAwB,EAAE,KAAK;IAC/B,2BAA2B,EAAE,KAAK;IAClC,sBAAsB,EAAE,GAAG,EAAE,GAAE,CAAC;IAChC,4BAA4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AAG,KAAK,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAA;IACzD,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAA;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import * as React from 'react'\nimport { submissionService } from '@oneblink/apps'\nimport useBooleanState from './useBooleanState'\nimport useIsMounted from './useIsMounted'\nimport useIsOffline from './useIsOffline'\n\n/** The value returned from `usePendingSubmissions()` hook */\nexport type PendingSubmissionsContextValue = {\n /** `true` if the pending submissions are currently loading */\n isLoading: boolean\n /** An Error object if loading pending submissions fails */\n loadError: Error | null\n /**\n * The submissions that were submitted offline and can be processed when back\n * online\n */\n pendingSubmissions: submissionService.PendingFormSubmission[]\n /** `true` submissions that where submitted offline are being processed */\n isProcessingPendingQueue: boolean\n /** A function to trigger processing of the pending queue */\n processPendingQueue: () => unknown\n /**\n * A function to trigger loading of the submissions that were submitted\n * offline\n */\n reloadPendingSubmissions: () => unknown\n /** A function to remove a submission from the pending submissions */\n deletePendingSubmission: (pendingTimestamp: string) => unknown\n /** `true` if a submission being processed fails */\n isShowingFailedNotification: boolean\n /** A function to hide the notification when a submission fails to process */\n hideFailedNotification: () => unknown\n /** `true` if a submission being processed completes successfully. */\n isShowingSuccessNotification: boolean\n}\n\nconst defaultState = {\n isLoading: false,\n loadError: null,\n pendingSubmissions: [],\n}\n\nconst PendingSubmissionsContext =\n React.createContext<PendingSubmissionsContextValue>({\n ...defaultState,\n reloadPendingSubmissions: () => {},\n processPendingQueue: () => {},\n deletePendingSubmission: () => {},\n isProcessingPendingQueue: false,\n isShowingFailedNotification: false,\n hideFailedNotification: () => {},\n isShowingSuccessNotification: false,\n })\n\n/**\n * React Component that provides the context for the `usePendingSubmissions()`\n * hook to be used by components further down your component tree. **It should\n * only be 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 { PendingSubmissionsContextProvider } from '@oneblink/apps-react'\n *\n * function Component() {\n * const pendingSubmissionsContext = usePendingSubmissions()\n * // use pending submissions here\n * }\n *\n * function App() {\n * return (\n * <PendingSubmissionsContextProvider\n * isPendingQueueEnabled\n * successNotificationTimeoutMs={3000}\n * >\n * <Component />\n * </PendingSubmissionsContextProvider>\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 PendingSubmissionsContextProvider({\n isPendingQueueEnabled,\n successNotificationTimeoutMs = 500,\n children,\n}: {\n /**\n * `true` if pending queue is enabled, otherwise `false`. Can be used prevent\n * offline submissions from being processed.\n */\n isPendingQueueEnabled: boolean\n /**\n * When a submission is processed successfully the\n * `isShowingSuccessNotification` will be temporarily set to `true`, it will\n * be set back to `false` after 5 seconds. This prop will allow you to\n * customise how long to wait before hiding the notification with a\n * milliseconds value.\n */\n successNotificationTimeoutMs?: number\n /** Your application components */\n children: React.ReactNode\n}) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n\n // Using a number as state so we can reset the timer used to close\n // the snack bar each time a pending queue item is processed\n const [submittedNotificationCount, setSubmittedNotificationCount] =\n React.useState(0)\n const [\n isShowingFailedNotification,\n showFailedNotification,\n hideFailedNotification,\n ] = useBooleanState(false)\n const [isProcessingPendingQueue, setIsProcessingPendingQueue] =\n React.useState(false)\n const [state, setState] = React.useState<{\n isLoading: boolean\n loadError: Error | null\n pendingSubmissions: submissionService.PendingFormSubmission[]\n }>(defaultState)\n\n const processPendingQueue = React.useCallback(async () => {\n if (isMounted.current) {\n setIsProcessingPendingQueue(true)\n }\n\n await submissionService.processPendingQueue({\n shouldRunExternalIdGeneration: true,\n shouldRunServerValidation: true,\n })\n\n if (isMounted.current) {\n setIsProcessingPendingQueue(false)\n }\n }, [isMounted])\n\n const reloadPendingSubmissions = React.useCallback(async () => {\n if (isMounted.current) {\n setState((currentState) => ({\n isLoading: true,\n loadError: null,\n pendingSubmissions: currentState.pendingSubmissions,\n }))\n }\n let newError = null\n let newPendingSubmissions: submissionService.PendingFormSubmission[] = []\n\n try {\n newPendingSubmissions =\n await submissionService.getPendingQueueSubmissions()\n } catch (error) {\n newError = error as Error\n }\n\n if (isMounted.current) {\n setState({\n isLoading: false,\n loadError: newError,\n pendingSubmissions: newPendingSubmissions,\n })\n }\n }, [isMounted])\n\n React.useEffect(() => {\n if (!isPendingQueueEnabled) {\n return\n }\n reloadPendingSubmissions()\n return submissionService.registerPendingQueueListener(\n (pendingSubmissions, action) => {\n switch (action) {\n case 'SUBMIT_SUCCEEDED': {\n setSubmittedNotificationCount((current) => current + 1)\n break\n }\n case 'SUBMIT_FAILED': {\n showFailedNotification()\n break\n }\n case 'SUBMIT_STARTED': {\n hideFailedNotification()\n break\n }\n case 'ADDITION': {\n processPendingQueue()\n break\n }\n }\n setState({\n isLoading: false,\n pendingSubmissions,\n loadError: null,\n })\n },\n )\n }, [\n hideFailedNotification,\n isPendingQueueEnabled,\n processPendingQueue,\n reloadPendingSubmissions,\n showFailedNotification,\n ])\n\n React.useEffect(() => {\n if (!isOffline) {\n processPendingQueue()\n }\n }, [isOffline, processPendingQueue])\n\n React.useEffect(() => {\n if (submittedNotificationCount > 0) {\n const timeoutId = setTimeout(() => {\n setSubmittedNotificationCount(0)\n }, successNotificationTimeoutMs)\n return () => {\n clearTimeout(timeoutId)\n }\n }\n }, [submittedNotificationCount, successNotificationTimeoutMs])\n\n const value = React.useMemo(\n () => ({\n ...state,\n isShowingFailedNotification,\n hideFailedNotification,\n isProcessingPendingQueue,\n processPendingQueue,\n reloadPendingSubmissions,\n deletePendingSubmission: submissionService.deletePendingQueueSubmission,\n isShowingSuccessNotification: submittedNotificationCount > 0,\n }),\n [\n state,\n isShowingFailedNotification,\n hideFailedNotification,\n isProcessingPendingQueue,\n processPendingQueue,\n reloadPendingSubmissions,\n submittedNotificationCount,\n ],\n )\n\n return (\n <PendingSubmissionsContext.Provider value={value}>\n {children}\n </PendingSubmissionsContext.Provider>\n )\n}\n\n/**\n * React hook to get the context value for Pending Submissions. Will throw an\n * Error if used outside of the `<PendingSubmissionsContextProvider />`\n * component.\n *\n * @returns\n * @group Hooks\n */\nexport default function usePendingSubmissions(): PendingSubmissionsContextValue {\n const value = React.useContext(PendingSubmissionsContext)\n if (!value) {\n throw new Error(\n `\"usePendingSubmissions\" hook was used outside of the \"<PendingSubmissionsContextProvider />\" component's children.`,\n )\n }\n return value\n}\n"]}
|
1
|
+
{"version":3,"file":"usePendingSubmissions.js","sourceRoot":"","sources":["../../src/hooks/usePendingSubmissions.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAqCzC,MAAM,YAAY,GAAG;IACnB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,IAAI;IACf,kBAAkB,EAAE,EAAE;CACvB,CAAA;AAED,MAAM,yBAAyB,GAAG,KAAK,CAAC,aAAa,CAEnD,SAAS,CAAC,CAAA;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,iCAAiC,CAAC,EAChD,qBAAqB,EACrB,4BAA4B,GAAG,IAAI,EACnC,QAAQ,GAiBT;IACC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,kEAAkE;IAClE,4DAA4D;IAC5D,MAAM,CAAC,0BAA0B,EAAE,6BAA6B,CAAC,GAC/D,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;IACnB,MAAM,uBAAuB,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACrD,6BAA6B,CAAC,C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G,EAAE;QACnB,IAAI,0BAA0B,GAAG,CAAC,EAAE;YAClC,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;gBAChC,uBAAuB,EAAE,CAAA;YAC3B,CAAC,EAAE,4BAA4B,CAAC,CAAA;YAChC,OAAO,GAAG,EAAE;gBACV,YAAY,CAAC,SAAS,CAAC,CAAA;YACzB,CAAC,CAAA;SACF;IACH,CAAC,EAAE;QACD,uBAAuB;QACvB,0BAA0B;QAC1B,4BAA4B;KAC7B,CAAC,CAAA;IAEF,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CACzB,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,KAAK;QACR,2BAA2B;QAC3B,sBAAsB;QACtB,wBAAwB;QACxB,mBAAmB;QACnB,wBAAwB;QACxB,uBAAuB,EAAE,iBAAiB,CAAC,4BAA4B;QACvE,4BAA4B,EAAE,0BAA0B,GAAG,CAAC;QAC5D,uBAAuB;KACxB,CAAC,EACF;QACE,KAAK;QACL,2BAA2B;QAC3B,sBAAsB;QACtB,wBAAwB;QACxB,mBAAmB;QACnB,wBAAwB;QACxB,0BAA0B;QAC1B,uBAAuB;KACxB,CACF,CAAA;IAED,OAAO,CACL,oBAAC,yBAAyB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAC7C,QAAQ,CAC0B,CACtC,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAA;IACzD,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAA;KACF;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import * as React from 'react'\nimport { submissionService } from '@oneblink/apps'\nimport useBooleanState from './useBooleanState'\nimport useIsMounted from './useIsMounted'\nimport useIsOffline from './useIsOffline'\n\n/** The value returned from `usePendingSubmissions()` hook */\nexport type PendingSubmissionsContextValue = {\n /** `true` if the pending submissions are currently loading */\n isLoading: boolean\n /** An Error object if loading pending submissions fails */\n loadError: Error | null\n /**\n * The submissions that were submitted offline and can be processed when back\n * online\n */\n pendingSubmissions: submissionService.PendingFormSubmission[]\n /** `true` submissions that where submitted offline are being processed */\n isProcessingPendingQueue: boolean\n /** A function to trigger processing of the pending queue */\n processPendingQueue: () => unknown\n /**\n * A function to trigger loading of the submissions that were submitted\n * offline\n */\n reloadPendingSubmissions: () => unknown\n /** A function to remove a submission from the pending submissions */\n deletePendingSubmission: (pendingTimestamp: string) => unknown\n /** `true` if a submission being processed fails */\n isShowingFailedNotification: boolean\n /** A function to hide the notification when a submission fails to process */\n hideFailedNotification: () => unknown\n /** `true` if a submission being processed completes successfully. */\n isShowingSuccessNotification: boolean\n /**\n * A function to hide the notification after a submission completed\n * successfully\n */\n hideSuccessNotification: () => unknown\n}\n\nconst defaultState = {\n isLoading: false,\n loadError: null,\n pendingSubmissions: [],\n}\n\nconst PendingSubmissionsContext = React.createContext<\n PendingSubmissionsContextValue | undefined\n>(undefined)\n\n/**\n * React Component that provides the context for the `usePendingSubmissions()`\n * hook to be used by components further down your component tree. **It should\n * only be 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 {\n * PendingSubmissionsContextProvider,\n * usePendingSubmissions,\n * } from '@oneblink/apps-react'\n *\n * function Component() {\n * const pendingSubmissionsContext = usePendingSubmissions()\n * // use pending submissions here\n * }\n *\n * function App() {\n * return (\n * <PendingSubmissionsContextProvider\n * isPendingQueueEnabled\n * successNotificationTimeoutMs={3000}\n * >\n * <Component />\n * </PendingSubmissionsContextProvider>\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 PendingSubmissionsContextProvider({\n isPendingQueueEnabled,\n successNotificationTimeoutMs = 5000,\n children,\n}: {\n /**\n * `true` if pending queue is enabled, otherwise `false`. Can be used prevent\n * offline submissions from being processed.\n */\n isPendingQueueEnabled: boolean\n /**\n * When a submission is processed successfully the\n * `isShowingSuccessNotification` will be temporarily set to `true`, it will\n * be set back to `false` after 5 seconds. This prop will allow you to\n * customise how long to wait before hiding the notification with a\n * milliseconds value.\n */\n successNotificationTimeoutMs?: number\n /** Your application components */\n children: React.ReactNode\n}) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n\n // Using a number as state so we can reset the timer used to close\n // the snack bar each time a pending queue item is processed\n const [submittedNotificationCount, setSubmittedNotificationCount] =\n React.useState(0)\n const hideSuccessNotification = React.useCallback(() => {\n setSubmittedNotificationCount(0)\n }, [])\n const [\n isShowingFailedNotification,\n showFailedNotification,\n hideFailedNotification,\n ] = useBooleanState(false)\n const [isProcessingPendingQueue, setIsProcessingPendingQueue] =\n React.useState(false)\n const [state, setState] = React.useState<{\n isLoading: boolean\n loadError: Error | null\n pendingSubmissions: submissionService.PendingFormSubmission[]\n }>(defaultState)\n\n const processPendingQueue = React.useCallback(async () => {\n if (isMounted.current) {\n setIsProcessingPendingQueue(true)\n }\n\n await submissionService.processPendingQueue({\n shouldRunExternalIdGeneration: true,\n shouldRunServerValidation: true,\n })\n\n if (isMounted.current) {\n setIsProcessingPendingQueue(false)\n }\n }, [isMounted])\n\n const reloadPendingSubmissions = React.useCallback(async () => {\n if (isMounted.current) {\n setState((currentState) => ({\n isLoading: true,\n loadError: null,\n pendingSubmissions: currentState.pendingSubmissions,\n }))\n }\n let newError = null\n let newPendingSubmissions: submissionService.PendingFormSubmission[] = []\n\n try {\n newPendingSubmissions =\n await submissionService.getPendingQueueSubmissions()\n } catch (error) {\n newError = error as Error\n }\n\n if (isMounted.current) {\n setState({\n isLoading: false,\n loadError: newError,\n pendingSubmissions: newPendingSubmissions,\n })\n }\n }, [isMounted])\n\n React.useEffect(() => {\n if (!isPendingQueueEnabled) {\n return\n }\n reloadPendingSubmissions()\n return submissionService.registerPendingQueueListener(\n (pendingSubmissions, action) => {\n switch (action) {\n case 'SUBMIT_SUCCEEDED': {\n setSubmittedNotificationCount((current) => current + 1)\n break\n }\n case 'SUBMIT_FAILED': {\n showFailedNotification()\n break\n }\n case 'SUBMIT_STARTED': {\n hideFailedNotification()\n break\n }\n case 'ADDITION': {\n processPendingQueue()\n break\n }\n }\n setState({\n isLoading: false,\n pendingSubmissions,\n loadError: null,\n })\n },\n )\n }, [\n hideFailedNotification,\n isPendingQueueEnabled,\n processPendingQueue,\n reloadPendingSubmissions,\n showFailedNotification,\n ])\n\n React.useEffect(() => {\n if (!isOffline) {\n processPendingQueue()\n }\n }, [isOffline, processPendingQueue])\n\n React.useEffect(() => {\n if (submittedNotificationCount > 0) {\n const timeoutId = setTimeout(() => {\n hideSuccessNotification()\n }, successNotificationTimeoutMs)\n return () => {\n clearTimeout(timeoutId)\n }\n }\n }, [\n hideSuccessNotification,\n submittedNotificationCount,\n successNotificationTimeoutMs,\n ])\n\n const value = React.useMemo<PendingSubmissionsContextValue>(\n () => ({\n ...state,\n isShowingFailedNotification,\n hideFailedNotification,\n isProcessingPendingQueue,\n processPendingQueue,\n reloadPendingSubmissions,\n deletePendingSubmission: submissionService.deletePendingQueueSubmission,\n isShowingSuccessNotification: submittedNotificationCount > 0,\n hideSuccessNotification,\n }),\n [\n state,\n isShowingFailedNotification,\n hideFailedNotification,\n isProcessingPendingQueue,\n processPendingQueue,\n reloadPendingSubmissions,\n submittedNotificationCount,\n hideSuccessNotification,\n ],\n )\n\n return (\n <PendingSubmissionsContext.Provider value={value}>\n {children}\n </PendingSubmissionsContext.Provider>\n )\n}\n\n/**\n * React hook to get the context value for Pending Submissions. Will throw an\n * Error if used outside of the `<PendingSubmissionsContextProvider />`\n * component.\n *\n * @returns\n * @group Hooks\n */\nexport default function usePendingSubmissions(): PendingSubmissionsContextValue {\n const value = React.useContext(PendingSubmissionsContext)\n if (!value) {\n throw new Error(\n `\"usePendingSubmissions\" hook was used outside of the \"<PendingSubmissionsContextProvider />\" component's children.`,\n )\n }\n return value\n}\n"]}
|
package/dist/hooks/useSignUp.js
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { authService, Sentry } from '@oneblink/apps';
|
3
|
+
/**
|
4
|
+
* @param options
|
5
|
+
* @returns
|
6
|
+
* @group Hooks
|
7
|
+
*/
|
3
8
|
export default function useSignUp({ formsAppId, username, firstName, lastName, }) {
|
4
9
|
const usernameValidation = React.useMemo(() => {
|
5
10
|
// regex source: https://www.w3resource.com/javascript/form/email-validation.php#:~:text=To%20get%20a%20valid%20email,%5D%2B)*%24%2F.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useSignUp.js","sourceRoot":"","sources":["../../src/hooks/useSignUp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,GAMT;IACC,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5C,qIAAqI;QACrI,OAAO;YACL,SAAS,EAAE,CAAC,QAAQ,CAAC,KAAK,CACxB,sEAAsE,CACvE;SACF,CAAA;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,MAAM,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE,cAAc,CAAC,GAClE,KAAK,CAAC,QAAQ,CAIX;QACD,WAAW,EAAE,KAAK;QAClB,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,KAAK;KACtB,CAAC,CAAA;IAEJ,MAAM,gBAAgB,GAAG,KAAK,CAAC,WAAW,CACxC,GAAG,EAAE,CACH,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC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esContent":["import * as React from 'react'\nimport { authService, Sentry } from '@oneblink/apps'\n\nexport default function useSignUp({\n formsAppId,\n username,\n firstName,\n lastName,\n}: {\n formsAppId: number\n username: string\n firstName?: string\n lastName?: string\n}) {\n const usernameValidation = React.useMemo(() => {\n // regex source: https://www.w3resource.com/javascript/form/email-validation.php#:~:text=To%20get%20a%20valid%20email,%5D%2B)*%24%2F.\n return {\n isInvalid: !username.match(\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$/,\n ),\n }\n }, [username])\n\n const [{ isSigningUp, signUpError, signUpComplete }, setSignUpState] =\n React.useState<{\n isSigningUp: boolean\n signUpError: Error | null\n signUpComplete: boolean\n }>({\n isSigningUp: false,\n signUpError: null,\n signUpComplete: false,\n })\n\n const clearSignUpError = React.useCallback(\n () =>\n setSignUpState((current) => ({\n ...current,\n signUpError: null,\n })),\n [],\n )\n\n const signUpWithUserDetails = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setSignUpState((current) => ({\n ...current,\n signUpError: new Error('Please enter a valid email address'),\n }))\n return\n }\n\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: true,\n signUpError: null,\n }))\n\n try {\n await authService.signUp({\n formsAppId,\n email: username,\n firstName,\n lastName,\n })\n\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: false,\n signUpComplete: true,\n }))\n } catch (error) {\n Sentry.captureException(error)\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: false,\n signUpError: error as Error,\n }))\n }\n }, [firstName, formsAppId, lastName, username, usernameValidation.isInvalid])\n\n return {\n signUpWithUserDetails,\n clearSignUpError,\n isSigningUp,\n signUpError,\n signUpComplete,\n usernameValidation,\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"useSignUp.js","sourceRoot":"","sources":["../../src/hooks/useSignUp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;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AAM,CAAC;gBACvB,UAAU;gBACV,KAAK,EAAE,QAAQ;gBACf,SAAS;gBACT,QAAQ;aACT,CAAC,CAAA;YAEF,cAAc,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;gBAChC,GAAG,YAAY;gBACf,WAAW,EAAE,KAAK;gBAClB,cAAc,EAAE,IAAI;aACrB,CAAC,CAAC,CAAA;SACJ;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;YAC9B,cAAc,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;gBAChC,GAAG,YAAY;gBACf,WAAW,EAAE,KAAK;gBAClB,WAAW,EAAE,KAAc;aAC5B,CAAC,CAAC,CAAA;SACJ;IACH,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC,CAAA;IAE7E,OAAO;QACL,qBAAqB;QACrB,gBAAgB;QAChB,WAAW;QACX,WAAW;QACX,cAAc;QACd,kBAAkB;KACnB,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService, Sentry } from '@oneblink/apps'\n\n/**\n * @param options\n * @returns\n * @group Hooks\n */\nexport default function useSignUp({\n formsAppId,\n username,\n firstName,\n lastName,\n}: {\n formsAppId: number\n username: string\n firstName?: string\n lastName?: string\n}) {\n const usernameValidation = React.useMemo(() => {\n // regex source: https://www.w3resource.com/javascript/form/email-validation.php#:~:text=To%20get%20a%20valid%20email,%5D%2B)*%24%2F.\n return {\n isInvalid: !username.match(\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$/,\n ),\n }\n }, [username])\n\n const [{ isSigningUp, signUpError, signUpComplete }, setSignUpState] =\n React.useState<{\n isSigningUp: boolean\n signUpError: Error | null\n signUpComplete: boolean\n }>({\n isSigningUp: false,\n signUpError: null,\n signUpComplete: false,\n })\n\n const clearSignUpError = React.useCallback(\n () =>\n setSignUpState((current) => ({\n ...current,\n signUpError: null,\n })),\n [],\n )\n\n const signUpWithUserDetails = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setSignUpState((current) => ({\n ...current,\n signUpError: new Error('Please enter a valid email address'),\n }))\n return\n }\n\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: true,\n signUpError: null,\n }))\n\n try {\n await authService.signUp({\n formsAppId,\n email: username,\n firstName,\n lastName,\n })\n\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: false,\n signUpComplete: true,\n }))\n } catch (error) {\n Sentry.captureException(error)\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: false,\n signUpError: error as Error,\n }))\n }\n }, [firstName, formsAppId, lastName, username, usernameValidation.isInvalid])\n\n return {\n signUpWithUserDetails,\n clearSignUpError,\n isSigningUp,\n signUpError,\n signUpComplete,\n usernameValidation,\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
@@ -12,7 +12,7 @@ export { default as useBooleanState } from './hooks/useBooleanState';
|
|
12
12
|
export { default as useNullableState } from './hooks/useNullableState';
|
13
13
|
export { default as useClickOutsideElement } from './hooks/useClickOutsideElement';
|
14
14
|
export { default as useIsOffline, IsOfflineContextProvider, } from './hooks/useIsOffline';
|
15
|
-
export { default as useLogin } from './hooks/useLogin';
|
15
|
+
export { default as useLogin, UseLoginValue } from './hooks/useLogin';
|
16
16
|
export { default as useSignUp } from './hooks/useSignUp';
|
17
17
|
export { default as useAuth, AuthContextProvider, AuthContextValue, } from './hooks/useAuth';
|
18
18
|
export { default as usePendingSubmissions, PendingSubmissionsContextProvider, PendingSubmissionsContextValue, } from './hooks/usePendingSubmissions';
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,IAAI,YAAY,EACxC,s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AElG,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,6CAA6C,CAAA;AAClG,OAAO,EAAE,OAAO,IAAI,6BAA6B,EAAE,MAAM,iDAAiD,CAAA;AAC1G,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,6CAA6C,CAAA;AAClG,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAC1E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAE5D,cAAc,cAAc,CAAA","sourcesContent":["export {\n OneBlinkFormBaseProps,\n OneBlinkFormControlledProps,\n OneBlinkFormUncontrolled as OneBlinkForm,\n OneBlinkFormControlled,\n} from './OneBlinkForm'\nexport { default as OneBlinkAutoSaveForm } from './OneBlinkAutoSaveForm'\nexport { default as OneBlinkReadOnlyForm } from './OneBlinkReadOnlyForm'\nexport { OneBlinkFormStoreProvider } from './components/formStore/OneBlinkFormStoreProvider'\nexport { default as OneBlinkFormStoreClearFiltersButton } from './components/formStore/OneBlinkFormStoreClearFiltersButton'\nexport { default as OneBlinkFormStoreColumnsButton } from './components/formStore/OneBlinkFormStoreColumnsButton'\nexport { default as OneBlinkFormStoreDownloadButton } from './components/formStore/OneBlinkFormStoreDownloadButton'\nexport { default as OneBlinkFormStoreRefreshButton } from './components/formStore/OneBlinkFormStoreRefreshButton'\nexport { default as OneBlinkFormStoreTable } from './components/formStore/OneBlinkFormStoreTable'\n\nexport { default as useIsMounted } from './hooks/useIsMounted'\nexport { default as useBooleanState } from './hooks/useBooleanState'\nexport { default as useNullableState } from './hooks/useNullableState'\nexport { default as useClickOutsideElement } from './hooks/useClickOutsideElement'\nexport {\n default as useIsOffline,\n IsOfflineContextProvider,\n} from './hooks/useIsOffline'\nexport { default as useLogin, UseLoginValue } from './hooks/useLogin'\nexport { default as useSignUp } from './hooks/useSignUp'\nexport {\n default as useAuth,\n AuthContextProvider,\n AuthContextValue,\n} from './hooks/useAuth'\nexport {\n default as usePendingSubmissions,\n PendingSubmissionsContextProvider,\n PendingSubmissionsContextValue,\n} from './hooks/usePendingSubmissions'\nexport {\n default as useDrafts,\n DraftsContextProvider,\n DraftsContextValue,\n} from './hooks/useDrafts'\nexport {\n default as useLoadDataState,\n LoadDataState,\n} from './hooks/useLoadDataState'\nexport { default as useFormSubmissionState } from './hooks/useFormSubmissionState'\nexport { default as useFormSubmissionAutoSaveState } from './hooks/useFormSubmissionAutoSaveState'\n\nexport { default as MuiV4CompatibleDatePicker } from './components/pickers/V4CompatibleDatePicker'\nexport { default as MuiV4CompatibleDateTimePicker } from './components/pickers/V4CompatibleDateTimePicker'\nexport { default as MuiV4CompatibleTimePicker } from './components/pickers/V4CompatibleTimePicker'\nexport { default as ProgressBar } from './components/renderer/ProgressBar'\nexport { default as PaymentReceipt } from './PaymentReceipt'\n\nexport * from './types/form'\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": "4.0.0-beta.
|
4
|
+
"version": "4.0.0-beta.7",
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
6
6
|
"bugs": {
|
7
7
|
"url": "https://github.com/oneblink/apps-react/issues"
|