@oneblink/apps-react 4.1.0-beta.7 → 4.1.0-beta.8
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
package/README.md
CHANGED
@@ -2,12 +2,6 @@
|
|
2
2
|
|
3
3
|
Helpers for OneBlink apps in ReactJS.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Documentation
|
6
6
|
|
7
|
-
|
8
|
-
npm install react@17 react-dom@17 @oneblink/apps-react --save
|
9
|
-
```
|
10
|
-
|
11
|
-
## Usage
|
12
|
-
|
13
|
-
- [Usage Documentation](./docs/README.md)
|
7
|
+
See the [Documentation](https://oneblink.github.io/apps-react/) for more details.
|
@@ -1,12 +1,32 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { OneBlinkFormUncontrolled } from './OneBlinkForm';
|
3
|
-
|
4
|
-
|
3
|
+
declare function OneBlinkAutoSaveForm({ form, initialSubmission, resumeAtElement, autoSaveKey, removeAutoSaveDataBeforeSubmit, removeAutoSaveDataBeforeSaveDraft, onCancel, onSubmit, onSaveDraft, ...props }: React.ComponentProps<typeof OneBlinkFormUncontrolled> & {
|
4
|
+
/** Pass a unique key for this submission e.g. the `externalId` the parameter */
|
5
5
|
autoSaveKey: string;
|
6
|
+
/**
|
7
|
+
* By default, auto save data is removed when the user clicks Submit. If you
|
8
|
+
* would like auto save data to persist and clean up the auto save data later,
|
9
|
+
* pass `false`.
|
10
|
+
*/
|
6
11
|
removeAutoSaveDataBeforeSubmit?: boolean;
|
12
|
+
/**
|
13
|
+
* By default, auto save data is removed when the user clicks Save Draft. If
|
14
|
+
* you would like auto save data to persist and clean up the auto save data
|
15
|
+
* later, pass `false`.
|
16
|
+
*/
|
7
17
|
removeAutoSaveDataBeforeSaveDraft?: boolean;
|
8
|
-
|
9
|
-
|
10
|
-
|
18
|
+
}): JSX.Element;
|
19
|
+
/**
|
20
|
+
* This component is a drop in replacement for {@link OneBlinkForm} with the
|
21
|
+
* addition of auto save happening periodically to prevent users from losing
|
22
|
+
* submission data.
|
23
|
+
*
|
24
|
+
* If you need auto saving with a controlled form, see the
|
25
|
+
* {@link OneBlinkFormControlled} component for a full example.
|
26
|
+
*
|
27
|
+
* @param props
|
28
|
+
* @returns
|
29
|
+
* @group Components
|
30
|
+
*/
|
11
31
|
declare const _default: React.MemoExoticComponent<typeof OneBlinkAutoSaveForm>;
|
12
32
|
export default _default;
|
@@ -26,5 +26,17 @@ function OneBlinkAutoSaveForm({ form, initialSubmission, resumeAtElement, autoSa
|
|
26
26
|
}
|
27
27
|
return (React.createElement(OneBlinkFormBase, { ...props, isReadOnly: false, submission: submission, definition: definition, onCancel: handleCancel, onSubmit: handleSubmit, onSaveDraft: handleSaveDraft, setFormSubmission: setFormSubmission, handleNavigateAway: handleNavigateAway, lastElementUpdated: lastElementUpdated }));
|
28
28
|
}
|
29
|
+
/**
|
30
|
+
* This component is a drop in replacement for {@link OneBlinkForm} with the
|
31
|
+
* addition of auto save happening periodically to prevent users from losing
|
32
|
+
* submission data.
|
33
|
+
*
|
34
|
+
* If you need auto saving with a controlled form, see the
|
35
|
+
* {@link OneBlinkFormControlled} component for a full example.
|
36
|
+
*
|
37
|
+
* @param props
|
38
|
+
* @returns
|
39
|
+
* @group Components
|
40
|
+
*/
|
29
41
|
export default React.memo(OneBlinkAutoSaveForm);
|
30
42
|
//# sourceMappingURL=OneBlinkAutoSaveForm.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"OneBlinkAutoSaveForm.js","sourceRoot":"","sources":["../src/OneBlinkAutoSaveForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,KAAK,MAAM,6BAA6B,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,8BAA8B,MAAM,wCAAwC,CAAA;
|
1
|
+
{"version":3,"file":"OneBlinkAutoSaveForm.js","sourceRoot":"","sources":["../src/OneBlinkAutoSaveForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,SAAS,MAAM,iCAAiC,CAAA;AACvD,OAAO,KAAK,MAAM,6BAA6B,CAAA;AAC/C,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,8BAA8B,MAAM,wCAAwC,CAAA;AAGnF,SAAS,oBAAoB,CAAC,EAC5B,IAAI,EACJ,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,8BAA8B,EAC9B,iCAAiC,EACjC,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,GAAG,KAAK,EAgBT;IACC,MAAM,EACJ,UAAU,EACV,UAAU,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,GACnB,GAAG,8BAA8B,CAAC;QACjC,IAAI;QACJ,iBAAiB;QACjB,eAAe;QACf,WAAW;QACX,8BAA8B;QAC9B,iCAAiC;QACjC,QAAQ;QACR,QAAQ;QACR,WAAW;KACZ,CAAC,CAAA;IAEF,IAAI,2BAA2B,EAAE;QAC/B,OAAO,CACL,6BAAK,SAAS,EAAC,mCAAmC;YAChD,oBAAC,SAAS,IAAC,SAAS,EAAC,mBAAmB,GAAa,CACjD,CACP,CAAA;KACF;IAED,IAAI,6BAA6B,EAAE;QACjC,OAAO,CACL,oBAAC,KAAK,IACJ,MAAM,QACN,KAAK,EAAC,WAAW,EACjB,aAAa,EAAC,4BAA4B,EAC1C,OAAO,EACL;gBACE,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,yEAAyE,EACnF,OAAO,EAAE,kBAAkB,kBAGpB;gBACT,gCACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,wEAAwE,EAClF,OAAO,EAAE,0BAA0B,eAG5B,CACR,uGAKC,CACT,CAAA;KACF;IAED,OAAO,CACL,oBAAC,gBAAgB,OACX,KAAK,EACT,UAAU,EAAE,KAAK,EACjB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,YAAY,EACtB,WAAW,EAAE,eAAe,EAC5B,iBAAiB,EAAE,iBAAiB,EACpC,kBAAkB,EAAE,kBAAkB,EACtC,kBAAkB,EAAE,kBAAkB,GACtC,CACH,CAAA;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,eAAe,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport OnLoading from './components/renderer/OnLoading'\nimport Modal from './components/renderer/Modal'\nimport OneBlinkFormBase from './OneBlinkFormBase'\nimport useFormSubmissionAutoSaveState from './hooks/useFormSubmissionAutoSaveState'\nimport { OneBlinkFormUncontrolled } from './OneBlinkForm'\n\nfunction OneBlinkAutoSaveForm({\n form,\n initialSubmission,\n resumeAtElement,\n autoSaveKey,\n removeAutoSaveDataBeforeSubmit,\n removeAutoSaveDataBeforeSaveDraft,\n onCancel,\n onSubmit,\n onSaveDraft,\n ...props\n}: React.ComponentProps<typeof OneBlinkFormUncontrolled> & {\n /** Pass a unique key for this submission e.g. the `externalId` the parameter */\n autoSaveKey: string\n /**\n * By default, auto save data is removed when the user clicks Submit. If you\n * would like auto save data to persist and clean up the auto save data later,\n * pass `false`.\n */\n removeAutoSaveDataBeforeSubmit?: boolean\n /**\n * By default, auto save data is removed when the user clicks Save Draft. If\n * you would like auto save data to persist and clean up the auto save data\n * later, pass `false`.\n */\n removeAutoSaveDataBeforeSaveDraft?: boolean\n}) {\n const {\n definition,\n submission,\n isLoadingAutoSaveSubmission,\n isAutoSaveSubmissionAvailable,\n startNewSubmission,\n continueAutoSaveSubmission,\n handleSubmit,\n handleCancel,\n handleSaveDraft,\n setFormSubmission,\n handleNavigateAway,\n lastElementUpdated,\n } = useFormSubmissionAutoSaveState({\n form,\n initialSubmission,\n resumeAtElement,\n autoSaveKey,\n removeAutoSaveDataBeforeSubmit,\n removeAutoSaveDataBeforeSaveDraft,\n onCancel,\n onSubmit,\n onSaveDraft,\n })\n\n if (isLoadingAutoSaveSubmission) {\n return (\n <div className=\"cypress-loading has-text-centered\">\n <OnLoading className=\"has-text-centered\"></OnLoading>\n </div>\n )\n }\n\n if (isAutoSaveSubmissionAvailable) {\n return (\n <Modal\n isOpen\n title=\"Continue?\"\n cardClassName=\"cypress-continue-auto-save\"\n actions={\n <>\n <button\n type=\"button\"\n className=\"button ob-button is-light cypress-continue-auto-save-start-again-button\"\n onClick={startNewSubmission}\n >\n Start Again\n </button>\n <button\n type=\"button\"\n className=\"button ob-button is-primary cypress-continue-auto-save-continue-button\"\n onClick={continueAutoSaveSubmission}\n >\n Continue\n </button>\n </>\n }\n >\n We found an in progress submission, would you like to pick up where you\n left off or start again?\n </Modal>\n )\n }\n\n return (\n <OneBlinkFormBase\n {...props}\n isReadOnly={false}\n submission={submission}\n definition={definition}\n onCancel={handleCancel}\n onSubmit={handleSubmit}\n onSaveDraft={handleSaveDraft}\n setFormSubmission={setFormSubmission}\n handleNavigateAway={handleNavigateAway}\n lastElementUpdated={lastElementUpdated}\n />\n )\n}\n\n/**\n * This component is a drop in replacement for {@link OneBlinkForm} with the\n * addition of auto save happening periodically to prevent users from losing\n * submission data.\n *\n * If you need auto saving with a controlled form, see the\n * {@link OneBlinkFormControlled} component for a full example.\n *\n * @param props\n * @returns\n * @group Components\n */\nexport default React.memo(OneBlinkAutoSaveForm)\n"]}
|
package/dist/OneBlinkForm.d.ts
CHANGED
@@ -1,12 +1,562 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { FormTypes } from '@oneblink/types';
|
3
|
-
import {
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
import { OneBlinkFormBaseProps, OneBlinkFormControlledProps } from './OneBlinkFormBase';
|
4
|
+
export { OneBlinkFormBaseProps, OneBlinkFormControlledProps };
|
5
|
+
/**
|
6
|
+
* Similar to {@link OneBlinkForm}, however requires props to control the
|
7
|
+
* `definition` and `submission` values.
|
8
|
+
*
|
9
|
+
* #### Example
|
10
|
+
*
|
11
|
+
* ```tsx
|
12
|
+
* import React from 'react'
|
13
|
+
* import ReactDOM from 'react-dom'
|
14
|
+
* import { FormTypes } from '@oneblink/types'
|
15
|
+
* import {
|
16
|
+
* OneBlinkAppsError,
|
17
|
+
* draftService,
|
18
|
+
* submissionService,
|
19
|
+
* } from '@oneblink/apps'
|
20
|
+
* import {
|
21
|
+
* IsOfflineContextProvider,
|
22
|
+
* OneBlinkFormControlled,
|
23
|
+
* useIsMounted,
|
24
|
+
* useFormSubmissionState,
|
25
|
+
* } from '@oneblink/apps-react'
|
26
|
+
* import '@oneblink/apps-react/dist/styles.css'
|
27
|
+
*
|
28
|
+
* const captchaSiteKey = 'ENTER_YOUR_SITE_KEY_HERE'
|
29
|
+
* const googleMapsApiKey = 'ENTER_YOUR_MAPS_API_KEY_HERE'
|
30
|
+
* const formsAppId = 1
|
31
|
+
* const form: FormTypes.Form = {
|
32
|
+
* id: 1,
|
33
|
+
* name: 'Name of Form',
|
34
|
+
* description: '',
|
35
|
+
* organisationId: 'abc123',
|
36
|
+
* formsAppEnvironmentId: 1,
|
37
|
+
* formsAppIds: [],
|
38
|
+
* elements: [],
|
39
|
+
* isAuthenticated: false,
|
40
|
+
* isMultiPage: false,
|
41
|
+
* isInfoPage: false,
|
42
|
+
* publishStartDate: null,
|
43
|
+
* publishEndDate: null,
|
44
|
+
* postSubmissionAction: 'FORMS_LIBRARY',
|
45
|
+
* submissionEvents: [],
|
46
|
+
* tags: [],
|
47
|
+
* }
|
48
|
+
* const initialSubmission: Record<string, unknown> = {
|
49
|
+
* data: 1,
|
50
|
+
* }
|
51
|
+
*
|
52
|
+
* function FormContainer() {
|
53
|
+
* const isMounted = useIsMounted()
|
54
|
+
*
|
55
|
+
* const [{ definition, submission }, setFormSubmission] =
|
56
|
+
* useFormSubmissionState(form, initialSubmission)
|
57
|
+
*
|
58
|
+
* const [{ isSavingDraft, saveDraftError }, setSaveDraftState] =
|
59
|
+
* React.useState({
|
60
|
+
* isSavingDraft: false,
|
61
|
+
* saveDraftError: null,
|
62
|
+
* })
|
63
|
+
*
|
64
|
+
* const [
|
65
|
+
* { isSubmitting, submitError, formSubmissionResult },
|
66
|
+
* setSubmitState,
|
67
|
+
* ] = React.useState({
|
68
|
+
* formSubmissionResult: null,
|
69
|
+
* isSubmitting: false,
|
70
|
+
* submitError: null,
|
71
|
+
* })
|
72
|
+
*
|
73
|
+
* const handleSubmit = React.useCallback(
|
74
|
+
* async (newFormSubmission: FormTypes.NewFormSubmission) => {
|
75
|
+
* const formSubmission: FormSubmission = Object.assign(
|
76
|
+
* {},
|
77
|
+
* newFormSubmission,
|
78
|
+
* {
|
79
|
+
* formsAppId,
|
80
|
+
* jobId: null,
|
81
|
+
* externalId: null,
|
82
|
+
* draftId: null,
|
83
|
+
* preFillFormDataId: null,
|
84
|
+
* },
|
85
|
+
* )
|
86
|
+
*
|
87
|
+
* setSubmitState({
|
88
|
+
* formSubmissionResult: null,
|
89
|
+
* submitError: null,
|
90
|
+
* isSubmitting: true,
|
91
|
+
* })
|
92
|
+
*
|
93
|
+
* try {
|
94
|
+
* const newFormSubmissionResult = await submissionService.submit({
|
95
|
+
* formSubmission,
|
96
|
+
* })
|
97
|
+
* if (
|
98
|
+
* newFormSubmissionResult.isOffline &&
|
99
|
+
* !newFormSubmissionResult.isInPendingQueue
|
100
|
+
* ) {
|
101
|
+
* throw new OneBlinkAppsError(
|
102
|
+
* 'You cannot submit this form while offline, please try again when connectivity is restored.',
|
103
|
+
* {
|
104
|
+
* isOffline: true,
|
105
|
+
* },
|
106
|
+
* )
|
107
|
+
* }
|
108
|
+
*
|
109
|
+
* if (isMounted.current) {
|
110
|
+
* setSubmitState({
|
111
|
+
* formSubmissionResult: newFormSubmissionResult,
|
112
|
+
* isSubmitting: false,
|
113
|
+
* submitError: null,
|
114
|
+
* })
|
115
|
+
* }
|
116
|
+
* } catch (error) {
|
117
|
+
* if (isMounted.current) {
|
118
|
+
* setSubmitState({
|
119
|
+
* formSubmissionResult: null,
|
120
|
+
* isSubmitting: false,
|
121
|
+
* submitError: error,
|
122
|
+
* })
|
123
|
+
* }
|
124
|
+
* }
|
125
|
+
* },
|
126
|
+
* [isMounted],
|
127
|
+
* )
|
128
|
+
*
|
129
|
+
* const handleSaveDraft = React.useCallback(
|
130
|
+
* async (newDraftSubmission: FormTypes.NewDraftSubmission) => {
|
131
|
+
* const draftSubmission: FormTypes.DraftSubmission = {
|
132
|
+
* ...newDraftSubmission,
|
133
|
+
* formsAppId,
|
134
|
+
* }
|
135
|
+
* setSaveDraftState({
|
136
|
+
* saveDraftError: null,
|
137
|
+
* isSavingDraft: true,
|
138
|
+
* })
|
139
|
+
*
|
140
|
+
* try {
|
141
|
+
* await draftService.addDraft(
|
142
|
+
* {
|
143
|
+
* title: form.name,
|
144
|
+
* formId: form.id,
|
145
|
+
* externalId: null,
|
146
|
+
* jobId: null,
|
147
|
+
* },
|
148
|
+
* draftSubmission,
|
149
|
+
* )
|
150
|
+
*
|
151
|
+
* if (isMounted.current) {
|
152
|
+
* setSaveDraftState({
|
153
|
+
* saveDraftError: null,
|
154
|
+
* isSavingDraft: false,
|
155
|
+
* })
|
156
|
+
* }
|
157
|
+
* } catch (error) {
|
158
|
+
* if (isMounted.current) {
|
159
|
+
* setSaveDraftState({
|
160
|
+
* saveDraftError: error,
|
161
|
+
* isSavingDraft: false,
|
162
|
+
* })
|
163
|
+
* }
|
164
|
+
* }
|
165
|
+
* },
|
166
|
+
* [isMounted],
|
167
|
+
* )
|
168
|
+
*
|
169
|
+
* const handleCancel = React.useCallback(() => {
|
170
|
+
* // handle cancel here...
|
171
|
+
* }, [])
|
172
|
+
*
|
173
|
+
* if (isSubmitting) {
|
174
|
+
* // Render submitting animation/loading
|
175
|
+
* }
|
176
|
+
*
|
177
|
+
* if (submitError) {
|
178
|
+
* // Render error while submitting
|
179
|
+
* }
|
180
|
+
*
|
181
|
+
* if (isSavingDraft) {
|
182
|
+
* // Render saving draft animation/loading
|
183
|
+
* }
|
184
|
+
*
|
185
|
+
* if (saveDraftError) {
|
186
|
+
* // Render error while saving draft
|
187
|
+
* }
|
188
|
+
*
|
189
|
+
* if (formSubmissionResult) {
|
190
|
+
* // Render submission success
|
191
|
+
* }
|
192
|
+
*
|
193
|
+
* return (
|
194
|
+
* <OneBlinkFormControlled
|
195
|
+
* captchaSiteKey={captchaSiteKey}
|
196
|
+
* googleMapsApiKey={googleMapsApiKey}
|
197
|
+
* formsAppId={formsAppId}
|
198
|
+
* definition={definition}
|
199
|
+
* submission={submission}
|
200
|
+
* setFormSubmission={setFormSubmission}
|
201
|
+
* onCancel={handleCancel}
|
202
|
+
* onSubmit={handleSubmit}
|
203
|
+
* onSaveDraft={handleSaveDraft}
|
204
|
+
* />
|
205
|
+
* )
|
206
|
+
* }
|
207
|
+
*
|
208
|
+
* function App() {
|
209
|
+
* return (
|
210
|
+
* <IsOfflineContextProvider>
|
211
|
+
* <FormContainer />
|
212
|
+
* </IsOfflineContextProvider>
|
213
|
+
* )
|
214
|
+
* }
|
215
|
+
*
|
216
|
+
* const root = document.getElementById('root')
|
217
|
+
* if (root) {
|
218
|
+
* ReactDOM.render(<App />, root)
|
219
|
+
* }
|
220
|
+
* ```
|
221
|
+
*
|
222
|
+
* #### Implementing Controlled Auto Save
|
223
|
+
*
|
224
|
+
* The {@link OneBlinkAutoSaveForm} component does not offer props to allow for a
|
225
|
+
* controlled form (i.e. having access to `submission` and `definition` values).
|
226
|
+
* To implement a controlled version of the `<OneBlinkAutoSaveForm />`
|
227
|
+
* component, use the example component below.
|
228
|
+
*
|
229
|
+
* ```tsx
|
230
|
+
* import * as React from 'react'
|
231
|
+
* import {
|
232
|
+
* OneBlinkAutoSaveForm,
|
233
|
+
* OneBlinkFormControlled,
|
234
|
+
* useFormSubmissionAutoSaveState,
|
235
|
+
* } from '@oneblink/apps-react'
|
236
|
+
*
|
237
|
+
* function OneBlinkAutoSaveFormControlled({
|
238
|
+
* form,
|
239
|
+
* initialSubmission,
|
240
|
+
* autoSaveKey,
|
241
|
+
* onCancel,
|
242
|
+
* onSubmit,
|
243
|
+
* onSaveDraft,
|
244
|
+
* ...props
|
245
|
+
* }: React.ComponentProps<typeof OneBlinkAutoSaveForm>) {
|
246
|
+
* const {
|
247
|
+
* definition,
|
248
|
+
* submission,
|
249
|
+
* isLoadingAutoSaveSubmission,
|
250
|
+
* isAutoSaveSubmissionAvailable,
|
251
|
+
* startNewSubmission,
|
252
|
+
* continueAutoSaveSubmission,
|
253
|
+
* handleSubmit,
|
254
|
+
* handleCancel,
|
255
|
+
* handleSaveDraft,
|
256
|
+
* setFormSubmission,
|
257
|
+
* } = useFormSubmissionAutoSaveState({
|
258
|
+
* form,
|
259
|
+
* initialSubmission,
|
260
|
+
* autoSaveKey,
|
261
|
+
* onCancel,
|
262
|
+
* onSubmit,
|
263
|
+
* onSaveDraft,
|
264
|
+
* })
|
265
|
+
*
|
266
|
+
* // This is just an example of how you could intercept
|
267
|
+
* // the change event when a user enters/selects a value
|
268
|
+
* // on the form.
|
269
|
+
* const customSetFormSubmission = React.useCallback(
|
270
|
+
* (formSubmission) => {
|
271
|
+
* setFormSubmission((currentFormSubmission) => {
|
272
|
+
* const newFormSubmission =
|
273
|
+
* typeof formSubmission === 'function'
|
274
|
+
* ? formSubmission(currentFormSubmission)
|
275
|
+
* : formSubmission
|
276
|
+
*
|
277
|
+
* // This is where you can access the updated
|
278
|
+
* // submission data or form definition.
|
279
|
+
* // You could even change the form definition
|
280
|
+
* // programmatically based on user inputs.
|
281
|
+
* console.log(
|
282
|
+
* 'A change has occurred to the submission',
|
283
|
+
* newFormSubmission.submission,
|
284
|
+
* )
|
285
|
+
* newFormSubmission.definition.isInfoPage =
|
286
|
+
* !newFormSubmission.submission.doesTheUserNeedToSubmit
|
287
|
+
*
|
288
|
+
* return newFormSubmission
|
289
|
+
* })
|
290
|
+
* },
|
291
|
+
* [setFormSubmission],
|
292
|
+
* )
|
293
|
+
*
|
294
|
+
* if (isLoadingAutoSaveSubmission) {
|
295
|
+
* return <p>Checking for auto save data...</p>
|
296
|
+
* }
|
297
|
+
*
|
298
|
+
* if (isAutoSaveSubmissionAvailable) {
|
299
|
+
* return (
|
300
|
+
* <>
|
301
|
+
* <p>Do you want to use the auto save data?</p>
|
302
|
+
* <button onClick={startNewSubmission}>No, start again</button>
|
303
|
+
* <button onClick={continueAutoSaveSubmission}>
|
304
|
+
* Yes, continue
|
305
|
+
* </button>
|
306
|
+
* </>
|
307
|
+
* )
|
308
|
+
* }
|
309
|
+
*
|
310
|
+
* return (
|
311
|
+
* <OneBlinkFormControlled
|
312
|
+
* {...props}
|
313
|
+
* submission={submission}
|
314
|
+
* definition={definition}
|
315
|
+
* onCancel={handleCancel}
|
316
|
+
* onSubmit={handleSubmit}
|
317
|
+
* onSaveDraft={handleSaveDraft}
|
318
|
+
* setFormSubmission={customSetFormSubmission}
|
319
|
+
* />
|
320
|
+
* )
|
321
|
+
* }
|
322
|
+
*
|
323
|
+
* export default React.memo(OneBlinkAutoSaveFormControlled)
|
324
|
+
* ```
|
325
|
+
*
|
326
|
+
* @param props
|
327
|
+
* @returns
|
328
|
+
* @group Components
|
329
|
+
*/
|
330
|
+
declare const OneBlinkFormControlled: React.NamedExoticComponent<OneBlinkFormBaseProps & OneBlinkFormControlledProps>;
|
331
|
+
/**
|
332
|
+
* Component for rendering a OneBlink Form. This component will render the
|
333
|
+
* submit, cancel and save draft buttons but it is up to the developer to
|
334
|
+
* implement what happens when those buttons are clicked.
|
335
|
+
*
|
336
|
+
* It is also recommended to import the `css` from this library as well.
|
337
|
+
*
|
338
|
+
* ```js
|
339
|
+
* import { OneBlinkForm } from '@oneblink/apps-react'
|
340
|
+
* import '@oneblink/apps-react/dist/styles.css'
|
341
|
+
* ```
|
342
|
+
*
|
343
|
+
* #### Example
|
344
|
+
*
|
345
|
+
* ```tsx
|
346
|
+
* import React from 'react'
|
347
|
+
* import ReactDOM from 'react-dom'
|
348
|
+
* import { FormTypes } from '@oneblink/types'
|
349
|
+
* import {
|
350
|
+
* OneBlinkAppsError,
|
351
|
+
* draftService,
|
352
|
+
* submissionService,
|
353
|
+
* } from '@oneblink/apps'
|
354
|
+
* import {
|
355
|
+
* IsOfflineContextProvider,
|
356
|
+
* OneBlinkForm,
|
357
|
+
* useIsMounted,
|
358
|
+
* } from '@oneblink/apps-react'
|
359
|
+
* import '@oneblink/apps-react/dist/styles.css'
|
360
|
+
*
|
361
|
+
* const captchaSiteKey = 'ENTER_YOUR_SITE_KEY_HERE'
|
362
|
+
* const googleMapsApiKey = 'ENTER_YOUR_MAPS_API_KEY_HERE'
|
363
|
+
* const formsAppId = 1
|
364
|
+
* const form: FormTypes.Form = {
|
365
|
+
* id: 1,
|
366
|
+
* name: 'Name of Form',
|
367
|
+
* description: '',
|
368
|
+
* organisationId: 'abc123',
|
369
|
+
* formsAppEnvironmentId: 1,
|
370
|
+
* formsAppIds: [],
|
371
|
+
* elements: [],
|
372
|
+
* isAuthenticated: false,
|
373
|
+
* isMultiPage: false,
|
374
|
+
* isInfoPage: false,
|
375
|
+
* publishStartDate: null,
|
376
|
+
* publishEndDate: null,
|
377
|
+
* postSubmissionAction: 'FORMS_LIBRARY',
|
378
|
+
* submissionEvents: [],
|
379
|
+
* tags: [],
|
380
|
+
* }
|
381
|
+
*
|
382
|
+
* function FormContainer() {
|
383
|
+
* const isMounted = useIsMounted()
|
384
|
+
*
|
385
|
+
* const [{ isSavingDraft, saveDraftError }, setSaveDraftState] =
|
386
|
+
* React.useState({
|
387
|
+
* isSavingDraft: false,
|
388
|
+
* saveDraftError: null,
|
389
|
+
* })
|
390
|
+
*
|
391
|
+
* const [
|
392
|
+
* { isSubmitting, submitError, formSubmissionResult },
|
393
|
+
* setSubmitState,
|
394
|
+
* ] = React.useState({
|
395
|
+
* formSubmissionResult: null,
|
396
|
+
* isSubmitting: false,
|
397
|
+
* submitError: null,
|
398
|
+
* })
|
399
|
+
*
|
400
|
+
* const handleSubmit = React.useCallback(
|
401
|
+
* async (newFormSubmission: FormTypes.NewFormSubmission) => {
|
402
|
+
* const formSubmission: FormSubmission = Object.assign(
|
403
|
+
* {},
|
404
|
+
* newFormSubmission,
|
405
|
+
* {
|
406
|
+
* formsAppId,
|
407
|
+
* jobId: null,
|
408
|
+
* externalId: null,
|
409
|
+
* draftId: null,
|
410
|
+
* preFillFormDataId: null,
|
411
|
+
* },
|
412
|
+
* )
|
413
|
+
*
|
414
|
+
* setSubmitState({
|
415
|
+
* formSubmissionResult: null,
|
416
|
+
* submitError: null,
|
417
|
+
* isSubmitting: true,
|
418
|
+
* })
|
419
|
+
*
|
420
|
+
* try {
|
421
|
+
* const newFormSubmissionResult = await submissionService.submit({
|
422
|
+
* formSubmission,
|
423
|
+
* })
|
424
|
+
* if (
|
425
|
+
* newFormSubmissionResult.isOffline &&
|
426
|
+
* !newFormSubmissionResult.isInPendingQueue
|
427
|
+
* ) {
|
428
|
+
* throw new OneBlinkAppsError(
|
429
|
+
* 'You cannot submit this form while offline, please try again when connectivity is restored.',
|
430
|
+
* {
|
431
|
+
* isOffline: true,
|
432
|
+
* },
|
433
|
+
* )
|
434
|
+
* }
|
435
|
+
*
|
436
|
+
* if (isMounted.current) {
|
437
|
+
* setSubmitState({
|
438
|
+
* formSubmissionResult: newFormSubmissionResult,
|
439
|
+
* isSubmitting: false,
|
440
|
+
* submitError: null,
|
441
|
+
* })
|
442
|
+
* }
|
443
|
+
* } catch (error) {
|
444
|
+
* if (isMounted.current) {
|
445
|
+
* setSubmitState({
|
446
|
+
* formSubmissionResult: null,
|
447
|
+
* isSubmitting: false,
|
448
|
+
* submitError: error,
|
449
|
+
* })
|
450
|
+
* }
|
451
|
+
* }
|
452
|
+
* },
|
453
|
+
* [isMounted],
|
454
|
+
* )
|
455
|
+
*
|
456
|
+
* const handleSaveDraft = React.useCallback(
|
457
|
+
* async (newDraftSubmission: FormTypes.NewDraftSubmission) => {
|
458
|
+
* const draftSubmission: FormTypes.DraftSubmission = {
|
459
|
+
* ...newDraftSubmission,
|
460
|
+
* formsAppId,
|
461
|
+
* }
|
462
|
+
* setSaveDraftState({
|
463
|
+
* saveDraftError: null,
|
464
|
+
* isSavingDraft: true,
|
465
|
+
* })
|
466
|
+
*
|
467
|
+
* try {
|
468
|
+
* await draftService.addDraft(
|
469
|
+
* {
|
470
|
+
* title: form.name,
|
471
|
+
* formId: form.id,
|
472
|
+
* externalId: null,
|
473
|
+
* jobId: null,
|
474
|
+
* },
|
475
|
+
* draftSubmission,
|
476
|
+
* )
|
477
|
+
*
|
478
|
+
* if (isMounted.current) {
|
479
|
+
* setSaveDraftState({
|
480
|
+
* saveDraftError: null,
|
481
|
+
* isSavingDraft: false,
|
482
|
+
* })
|
483
|
+
* }
|
484
|
+
* } catch (error) {
|
485
|
+
* if (isMounted.current) {
|
486
|
+
* setSaveDraftState({
|
487
|
+
* saveDraftError: error,
|
488
|
+
* isSavingDraft: false,
|
489
|
+
* })
|
490
|
+
* }
|
491
|
+
* }
|
492
|
+
* },
|
493
|
+
* [isMounted],
|
494
|
+
* )
|
495
|
+
*
|
496
|
+
* const handleCancel = React.useCallback(() => {
|
497
|
+
* // handle cancel here...
|
498
|
+
* }, [isMounted])
|
499
|
+
*
|
500
|
+
* if (isSubmitting) {
|
501
|
+
* // Render submitting animation/loading
|
502
|
+
* }
|
503
|
+
*
|
504
|
+
* if (submitError) {
|
505
|
+
* // Render error while submitting
|
506
|
+
* }
|
507
|
+
*
|
508
|
+
* if (isSavingDraft) {
|
509
|
+
* // Render saving draft animation/loading
|
510
|
+
* }
|
511
|
+
*
|
512
|
+
* if (saveDraftError) {
|
513
|
+
* // Render error while saving draft
|
514
|
+
* }
|
515
|
+
*
|
516
|
+
* if (formSubmissionResult) {
|
517
|
+
* // Render submission success
|
518
|
+
* }
|
519
|
+
*
|
520
|
+
* return (
|
521
|
+
* <OneBlinkForm
|
522
|
+
* captchaSiteKey={captchaSiteKey}
|
523
|
+
* googleMapsApiKey={googleMapsApiKey}
|
524
|
+
* formsAppId={formsAppId}
|
525
|
+
* form={form}
|
526
|
+
* onCancel={handleCancel}
|
527
|
+
* onSubmit={handleSubmit}
|
528
|
+
* onSaveDraft={handleSaveDraft}
|
529
|
+
* attachmentRetentionInDays={1}
|
530
|
+
* />
|
531
|
+
* )
|
532
|
+
* }
|
533
|
+
*
|
534
|
+
* function App() {
|
535
|
+
* return (
|
536
|
+
* <IsOfflineContextProvider>
|
537
|
+
* <FormContainer />
|
538
|
+
* </IsOfflineContextProvider>
|
539
|
+
* )
|
540
|
+
* }
|
541
|
+
*
|
542
|
+
* const root = document.getElementById('root')
|
543
|
+
* if (root) {
|
544
|
+
* ReactDOM.render(<App />, root)
|
545
|
+
* }
|
546
|
+
* ```
|
547
|
+
*
|
548
|
+
* @param props
|
549
|
+
* @returns
|
550
|
+
* @group Components
|
551
|
+
*/
|
552
|
+
declare const OneBlinkFormUncontrolled: React.NamedExoticComponent<OneBlinkFormBaseProps & {
|
553
|
+
/** The OneBlink Form to render */
|
7
554
|
form: FormTypes.Form;
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
555
|
+
/** The initial submission data */
|
556
|
+
initialSubmission?: {
|
557
|
+
[name: string]: unknown;
|
558
|
+
} | undefined;
|
559
|
+
/** The element to resume the form at. */
|
560
|
+
resumeAtElement?: FormTypes.FormElement | undefined;
|
561
|
+
}>;
|
12
562
|
export { OneBlinkFormControlled, OneBlinkFormUncontrolled };
|