@oneblink/apps-react 4.1.0-beta.7 → 4.1.0
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/README.md +2 -8
- package/dist/OneBlinkAutoSaveForm.d.ts +25 -5
- package/dist/OneBlinkAutoSaveForm.js +12 -0
- package/dist/OneBlinkAutoSaveForm.js.map +1 -1
- package/dist/OneBlinkForm.d.ts +558 -8
- package/dist/OneBlinkForm.js +546 -0
- package/dist/OneBlinkForm.js.map +1 -1
- package/dist/OneBlinkFormBase.d.ts +53 -8
- package/dist/OneBlinkFormBase.js +49 -25
- package/dist/OneBlinkFormBase.js.map +1 -1
- package/dist/OneBlinkReadOnlyForm.d.ts +83 -6
- package/dist/OneBlinkReadOnlyForm.js +80 -1
- package/dist/OneBlinkReadOnlyForm.js.map +1 -1
- package/dist/PaymentReceipt.d.ts +59 -0
- package/dist/PaymentReceipt.js +61 -6
- package/dist/PaymentReceipt.js.map +1 -1
- package/dist/components/formStore/FormStoreTableProvider.js +23 -1
- package/dist/components/formStore/FormStoreTableProvider.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/formStore/table/ColumnFilters.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/LookupButton.d.ts +3 -1
- package/dist/components/renderer/LookupButton.js +7 -5
- package/dist/components/renderer/LookupButton.js.map +1 -1
- package/dist/components/renderer/LookupNotification.js +60 -15
- package/dist/components/renderer/LookupNotification.js.map +1 -1
- package/dist/components/renderer/OneBlinkFormElements.d.ts +3 -3
- package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
- package/dist/components/renderer/PageFormElements.d.ts +3 -3
- package/dist/components/renderer/PageFormElements.js.map +1 -1
- package/dist/components/renderer/ProgressBar.d.ts +7 -3
- package/dist/components/renderer/ProgressBar.js +5 -0
- package/dist/components/renderer/ProgressBar.js.map +1 -1
- package/dist/form-elements/FormElementABN.js +1 -1
- package/dist/form-elements/FormElementABN.js.map +1 -1
- package/dist/form-elements/FormElementBSB.js +1 -1
- package/dist/form-elements/FormElementBSB.js.map +1 -1
- package/dist/form-elements/FormElementBarcodeScanner.js +3 -3
- package/dist/form-elements/FormElementBarcodeScanner.js.map +1 -1
- package/dist/form-elements/FormElementCalculation.js.map +1 -1
- package/dist/form-elements/FormElementCheckBoxes.js +1 -1
- package/dist/form-elements/FormElementCheckBoxes.js.map +1 -1
- package/dist/form-elements/FormElementDate.js +1 -1
- package/dist/form-elements/FormElementDate.js.map +1 -1
- package/dist/form-elements/FormElementDateTime.js +1 -1
- package/dist/form-elements/FormElementDateTime.js.map +1 -1
- package/dist/form-elements/FormElementEmail.js +1 -1
- package/dist/form-elements/FormElementEmail.js.map +1 -1
- package/dist/form-elements/FormElementForm.d.ts +4 -4
- package/dist/form-elements/FormElementForm.js.map +1 -1
- package/dist/form-elements/FormElementNumber.js +1 -1
- package/dist/form-elements/FormElementNumber.js.map +1 -1
- package/dist/form-elements/FormElementRepeatableSet.d.ts +4 -4
- package/dist/form-elements/FormElementRepeatableSet.js.map +1 -1
- package/dist/form-elements/FormElementSelect.js +1 -1
- package/dist/form-elements/FormElementSelect.js.map +1 -1
- package/dist/form-elements/FormElementSummary.js.map +1 -1
- package/dist/form-elements/FormElementTelephone.js +1 -1
- package/dist/form-elements/FormElementTelephone.js.map +1 -1
- package/dist/form-elements/FormElementText.js +1 -1
- package/dist/form-elements/FormElementText.js.map +1 -1
- package/dist/form-elements/FormElementTextarea.js +1 -1
- package/dist/form-elements/FormElementTextarea.js.map +1 -1
- package/dist/form-elements/FormElementTime.js +1 -1
- package/dist/form-elements/FormElementTime.js.map +1 -1
- package/dist/hooks/useAuth.d.ts +81 -6
- package/dist/hooks/useAuth.js +54 -0
- package/dist/hooks/useAuth.js.map +1 -1
- package/dist/hooks/useBooleanState.d.ts +42 -5
- package/dist/hooks/useBooleanState.js +36 -0
- package/dist/hooks/useBooleanState.js.map +1 -1
- package/dist/hooks/useClickOutsideElement.d.ts +40 -0
- package/dist/hooks/useClickOutsideElement.js +40 -0
- package/dist/hooks/useClickOutsideElement.js.map +1 -1
- package/dist/hooks/useConditionalLogic.d.ts +2 -3
- package/dist/hooks/useConditionalLogic.js.map +1 -1
- package/dist/hooks/useDrafts.d.ts +82 -0
- package/dist/hooks/useDrafts.js +204 -0
- package/dist/hooks/useDrafts.js.map +1 -0
- package/dist/hooks/useFormSubmissionAutoSaveState.d.ts +18 -5
- package/dist/hooks/useFormSubmissionAutoSaveState.js +10 -0
- package/dist/hooks/useFormSubmissionAutoSaveState.js.map +1 -1
- package/dist/hooks/useFormSubmissionModelContext.d.ts +4 -4
- package/dist/hooks/useFormSubmissionModelContext.js.map +1 -1
- package/dist/hooks/useFormSubmissionState.d.ts +45 -5
- package/dist/hooks/useFormSubmissionState.js +37 -0
- package/dist/hooks/useFormSubmissionState.js.map +1 -1
- package/dist/hooks/useFormValidation.d.ts +3 -3
- package/dist/hooks/useFormValidation.js.map +1 -1
- package/dist/hooks/useInjectPages.d.ts +2 -3
- package/dist/hooks/useInjectPages.js.map +1 -1
- package/dist/hooks/useIsMounted.d.ts +20 -0
- package/dist/hooks/useIsMounted.js +19 -0
- package/dist/hooks/useIsMounted.js.map +1 -1
- package/dist/hooks/useIsOffline.d.ts +54 -0
- package/dist/hooks/useIsOffline.js +54 -0
- package/dist/hooks/useIsOffline.js.map +1 -1
- package/dist/hooks/useLoadDataState.d.ts +46 -3
- package/dist/hooks/useLoadDataState.js +41 -0
- package/dist/hooks/useLoadDataState.js.map +1 -1
- package/dist/hooks/useLogin.d.ts +400 -13
- package/dist/hooks/useLogin.js +300 -0
- package/dist/hooks/useLogin.js.map +1 -1
- package/dist/hooks/useLookupNotification.d.ts +11 -4
- package/dist/hooks/useLookupNotification.js +42 -3
- package/dist/hooks/useLookupNotification.js.map +1 -1
- package/dist/hooks/useLookups.d.ts +3 -3
- package/dist/hooks/useLookups.js.map +1 -1
- package/dist/hooks/useNullableState.d.ts +46 -1
- package/dist/hooks/useNullableState.js +42 -1
- package/dist/hooks/useNullableState.js.map +1 -1
- package/dist/hooks/usePendingSubmissions.d.ts +103 -0
- package/dist/hooks/usePendingSubmissions.js +195 -0
- package/dist/hooks/usePendingSubmissions.js.map +1 -0
- package/dist/hooks/useReplaceableText.js +2 -1
- package/dist/hooks/useReplaceableText.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 +7 -4
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/services/checkBsbsAreInvalid.d.ts +2 -3
- package/dist/services/checkBsbsAreInvalid.js.map +1 -1
- package/dist/services/checkIfAttachmentsExist.d.ts +2 -3
- package/dist/services/checkIfAttachmentsExist.js.map +1 -1
- package/dist/services/checkIfBsbsAreValidating.d.ts +2 -3
- package/dist/services/checkIfBsbsAreValidating.js.map +1 -1
- package/dist/services/cleanFormSubmissionModel.d.ts +4 -4
- package/dist/services/cleanFormSubmissionModel.js +2 -1
- package/dist/services/cleanFormSubmissionModel.js.map +1 -1
- package/dist/services/form-validation.d.ts +3 -3
- package/dist/services/form-validation.js.map +1 -1
- package/dist/services/generate-default-data.d.ts +2 -3
- package/dist/services/generate-default-data.js +3 -1
- package/dist/services/generate-default-data.js.map +1 -1
- package/dist/services/generateFreshdeskDependentFieldElements.js.map +1 -1
- package/dist/services/getDateRangeConfiguration.d.ts +2 -3
- package/dist/services/getDateRangeConfiguration.js.map +1 -1
- package/dist/services/getRepeatableSetEntriesConfiguration.d.ts +2 -3
- package/dist/services/getRepeatableSetEntriesConfiguration.js.map +1 -1
- package/dist/styles/receipt.scss +1 -1
- package/dist/styles/repeatable-set.scss +2 -2
- package/dist/typedoc.d.ts +2 -0
- package/dist/typedoc.js +3 -0
- package/dist/typedoc.js.map +1 -0
- package/dist/types/form.d.ts +5 -6
- package/dist/types/form.js.map +1 -1
- package/package.json +10 -4
- package/dist/services/determineIsInfoPage.d.ts +0 -2
- package/dist/services/determineIsInfoPage.js +0 -17
- package/dist/services/determineIsInfoPage.js.map +0 -1
@@ -1,5 +1,46 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
|
2
|
+
/**
|
3
|
+
* This function is a react hook for state of type of your choosing. It comes
|
4
|
+
* with two memoized functions, one for setting state and one for clearing it.
|
5
|
+
*
|
6
|
+
* The items returned in the array can be destructured and named whatever you
|
7
|
+
* like:
|
8
|
+
*
|
9
|
+
* ```js
|
10
|
+
* import { useNullableState } from '@oneblink/apps-react'
|
11
|
+
*
|
12
|
+
* const startingProfile = {
|
13
|
+
* name: 'Forest Gump',
|
14
|
+
* profession: 'Military, Athlete, Other',
|
15
|
+
* }
|
16
|
+
*
|
17
|
+
* const [userProfile, setUserProfile, unsetUserProfile] =
|
18
|
+
* useBooleanState(startingProfile)
|
19
|
+
* ```
|
20
|
+
*
|
21
|
+
* `setUserProfile` can then be called with an object of type `T` like:
|
22
|
+
*
|
23
|
+
* ```js
|
24
|
+
* setUserProfile({
|
25
|
+
* name: 'Walter White',
|
26
|
+
* profession: 'Chemistry Teacher (Secondary School), Other',
|
27
|
+
* })
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* And `unsetUserProfile` can be called like:
|
31
|
+
*
|
32
|
+
* ```js
|
33
|
+
* unsetUserProfile()
|
34
|
+
* ```
|
35
|
+
*
|
36
|
+
* @typeParam T The type of the state
|
37
|
+
* @param defaultValue
|
38
|
+
* @returns
|
39
|
+
* @group Hooks
|
40
|
+
*/
|
41
|
+
export default function useNullableState(
|
42
|
+
/** The starting state for the hook. */
|
43
|
+
defaultValue) {
|
3
44
|
const [state, setState] = React.useState(defaultValue);
|
4
45
|
const unsetState = React.useCallback(() => setState(null), []);
|
5
46
|
return [state, setState, unsetState];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useNullableState.js","sourceRoot":"","sources":["../../src/hooks/useNullableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,CAAC,OAAO,UAAU,gBAAgB,
|
1
|
+
{"version":3,"file":"useNullableState.js","sourceRoot":"","sources":["../../src/hooks/useNullableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB;AACtC,uCAAuC;AACvC,YAAsB;IAMtB,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAA;IACtD,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IAC9D,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;AACtC,CAAC","sourcesContent":["import * as React from 'react'\n\n/**\n * This function is a react hook for state of type of your choosing. It comes\n * with two memoized functions, one for setting state and one for clearing it.\n *\n * The items returned in the array can be destructured and named whatever you\n * like:\n *\n * ```js\n * import { useNullableState } from '@oneblink/apps-react'\n *\n * const startingProfile = {\n * name: 'Forest Gump',\n * profession: 'Military, Athlete, Other',\n * }\n *\n * const [userProfile, setUserProfile, unsetUserProfile] =\n * useBooleanState(startingProfile)\n * ```\n *\n * `setUserProfile` can then be called with an object of type `T` like:\n *\n * ```js\n * setUserProfile({\n * name: 'Walter White',\n * profession: 'Chemistry Teacher (Secondary School), Other',\n * })\n * ```\n *\n * And `unsetUserProfile` can be called like:\n *\n * ```js\n * unsetUserProfile()\n * ```\n *\n * @typeParam T The type of the state\n * @param defaultValue\n * @returns\n * @group Hooks\n */\nexport default function useNullableState<T>(\n /** The starting state for the hook. */\n defaultValue: T | null,\n): [\n state: T | null,\n setState: React.Dispatch<React.SetStateAction<T | null>>,\n clearState: () => void,\n] {\n const [state, setState] = React.useState(defaultValue)\n const unsetState = React.useCallback(() => setState(null), [])\n return [state, setState, unsetState]\n}\n"]}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { submissionService } from '@oneblink/apps';
|
3
|
+
/** The value returned from `usePendingSubmissions()` hook */
|
4
|
+
export type PendingSubmissionsContextValue = {
|
5
|
+
/** `true` if the pending submissions are currently loading */
|
6
|
+
isLoading: boolean;
|
7
|
+
/** An Error object if loading pending submissions fails */
|
8
|
+
loadError: Error | null;
|
9
|
+
/**
|
10
|
+
* The submissions that were submitted offline and can be processed when back
|
11
|
+
* online
|
12
|
+
*/
|
13
|
+
pendingSubmissions: submissionService.PendingFormSubmission[];
|
14
|
+
/** `true` submissions that where submitted offline are being processed */
|
15
|
+
isProcessingPendingQueue: boolean;
|
16
|
+
/** A function to trigger processing of the pending queue */
|
17
|
+
processPendingQueue: () => unknown;
|
18
|
+
/**
|
19
|
+
* A function to trigger loading of the submissions that were submitted
|
20
|
+
* offline
|
21
|
+
*/
|
22
|
+
reloadPendingSubmissions: () => unknown;
|
23
|
+
/** A function to remove a submission from the pending submissions */
|
24
|
+
deletePendingSubmission: (pendingTimestamp: string) => unknown;
|
25
|
+
/** `true` if a submission being processed fails */
|
26
|
+
isShowingFailedNotification: boolean;
|
27
|
+
/** A function to hide the notification when a submission fails to process */
|
28
|
+
hideFailedNotification: () => unknown;
|
29
|
+
/** `true` if a submission being processed completes successfully. */
|
30
|
+
isShowingSuccessNotification: boolean;
|
31
|
+
/**
|
32
|
+
* A function to hide the notification after a submission completed
|
33
|
+
* successfully
|
34
|
+
*/
|
35
|
+
hideSuccessNotification: () => unknown;
|
36
|
+
};
|
37
|
+
/**
|
38
|
+
* React Component that provides the context for the `usePendingSubmissions()`
|
39
|
+
* hook to be used by components further down your component tree. **It should
|
40
|
+
* only be included in your component tree once and ideally at the root of the
|
41
|
+
* application.**
|
42
|
+
*
|
43
|
+
* #### Example
|
44
|
+
*
|
45
|
+
* ```jsx
|
46
|
+
* import * as React from 'react'
|
47
|
+
* import {
|
48
|
+
* PendingSubmissionsContextProvider,
|
49
|
+
* usePendingSubmissions,
|
50
|
+
* } from '@oneblink/apps-react'
|
51
|
+
*
|
52
|
+
* function Component() {
|
53
|
+
* const pendingSubmissionsContext = usePendingSubmissions()
|
54
|
+
* // use pending submissions here
|
55
|
+
* }
|
56
|
+
*
|
57
|
+
* function App() {
|
58
|
+
* return (
|
59
|
+
* <PendingSubmissionsContextProvider
|
60
|
+
* isPendingQueueEnabled
|
61
|
+
* successNotificationTimeoutMs={3000}
|
62
|
+
* >
|
63
|
+
* <Component />
|
64
|
+
* </PendingSubmissionsContextProvider>
|
65
|
+
* )
|
66
|
+
* }
|
67
|
+
*
|
68
|
+
* const root = document.getElementById('root')
|
69
|
+
* if (root) {
|
70
|
+
* ReactDOM.render(<App />, root)
|
71
|
+
* }
|
72
|
+
* ```
|
73
|
+
*
|
74
|
+
* @param props
|
75
|
+
* @returns
|
76
|
+
* @group Components
|
77
|
+
*/
|
78
|
+
export declare function PendingSubmissionsContextProvider({ isPendingQueueEnabled, successNotificationTimeoutMs, children, }: {
|
79
|
+
/**
|
80
|
+
* `true` if pending queue is enabled, otherwise `false`. Can be used prevent
|
81
|
+
* offline submissions from being processed.
|
82
|
+
*/
|
83
|
+
isPendingQueueEnabled: boolean;
|
84
|
+
/**
|
85
|
+
* When a submission is processed successfully the
|
86
|
+
* `isShowingSuccessNotification` will be temporarily set to `true`, it will
|
87
|
+
* be set back to `false` after 5 seconds. This prop will allow you to
|
88
|
+
* customise how long to wait before hiding the notification with a
|
89
|
+
* milliseconds value.
|
90
|
+
*/
|
91
|
+
successNotificationTimeoutMs?: number;
|
92
|
+
/** Your application components */
|
93
|
+
children: React.ReactNode;
|
94
|
+
}): JSX.Element;
|
95
|
+
/**
|
96
|
+
* React hook to get the context value for Pending Submissions. Will throw an
|
97
|
+
* Error if used outside of the `<PendingSubmissionsContextProvider />`
|
98
|
+
* component.
|
99
|
+
*
|
100
|
+
* @returns
|
101
|
+
* @group Hooks
|
102
|
+
*/
|
103
|
+
export default function usePendingSubmissions(): PendingSubmissionsContextValue;
|
@@ -0,0 +1,195 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { submissionService } from '@oneblink/apps';
|
3
|
+
import useBooleanState from './useBooleanState';
|
4
|
+
import useIsMounted from './useIsMounted';
|
5
|
+
import useIsOffline from './useIsOffline';
|
6
|
+
const defaultState = {
|
7
|
+
isLoading: false,
|
8
|
+
loadError: null,
|
9
|
+
pendingSubmissions: [],
|
10
|
+
};
|
11
|
+
const PendingSubmissionsContext = React.createContext(undefined);
|
12
|
+
/**
|
13
|
+
* React Component that provides the context for the `usePendingSubmissions()`
|
14
|
+
* hook to be used by components further down your component tree. **It should
|
15
|
+
* only be included in your component tree once and ideally at the root of the
|
16
|
+
* application.**
|
17
|
+
*
|
18
|
+
* #### Example
|
19
|
+
*
|
20
|
+
* ```jsx
|
21
|
+
* import * as React from 'react'
|
22
|
+
* import {
|
23
|
+
* PendingSubmissionsContextProvider,
|
24
|
+
* usePendingSubmissions,
|
25
|
+
* } from '@oneblink/apps-react'
|
26
|
+
*
|
27
|
+
* function Component() {
|
28
|
+
* const pendingSubmissionsContext = usePendingSubmissions()
|
29
|
+
* // use pending submissions here
|
30
|
+
* }
|
31
|
+
*
|
32
|
+
* function App() {
|
33
|
+
* return (
|
34
|
+
* <PendingSubmissionsContextProvider
|
35
|
+
* isPendingQueueEnabled
|
36
|
+
* successNotificationTimeoutMs={3000}
|
37
|
+
* >
|
38
|
+
* <Component />
|
39
|
+
* </PendingSubmissionsContextProvider>
|
40
|
+
* )
|
41
|
+
* }
|
42
|
+
*
|
43
|
+
* const root = document.getElementById('root')
|
44
|
+
* if (root) {
|
45
|
+
* ReactDOM.render(<App />, root)
|
46
|
+
* }
|
47
|
+
* ```
|
48
|
+
*
|
49
|
+
* @param props
|
50
|
+
* @returns
|
51
|
+
* @group Components
|
52
|
+
*/
|
53
|
+
export function PendingSubmissionsContextProvider({ isPendingQueueEnabled, successNotificationTimeoutMs = 5000, children, }) {
|
54
|
+
const isMounted = useIsMounted();
|
55
|
+
const isOffline = useIsOffline();
|
56
|
+
// Using a number as state so we can reset the timer used to close
|
57
|
+
// the snack bar each time a pending queue item is processed
|
58
|
+
const [submittedNotificationCount, setSubmittedNotificationCount] = React.useState(0);
|
59
|
+
const hideSuccessNotification = React.useCallback(() => {
|
60
|
+
setSubmittedNotificationCount(0);
|
61
|
+
}, []);
|
62
|
+
const [isShowingFailedNotification, showFailedNotification, hideFailedNotification,] = useBooleanState(false);
|
63
|
+
const [isProcessingPendingQueue, setIsProcessingPendingQueue] = React.useState(false);
|
64
|
+
const [state, setState] = React.useState(defaultState);
|
65
|
+
const processPendingQueue = React.useCallback(async () => {
|
66
|
+
if (isMounted.current) {
|
67
|
+
setIsProcessingPendingQueue(true);
|
68
|
+
}
|
69
|
+
await submissionService.processPendingQueue({
|
70
|
+
shouldRunExternalIdGeneration: true,
|
71
|
+
shouldRunServerValidation: true,
|
72
|
+
});
|
73
|
+
if (isMounted.current) {
|
74
|
+
setIsProcessingPendingQueue(false);
|
75
|
+
}
|
76
|
+
}, [isMounted]);
|
77
|
+
const reloadPendingSubmissions = React.useCallback(async () => {
|
78
|
+
if (isMounted.current) {
|
79
|
+
setState((currentState) => ({
|
80
|
+
isLoading: true,
|
81
|
+
loadError: null,
|
82
|
+
pendingSubmissions: currentState.pendingSubmissions,
|
83
|
+
}));
|
84
|
+
}
|
85
|
+
let newError = null;
|
86
|
+
let newPendingSubmissions = [];
|
87
|
+
try {
|
88
|
+
newPendingSubmissions =
|
89
|
+
await submissionService.getPendingQueueSubmissions();
|
90
|
+
}
|
91
|
+
catch (error) {
|
92
|
+
newError = error;
|
93
|
+
}
|
94
|
+
if (isMounted.current) {
|
95
|
+
setState({
|
96
|
+
isLoading: false,
|
97
|
+
loadError: newError,
|
98
|
+
pendingSubmissions: newPendingSubmissions,
|
99
|
+
});
|
100
|
+
}
|
101
|
+
}, [isMounted]);
|
102
|
+
React.useEffect(() => {
|
103
|
+
if (!isPendingQueueEnabled) {
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
reloadPendingSubmissions();
|
107
|
+
return submissionService.registerPendingQueueListener((pendingSubmissions, action) => {
|
108
|
+
switch (action) {
|
109
|
+
case 'SUBMIT_SUCCEEDED': {
|
110
|
+
setSubmittedNotificationCount((current) => current + 1);
|
111
|
+
break;
|
112
|
+
}
|
113
|
+
case 'SUBMIT_FAILED': {
|
114
|
+
showFailedNotification();
|
115
|
+
break;
|
116
|
+
}
|
117
|
+
case 'SUBMIT_STARTED': {
|
118
|
+
hideFailedNotification();
|
119
|
+
break;
|
120
|
+
}
|
121
|
+
case 'ADDITION': {
|
122
|
+
processPendingQueue();
|
123
|
+
break;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
setState({
|
127
|
+
isLoading: false,
|
128
|
+
pendingSubmissions,
|
129
|
+
loadError: null,
|
130
|
+
});
|
131
|
+
});
|
132
|
+
}, [
|
133
|
+
hideFailedNotification,
|
134
|
+
isPendingQueueEnabled,
|
135
|
+
processPendingQueue,
|
136
|
+
reloadPendingSubmissions,
|
137
|
+
showFailedNotification,
|
138
|
+
]);
|
139
|
+
React.useEffect(() => {
|
140
|
+
if (!isOffline) {
|
141
|
+
processPendingQueue();
|
142
|
+
}
|
143
|
+
}, [isOffline, processPendingQueue]);
|
144
|
+
React.useEffect(() => {
|
145
|
+
if (submittedNotificationCount > 0) {
|
146
|
+
const timeoutId = setTimeout(() => {
|
147
|
+
hideSuccessNotification();
|
148
|
+
}, successNotificationTimeoutMs);
|
149
|
+
return () => {
|
150
|
+
clearTimeout(timeoutId);
|
151
|
+
};
|
152
|
+
}
|
153
|
+
}, [
|
154
|
+
hideSuccessNotification,
|
155
|
+
submittedNotificationCount,
|
156
|
+
successNotificationTimeoutMs,
|
157
|
+
]);
|
158
|
+
const value = React.useMemo(() => ({
|
159
|
+
...state,
|
160
|
+
isShowingFailedNotification,
|
161
|
+
hideFailedNotification,
|
162
|
+
isProcessingPendingQueue,
|
163
|
+
processPendingQueue,
|
164
|
+
reloadPendingSubmissions,
|
165
|
+
deletePendingSubmission: submissionService.deletePendingQueueSubmission,
|
166
|
+
isShowingSuccessNotification: submittedNotificationCount > 0,
|
167
|
+
hideSuccessNotification,
|
168
|
+
}), [
|
169
|
+
state,
|
170
|
+
isShowingFailedNotification,
|
171
|
+
hideFailedNotification,
|
172
|
+
isProcessingPendingQueue,
|
173
|
+
processPendingQueue,
|
174
|
+
reloadPendingSubmissions,
|
175
|
+
submittedNotificationCount,
|
176
|
+
hideSuccessNotification,
|
177
|
+
]);
|
178
|
+
return (React.createElement(PendingSubmissionsContext.Provider, { value: value }, children));
|
179
|
+
}
|
180
|
+
/**
|
181
|
+
* React hook to get the context value for Pending Submissions. Will throw an
|
182
|
+
* Error if used outside of the `<PendingSubmissionsContextProvider />`
|
183
|
+
* component.
|
184
|
+
*
|
185
|
+
* @returns
|
186
|
+
* @group Hooks
|
187
|
+
*/
|
188
|
+
export default function usePendingSubmissions() {
|
189
|
+
const value = React.useContext(PendingSubmissionsContext);
|
190
|
+
if (!value) {
|
191
|
+
throw new Error(`"usePendingSubmissions" hook was used outside of the "<PendingSubmissionsContextProvider />" component's children.`);
|
192
|
+
}
|
193
|
+
return value;
|
194
|
+
}
|
195
|
+
//# sourceMappingURL=usePendingSubmissions.js.map
|
@@ -0,0 +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;AAqCzC,MAAM,YAAY,GAAG;IACnB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,IAAI;IACf,kBAAkB,EAAE,EAAE;CACvB,CAAA;AAED,MAAM,yBAAyB,GAAG,KA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O,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"]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { localisationService } from '@oneblink/apps';
|
1
|
+
import { localisationService, authService } from '@oneblink/apps';
|
2
2
|
import * as React from 'react';
|
3
3
|
import useFormSubmissionModel from './useFormSubmissionModelContext';
|
4
4
|
import { useRepeatableSetIndexText } from '../form-elements/FormElementRepeatableSet';
|
@@ -9,6 +9,7 @@ export default function useReplaceableText(text) {
|
|
9
9
|
return localisationService.replaceInjectablesWithElementValues(textWithIndex, {
|
10
10
|
submission: formSubmissionModel,
|
11
11
|
formElements: elements,
|
12
|
+
userProfile: authService.getUserProfile() || undefined,
|
12
13
|
});
|
13
14
|
}, [elements, formSubmissionModel, textWithIndex]);
|
14
15
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useReplaceableText.js","sourceRoot":"","sources":["../../src/hooks/useReplaceableText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;
|
1
|
+
{"version":3,"file":"useReplaceableText.js","sourceRoot":"","sources":["../../src/hooks/useReplaceableText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,sBAAsB,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AAErF,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAY;IACrD,MAAM,aAAa,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAA;IACrD,MAAM,EAAE,mBAAmB,EAAE,QAAQ,EAAE,GAAG,sBAAsB,EAAE,CAAA;IAClE,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACxB,OAAO,mBAAmB,CAAC,mCAAmC,CAC5D,aAAa,EACb;YACE,UAAU,EAAE,mBAAmB;YAC/B,YAAY,EAAE,QAAQ;YACtB,WAAW,EAAE,WAAW,CAAC,cAAc,EAAE,IAAI,SAAS;SACvD,CACF,CAAA;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAA;AACpD,CAAC","sourcesContent":["import { localisationService, authService } from '@oneblink/apps'\nimport * as React from 'react'\nimport useFormSubmissionModel from './useFormSubmissionModelContext'\nimport { useRepeatableSetIndexText } from '../form-elements/FormElementRepeatableSet'\n\nexport default function useReplaceableText(text: string) {\n const textWithIndex = useRepeatableSetIndexText(text)\n const { formSubmissionModel, elements } = useFormSubmissionModel()\n return React.useMemo(() => {\n return localisationService.replaceInjectablesWithElementValues(\n textWithIndex,\n {\n submission: formSubmissionModel,\n formElements: elements,\n userProfile: authService.getUserProfile() || undefined,\n },\n )\n }, [elements, formSubmissionModel, textWithIndex])\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;QAC3B,GAAG,OAAO;QACV,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC,EACL,EAAE,CACH,CAAA;IAED,MAAM,qBAAqB,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE;QACzD,IAAI,kBAAkB,CAAC,SAAS,EAAE;YAChC,cAAc,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBAC3B,GAAG,OAAO;gBACV,WAAW,EAAE,IAAI,KAAK,CAAC,oCAAoC,CAAC;aAC7D,CAAC,CAAC,CAAA;YACH,OAAM;SACP;QAED,cAAc,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YAChC,GAAG,YAAY;YACf,WAAW,EAAE,IAAI;YACjB,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC,CAAA;QAEH,IAAI;YACF,MAAM,WAAW,CAAC,MAAM,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\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;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,GAMT;IACC,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,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B,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
@@ -1,4 +1,4 @@
|
|
1
|
-
export { OneBlinkFormUncontrolled as OneBlinkForm, OneBlinkFormControlled, } from './OneBlinkForm';
|
1
|
+
export { OneBlinkFormBaseProps, OneBlinkFormControlledProps, OneBlinkFormUncontrolled as OneBlinkForm, OneBlinkFormControlled, } from './OneBlinkForm';
|
2
2
|
export { default as OneBlinkAutoSaveForm } from './OneBlinkAutoSaveForm';
|
3
3
|
export { default as OneBlinkReadOnlyForm } from './OneBlinkReadOnlyForm';
|
4
4
|
export { OneBlinkFormStoreProvider } from './components/formStore/OneBlinkFormStoreProvider';
|
@@ -12,10 +12,12 @@ 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
|
-
export { default as useAuth, AuthContextProvider } from './hooks/useAuth';
|
18
|
-
export { default as
|
17
|
+
export { default as useAuth, AuthContextProvider, AuthContextValue, } from './hooks/useAuth';
|
18
|
+
export { default as usePendingSubmissions, PendingSubmissionsContextProvider, PendingSubmissionsContextValue, } from './hooks/usePendingSubmissions';
|
19
|
+
export { default as useDrafts, DraftsContextProvider, DraftsContextValue, } from './hooks/useDrafts';
|
20
|
+
export { default as useLoadDataState, LoadDataState, } from './hooks/useLoadDataState';
|
19
21
|
export { default as useFormSubmissionState } from './hooks/useFormSubmissionState';
|
20
22
|
export { default as useFormSubmissionAutoSaveState } from './hooks/useFormSubmissionAutoSaveState';
|
21
23
|
export { default as MuiV4CompatibleDatePicker } from './components/pickers/V4CompatibleDatePicker';
|
@@ -23,3 +25,4 @@ export { default as MuiV4CompatibleDateTimePicker } from './components/pickers/V
|
|
23
25
|
export { default as MuiV4CompatibleTimePicker } from './components/pickers/V4CompatibleTimePicker';
|
24
26
|
export { default as ProgressBar } from './components/renderer/ProgressBar';
|
25
27
|
export { default as PaymentReceipt } from './PaymentReceipt';
|
28
|
+
export * from './types/form';
|
package/dist/index.js
CHANGED
@@ -14,8 +14,10 @@ export { default as useClickOutsideElement } from './hooks/useClickOutsideElemen
|
|
14
14
|
export { default as useIsOffline, IsOfflineContextProvider, } from './hooks/useIsOffline';
|
15
15
|
export { default as useLogin } from './hooks/useLogin';
|
16
16
|
export { default as useSignUp } from './hooks/useSignUp';
|
17
|
-
export { default as useAuth, AuthContextProvider } from './hooks/useAuth';
|
18
|
-
export { default as
|
17
|
+
export { default as useAuth, AuthContextProvider, } from './hooks/useAuth';
|
18
|
+
export { default as usePendingSubmissions, PendingSubmissionsContextProvider, } from './hooks/usePendingSubmissions';
|
19
|
+
export { default as useDrafts, DraftsContextProvider, } from './hooks/useDrafts';
|
20
|
+
export { default as useLoadDataState, } from './hooks/useLoadDataState';
|
19
21
|
export { default as useFormSubmissionState } from './hooks/useFormSubmissionState';
|
20
22
|
export { default as useFormSubmissionAutoSaveState } from './hooks/useFormSubmissionAutoSaveState';
|
21
23
|
export { default as MuiV4CompatibleDatePicker } from './components/pickers/V4CompatibleDatePicker';
|
@@ -23,4 +25,5 @@ export { default as MuiV4CompatibleDateTimePicker } from './components/pickers/V
|
|
23
25
|
export { default as MuiV4CompatibleTimePicker } from './components/pickers/V4CompatibleTimePicker';
|
24
26
|
export { default as ProgressBar } from './components/renderer/ProgressBar';
|
25
27
|
export { default as PaymentReceipt } from './PaymentReceipt';
|
28
|
+
export * from './types/form';
|
26
29
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,IAAI,YAAY,EACxC,sBAAsB,GACvB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACxE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAA;AAC5F,OAAO,EAAE,OAAO,IAAI,mCAAmC,EAAE,MAAM,4DAA4D,CAAA;AAC3H,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,uDAAuD,CAAA;AACjH,OAAO,EAAE,OAAO,IAAI,+BAA+B,EAAE,MAAM,wDAAwD,CAAA;AACnH,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,uDAAuD,CAAA;AACjH,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,+CAA+C,CAAA;AAEjG,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAC9D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACpE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AACtE,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAClF,OAAO,EACL,OAAO,IAAI,YAAY,EACvB,wBAAwB,GACzB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAiB,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EACL,OAAO,IAAI,OAAO,EAClB,mBAAmB,GAEpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,OAAO,IAAI,qBAAqB,EAChC,iCAAiC,GAElC,MAAM,+BAA+B,CAAA;AACtC,OAAO,EACL,OAAO,IAAI,SAAS,EACpB,qBAAqB,GAEtB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,OAAO,IAAI,gBAAgB,GAE5B,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAClF,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,wCAAwC,CAAA;AAElG,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"]}
|
@@ -1,3 +1,2 @@
|
|
1
|
-
import { FormTypes } from '@oneblink/types';
|
2
|
-
|
3
|
-
export default function checkBsbsAreInvalid(form: FormTypes.Form, submission: FormSubmissionModel): boolean;
|
1
|
+
import { FormTypes, SubmissionTypes } from '@oneblink/types';
|
2
|
+
export default function checkBsbsAreInvalid(form: FormTypes.Form, submission: SubmissionTypes.S3SubmissionData['submission']): boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"checkBsbsAreInvalid.js","sourceRoot":"","sources":["../../src/services/checkBsbsAreInvalid.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"checkBsbsAreInvalid.js","sourceRoot":"","sources":["../../src/services/checkBsbsAreInvalid.ts"],"names":[],"mappings":"AAEA,SAAS,oCAAoC,CAC3C,YAAqC,EACrC,UAA0D;IAE1D,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;QACvC,QAAQ,WAAW,CAAC,IAAI,EAAE;YACxB,KAAK,SAAS,CAAC;YACf,KAAK,MAAM,CAAC,CAAC;gBACX,OAAO,oCAAoC,CACzC,WAAW,CAAC,QAAQ,EACpB,UAAU,CACX,CAAA;aACF;YACD,KAAK,MAAM,CAAC,CAAC;gBACX,MAAM,gBAAgB,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;gBACrD,IAAI,CAAC,gBAAgB,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE;oBAC7D,MAAK;iBACN;gBACD,OAAO,oCAAoC,CACzC,WAAW,CAAC,QAAQ,IAAI,EAAE,EAC1B,gBAAkE,CACnE,CAAA;aACF;YACD,KAAK,eAAe,CAAC,CAAC;gBACpB,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;gBAC5C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;oBAC3B,MAAK;iBACN;gBACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC5B,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;wBACzB,oCAAoC,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAClE,CAAA;gBACH,CAAC,CAAC,CAAA;aACH;YACD,KAAK,KAAK,CAAC,CAAC;gBACV,MAAM,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;gBAC1C,IAAI,CAAC,KAAK,EAAE;oBACV,MAAK;iBACN;gBACD,MAAM,QAAQ,GAAG,KAAwC,CAAA;gBACzD,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;oBAChC,OAAO,QAAQ,CAAC,SAAS,CAAA;iBAC1B;aACF;SACF;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,IAAoB,EACpB,UAA0D;IAE1D,OAAO,oCAAoC,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;AACxE,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\n\nfunction checkIfBsbsAreInvalidForFormElements(\n formElements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'],\n): boolean {\n return formElements.some((formElement) => {\n switch (formElement.type) {\n case 'section':\n case 'page': {\n return checkIfBsbsAreInvalidForFormElements(\n formElement.elements,\n submission,\n )\n }\n case 'form': {\n const nestedSubmission = submission[formElement.name]\n if (!nestedSubmission || typeof nestedSubmission !== 'object') {\n break\n }\n return checkIfBsbsAreInvalidForFormElements(\n formElement.elements || [],\n nestedSubmission as SubmissionTypes.S3SubmissionData['submission'],\n )\n }\n case 'repeatableSet': {\n const entries = submission[formElement.name]\n if (!Array.isArray(entries)) {\n break\n }\n return entries.some((entry) => {\n return (\n typeof entry === 'object' &&\n checkIfBsbsAreInvalidForFormElements(formElement.elements, entry)\n )\n })\n }\n case 'bsb': {\n const value = submission[formElement.name]\n if (!value) {\n break\n }\n const bsbValue = value as string | { isInvalid: boolean }\n if (typeof bsbValue === 'object') {\n return bsbValue.isInvalid\n }\n }\n }\n })\n}\n\nexport default function checkBsbsAreInvalid(\n form: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n): boolean {\n return checkIfBsbsAreInvalidForFormElements(form.elements, submission)\n}\n"]}
|
@@ -1,5 +1,4 @@
|
|
1
|
-
import { FormTypes } from '@oneblink/types';
|
1
|
+
import { FormTypes, SubmissionTypes } from '@oneblink/types';
|
2
2
|
import { attachmentsService } from '@oneblink/apps';
|
3
|
-
import { FormSubmissionModel } from '../types/form';
|
4
3
|
export declare function validateAttachmentExists(attachment: attachmentsService.Attachment, attachmentRetentionInDays: number | undefined): attachmentsService.AttachmentError | void;
|
5
|
-
export default function checkIfAttachmentsExist(form: FormTypes.Form, submission:
|
4
|
+
export default function checkIfAttachmentsExist(form: FormTypes.Form, submission: SubmissionTypes.S3SubmissionData['submission'], attachmentRetentionInDays: number | undefined): SubmissionTypes.S3SubmissionData['submission'] | void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"checkIfAttachmentsExist.js","sourceRoot":"","sources":["../../src/services/checkIfAttachmentsExist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAMjC,MAAM,UAAU,wBAAwB,CACtC,UAAyC,EACzC,yBAA6C;IAE7C,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,yBAAyB,EAAE;QAC3E,OAAM;KACP;IAED,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IAClD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACjD,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,yBAAyB,CAAC,CAAA;IACnE,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;I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KAAK,EACL,yBAAyB,CAC1B,CAAA;wBACD,IAAI,cAAc,EAAE;4BAClB,UAAU,GAAG,IAAI,CAAA;4BACjB,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,cAAc,CAAA;yBAC1C;wBACD,MAAK;qBACN;iBACF;aACF;SACF;KACF;IACD,IAAI,UAAU,EAAE;QACd,OAAO,MAAM,CAAA;KACd;AACH,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAC7C,IAAoB,EACpB,UAA+B,EAC/B,yBAA6C;IAE7C,OAAO,sCAAsC,CAC3C,IAAI,CAAC,QAAQ,EACb,UAAU,EACV,yBAAyB,CAC1B,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport { v4 as uuid } from 'uuid'\nimport { attachmentsService } from '@oneblink/apps'\n\nimport { Value as FormElementComplianceValue } from '../form-elements/FormElementCompliance'\nimport { FormSubmissionModel } from '../types/form'\n\nexport function validateAttachmentExists(\n attachment: attachmentsService.Attachment,\n attachmentRetentionInDays: number | undefined,\n): attachmentsService.AttachmentError | void {\n if (attachment.type || !attachment.uploadedAt || !attachmentRetentionInDays) {\n return\n }\n\n const uploadedAt = new Date(attachment.uploadedAt)\n const expiresAt = new Date(attachment.uploadedAt)\n expiresAt.setDate(uploadedAt.getDate() + attachmentRetentionInDays)\n const now = new Date()\n console.log('Checking if attachment still exists', {\n uploadedAt,\n expiresAt,\n attachment,\n })\n // check if attachment exists\n if (expiresAt > now) {\n return\n }\n\n const attachmentError: attachmentsService.AttachmentError = {\n type: 'ERROR',\n errorMessage:\n \"This attachment has been removed based on your administrator's data retention policy, please remove it and upload it again.\",\n _id: uuid(),\n fileName: attachment.fileName,\n isPrivate: attachment.isPrivate,\n }\n return attachmentError\n}\n\nfunction validateAttachmentsExists(\n attachments: unknown,\n attachmentRetentionInDays: number | undefined,\n): attachmentsService.Attachment[] | void {\n if (!Array.isArray(attachments)) {\n return\n }\n const newAttachments = [...attachments]\n let hasChanges = false\n for (let index = 0; index < newAttachments.length; index++) {\n const attachmentError = validateAttachmentExists(\n newAttachments[index] as attachmentsService.Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n newAttachments[index] = attachmentError\n }\n }\n if (hasChanges) {\n return newAttachments\n }\n}\n\nfunction checkIfAttachmentsExistForFormElements(\n formElements: FormTypes.FormElement[],\n submission: FormSubmissionModel,\n attachmentRetentionInDays: number | undefined,\n): FormSubmissionModel | void {\n const result: FormSubmissionModel = {\n ...submission,\n }\n let hasChanges = false\n for (const formElement of formElements) {\n switch (formElement.type) {\n case 'section':\n case 'page': {\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n result,\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n Object.assign(result, newSubmission)\n }\n break\n }\n case 'form': {\n const nestedSubmission = submission[formElement.name]\n if (!nestedSubmission || typeof nestedSubmission !== 'object') {\n break\n }\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements || [],\n nestedSubmission as FormSubmissionModel,\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n result[formElement.name] = newSubmission\n }\n break\n }\n case 'repeatableSet': {\n const entries = submission[formElement.name]\n if (!Array.isArray(entries)) {\n break\n }\n const newEntries = [...entries]\n let hasEntryChanges = false\n for (let index = 0; index < entries.length; index++) {\n const entry = entries[index]\n if (typeof entry === 'object') {\n const newEntry = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n entry,\n attachmentRetentionInDays,\n )\n if (newEntry) {\n hasEntryChanges = true\n newEntries[index] = newEntry\n }\n }\n }\n if (hasEntryChanges) {\n hasChanges = true\n result[formElement.name] = newEntries\n }\n break\n }\n case 'camera':\n case 'draw':\n case 'compliance':\n case 'files': {\n const value = submission[formElement.name]\n if (!value) {\n break\n }\n\n // If the attachment has a type, it has not finished uploading\n switch (formElement.type) {\n case 'camera':\n case 'draw': {\n const attachmentError = validateAttachmentExists(\n value as attachmentsService.Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n result[formElement.name] = attachmentError\n }\n break\n }\n case 'compliance': {\n const newAttachments = validateAttachmentsExists(\n (value as FormElementComplianceValue).files,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = {\n ...(value as FormElementComplianceValue),\n files: newAttachments,\n }\n }\n break\n }\n case 'files': {\n const newAttachments = validateAttachmentsExists(\n value,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = newAttachments\n }\n break\n }\n }\n }\n }\n }\n if (hasChanges) {\n return result\n }\n}\n\nexport default function checkIfAttachmentsExist(\n form: FormTypes.Form,\n submission: FormSubmissionModel,\n attachmentRetentionInDays: number | undefined,\n): FormSubmissionModel | void {\n return checkIfAttachmentsExistForFormElements(\n form.elements,\n submission,\n attachmentRetentionInDays,\n )\n}\n"]}
|
1
|
+
{"version":3,"file":"checkIfAttachmentsExist.js","sourceRoot":"","sources":["../../src/services/checkIfAttachmentsExist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAKjC,MAAM,UAAU,wBAAwB,CACtC,UAAyC,EACzC,yBAA6C;IAE7C,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,yBAAyB,EAAE;QAC3E,OAAM;KACP;IAED,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IAClD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACjD,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,yBAAyB,CAAC,CAAA;IACnE,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAA;IACtB,OAAO,CAAC,GAAG,CAAC,qCAAqC,EAAE;QACjD,UAAU;QACV,SAAS;QACT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,GAAG,IAAI,CAAA;4BACjB,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,cAAc,CAAA;yBAC1C;wBACD,MAAK;qBACN;iBACF;aACF;SACF;KACF;IACD,IAAI,UAAU,EAAE;QACd,OAAO,MAAM,CAAA;KACd;AACH,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAC7C,IAAoB,EACpB,UAA0D,EAC1D,yBAA6C;IAE7C,OAAO,sCAAsC,CAC3C,IAAI,CAAC,QAAQ,EACb,UAAU,EACV,yBAAyB,CAC1B,CAAA;AACH,CAAC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { v4 as uuid } from 'uuid'\nimport { attachmentsService } from '@oneblink/apps'\n\nimport { Value as FormElementComplianceValue } from '../form-elements/FormElementCompliance'\n\nexport function validateAttachmentExists(\n attachment: attachmentsService.Attachment,\n attachmentRetentionInDays: number | undefined,\n): attachmentsService.AttachmentError | void {\n if (attachment.type || !attachment.uploadedAt || !attachmentRetentionInDays) {\n return\n }\n\n const uploadedAt = new Date(attachment.uploadedAt)\n const expiresAt = new Date(attachment.uploadedAt)\n expiresAt.setDate(uploadedAt.getDate() + attachmentRetentionInDays)\n const now = new Date()\n console.log('Checking if attachment still exists', {\n uploadedAt,\n expiresAt,\n attachment,\n })\n // check if attachment exists\n if (expiresAt > now) {\n return\n }\n\n const attachmentError: attachmentsService.AttachmentError = {\n type: 'ERROR',\n errorMessage:\n \"This attachment has been removed based on your administrator's data retention policy, please remove it and upload it again.\",\n _id: uuid(),\n fileName: attachment.fileName,\n isPrivate: attachment.isPrivate,\n }\n return attachmentError\n}\n\nfunction validateAttachmentsExists(\n attachments: unknown,\n attachmentRetentionInDays: number | undefined,\n): attachmentsService.Attachment[] | void {\n if (!Array.isArray(attachments)) {\n return\n }\n const newAttachments = [...attachments]\n let hasChanges = false\n for (let index = 0; index < newAttachments.length; index++) {\n const attachmentError = validateAttachmentExists(\n newAttachments[index] as attachmentsService.Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n newAttachments[index] = attachmentError\n }\n }\n if (hasChanges) {\n return newAttachments\n }\n}\n\nfunction checkIfAttachmentsExistForFormElements(\n formElements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays: number | undefined,\n): SubmissionTypes.S3SubmissionData['submission'] | void {\n const result: SubmissionTypes.S3SubmissionData['submission'] = {\n ...submission,\n }\n let hasChanges = false\n for (const formElement of formElements) {\n switch (formElement.type) {\n case 'section':\n case 'page': {\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n result,\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n Object.assign(result, newSubmission)\n }\n break\n }\n case 'form': {\n const nestedSubmission = submission[formElement.name]\n if (!nestedSubmission || typeof nestedSubmission !== 'object') {\n break\n }\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements || [],\n nestedSubmission as SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n result[formElement.name] = newSubmission\n }\n break\n }\n case 'repeatableSet': {\n const entries = submission[formElement.name]\n if (!Array.isArray(entries)) {\n break\n }\n const newEntries = [...entries]\n let hasEntryChanges = false\n for (let index = 0; index < entries.length; index++) {\n const entry = entries[index]\n if (typeof entry === 'object') {\n const newEntry = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n entry,\n attachmentRetentionInDays,\n )\n if (newEntry) {\n hasEntryChanges = true\n newEntries[index] = newEntry\n }\n }\n }\n if (hasEntryChanges) {\n hasChanges = true\n result[formElement.name] = newEntries\n }\n break\n }\n case 'camera':\n case 'draw':\n case 'compliance':\n case 'files': {\n const value = submission[formElement.name]\n if (!value) {\n break\n }\n\n // If the attachment has a type, it has not finished uploading\n switch (formElement.type) {\n case 'camera':\n case 'draw': {\n const attachmentError = validateAttachmentExists(\n value as attachmentsService.Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n result[formElement.name] = attachmentError\n }\n break\n }\n case 'compliance': {\n const newAttachments = validateAttachmentsExists(\n (value as FormElementComplianceValue).files,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = {\n ...(value as FormElementComplianceValue),\n files: newAttachments,\n }\n }\n break\n }\n case 'files': {\n const newAttachments = validateAttachmentsExists(\n value,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = newAttachments\n }\n break\n }\n }\n }\n }\n }\n if (hasChanges) {\n return result\n }\n}\n\nexport default function checkIfAttachmentsExist(\n form: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays: number | undefined,\n): SubmissionTypes.S3SubmissionData['submission'] | void {\n return checkIfAttachmentsExistForFormElements(\n form.elements,\n submission,\n attachmentRetentionInDays,\n )\n}\n"]}
|
@@ -1,3 +1,2 @@
|
|
1
|
-
import { FormTypes } from '@oneblink/types';
|
2
|
-
|
3
|
-
export default function checkIfBsbsAreValidating(form: FormTypes.Form, submission: FormSubmissionModel): boolean;
|
1
|
+
import { FormTypes, SubmissionTypes } from '@oneblink/types';
|
2
|
+
export default function checkIfBsbsAreValidating(form: FormTypes.Form, submission: SubmissionTypes.S3SubmissionData['submission']): boolean;
|