@oneblink/apps-react 5.13.0-beta.2 → 5.13.0-beta.4

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.
@@ -10,6 +10,7 @@ const ReverseGeocodeContext = React.createContext({
10
10
  isReverseGeocoding: false,
11
11
  });
12
12
  export default function ReverseGeocode({ value, element, onLookup, children, }) {
13
+ var _a;
13
14
  const coords = React.useMemo(() => parseLocationValue(value), [value]);
14
15
  const [reverseGeocodingState, setReverseGeocodingState] = React.useState({
15
16
  isReverseGeocoding: false,
@@ -19,12 +20,12 @@ export default function ReverseGeocode({ value, element, onLookup, children, })
19
20
  const formSubmissionModel = useFormSubmissionModel();
20
21
  const formIsReadOnly = useFormIsReadOnly();
21
22
  const formattedAddressElement = React.useMemo(() => {
22
- if (element.showStreetAddress && element.formattedAddressElementId) {
23
- return formElementsService.findFormElement(formSubmissionModel.elements, (el) => el.id === element.formattedAddressElementId);
23
+ var _a;
24
+ if ((_a = element.reverseGeocoding) === null || _a === void 0 ? void 0 : _a.formattedAddressElementId) {
25
+ return formElementsService.findFormElement(formSubmissionModel.elements, (el) => { var _a; return el.id === ((_a = element.reverseGeocoding) === null || _a === void 0 ? void 0 : _a.formattedAddressElementId); });
24
26
  }
25
27
  }, [
26
- element.formattedAddressElementId,
27
- element.showStreetAddress,
28
+ (_a = element.reverseGeocoding) === null || _a === void 0 ? void 0 : _a.formattedAddressElementId,
28
29
  formSubmissionModel.elements,
29
30
  ]);
30
31
  const mergeReverseGeocodeData = React.useCallback((reverseGeocodeResult) => {
@@ -42,37 +43,34 @@ export default function ReverseGeocode({ value, element, onLookup, children, })
42
43
  React.useEffect(() => {
43
44
  const abortController = new AbortController();
44
45
  const effect = async () => {
46
+ var _a, _b;
45
47
  setReverseGeocodingState({ isReverseGeocoding: true });
46
48
  try {
47
49
  if (coords && formattedAddressElement) {
48
- if (element.showStreetAddress && formattedAddressElement) {
49
- const reverseGeocodeResult = {};
50
+ if (element.reverseGeocoding && formattedAddressElement) {
51
+ const mergeReverseGeocodeResult = {};
52
+ const reverseGeocodeResult = await formService.getGeoscapeReverseGeocoding({
53
+ lat: coords.latitude,
54
+ lng: coords.longitude,
55
+ formId: formDefinition.id,
56
+ abortSignal: abortController.signal,
57
+ });
50
58
  switch (formattedAddressElement.type) {
51
59
  case 'text': {
52
- const { reverseGeocodeResult: { formatted_address }, } = await formService.getGoogleMapsReverseGeocoding({
53
- lat: coords.latitude,
54
- lng: coords.longitude,
55
- formId: formDefinition.id,
56
- abortSignal: abortController.signal,
57
- });
58
- reverseGeocodeResult[formattedAddressElement.name] =
59
- formatted_address;
60
+ if ((_a = reverseGeocodeResult.addressDetails) === null || _a === void 0 ? void 0 : _a.formattedAddress) {
61
+ mergeReverseGeocodeResult[formattedAddressElement.name] =
62
+ (_b = reverseGeocodeResult.addressDetails) === null || _b === void 0 ? void 0 : _b.formattedAddress;
63
+ }
60
64
  break;
61
65
  }
62
66
  case 'geoscapeAddress': {
63
- const { reverseGeocodeResult: geoscapeReverseGeocodeResult } = await formService.getGeoscapeReverseGeocoding({
64
- lat: coords.latitude,
65
- lng: coords.longitude,
66
- formId: formDefinition.id,
67
- abortSignal: abortController.signal,
68
- });
69
- reverseGeocodeResult[formattedAddressElement.name] =
70
- geoscapeReverseGeocodeResult;
67
+ mergeReverseGeocodeResult[formattedAddressElement.name] =
68
+ reverseGeocodeResult;
71
69
  break;
72
70
  }
73
71
  }
74
72
  if (!abortController.signal.aborted) {
75
- mergeReverseGeocodeData(reverseGeocodeResult);
73
+ mergeReverseGeocodeData(mergeReverseGeocodeResult);
76
74
  }
77
75
  }
78
76
  }
@@ -101,7 +99,7 @@ export default function ReverseGeocode({ value, element, onLookup, children, })
101
99
  return () => abortController.abort();
102
100
  }, [
103
101
  coords,
104
- element.showStreetAddress,
102
+ element.reverseGeocoding,
105
103
  formDefinition.id,
106
104
  formDefinition.organisationId,
107
105
  formattedAddressElement,
@@ -1 +1 @@
1
- {"version":3,"file":"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ACN,OAAO,CAAC,iBAAiB;QACzB,cAAc,CAAC,EAAE;QACjB,cAAc,CAAC,cAAc;QAC7B,uBAAuB;QACvB,uBAAuB;QACvB,SAAS;QACT,cAAc;KACf,CAAC,CAAA;IAEF,OAAO,CACL,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,qBAAqB,IACzD,QAAQ,CACsB,CAClC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,MAAM,qBAAqB,GAAG,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAA;IACrE,IAAI,CAAC,qBAAqB,EAAE;QAC1B,MAAM,IAAI,SAAS,CACjB,iHAAiH,CAClH,CAAA;KACF;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC","sourcesContent":["import * as React from 'react'\n\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { formService, OneBlinkAppsError } from '@oneblink/apps'\nimport { formElementsService } from '@oneblink/sdk-core'\n\nimport { parseLocationValue } from '../../form-elements/FormElementLocation'\nimport useFormSubmissionModel from '../../hooks/useFormSubmissionModelContext'\nimport useFormDefinition from '../../hooks/useFormDefinition'\nimport useFormIsReadOnly from '../../hooks/useFormIsReadOnly'\nimport { FormElementLookupHandler } from '../../types/form'\nimport useIsOffline from '../../hooks/useIsOffline'\n\ntype ReverseGeocodeContextValue = {\n isReverseGeocoding: boolean\n reverseGeocodingErrorMsg?: string\n}\n\nconst ReverseGeocodeContext = React.createContext<ReverseGeocodeContextValue>({\n isReverseGeocoding: false,\n})\n\nexport default function ReverseGeocode({\n value,\n element,\n onLookup,\n children,\n}: React.PropsWithChildren<{\n value: unknown\n element: FormTypes.LocationElement\n onLookup: FormElementLookupHandler\n}>) {\n const coords = React.useMemo(() => parseLocationValue(value), [value])\n const [reverseGeocodingState, setReverseGeocodingState] =\n React.useState<ReverseGeocodeContextValue>({\n isReverseGeocoding: false,\n })\n const isOffline = useIsOffline()\n\n const formDefinition = useFormDefinition()\n const formSubmissionModel = useFormSubmissionModel()\n const formIsReadOnly = useFormIsReadOnly()\n\n const formattedAddressElement = React.useMemo(() => {\n if (element.showStreetAddress && element.formattedAddressElementId) {\n return formElementsService.findFormElement(\n formSubmissionModel.elements,\n (el) => el.id === element.formattedAddressElementId,\n )\n }\n }, [\n element.formattedAddressElementId,\n element.showStreetAddress,\n formSubmissionModel.elements,\n ])\n\n const mergeReverseGeocodeData = React.useCallback(\n (reverseGeocodeResult: SubmissionTypes.S3SubmissionData['submission']) => {\n onLookup(({ submission, elements, executedLookups }) => {\n return {\n elements,\n submission: {\n ...submission,\n ...reverseGeocodeResult,\n },\n executedLookups,\n }\n })\n },\n [onLookup],\n )\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const effect = async () => {\n setReverseGeocodingState({ isReverseGeocoding: true })\n try {\n if (coords && formattedAddressElement) {\n if (element.showStreetAddress && formattedAddressElement) {\n const reverseGeocodeResult: SubmissionTypes.S3SubmissionData['submission'] =\n {}\n switch (formattedAddressElement.type) {\n case 'text': {\n const {\n reverseGeocodeResult: { formatted_address },\n } = await formService.getGoogleMapsReverseGeocoding({\n lat: coords.latitude,\n lng: coords.longitude,\n formId: formDefinition.id,\n abortSignal: abortController.signal,\n })\n reverseGeocodeResult[formattedAddressElement.name] =\n formatted_address\n break\n }\n case 'geoscapeAddress': {\n const { reverseGeocodeResult: geoscapeReverseGeocodeResult } =\n await formService.getGeoscapeReverseGeocoding({\n lat: coords.latitude,\n lng: coords.longitude,\n formId: formDefinition.id,\n abortSignal: abortController.signal,\n })\n reverseGeocodeResult[formattedAddressElement.name] =\n geoscapeReverseGeocodeResult\n break\n }\n }\n if (!abortController.signal.aborted) {\n mergeReverseGeocodeData(reverseGeocodeResult)\n }\n }\n }\n setReverseGeocodingState({\n isReverseGeocoding: false,\n })\n } catch (e) {\n let errorMsg = 'Could not find your address.'\n if (e instanceof OneBlinkAppsError && e.httpStatusCode !== 404) {\n errorMsg = e.message\n }\n\n if (isOffline) {\n errorMsg =\n 'It looks like you&apos;re offline. Please try again when connectivity is restored.'\n }\n setReverseGeocodingState({\n isReverseGeocoding: false,\n reverseGeocodingErrorMsg: errorMsg,\n })\n }\n }\n\n if (!formIsReadOnly) {\n effect()\n }\n\n return () => abortController.abort()\n }, [\n coords,\n element.showStreetAddress,\n formDefinition.id,\n formDefinition.organisationId,\n formattedAddressElement,\n mergeReverseGeocodeData,\n isOffline,\n formIsReadOnly,\n ])\n\n return (\n <ReverseGeocodeContext.Provider value={reverseGeocodingState}>\n {children}\n </ReverseGeocodeContext.Provider>\n )\n}\n\nexport function useReverseGeocodeContext() {\n const reverseGeocodeContext = React.useContext(ReverseGeocodeContext)\n if (!reverseGeocodeContext) {\n throw new TypeError(\n 'You have attempted to run the hook \"useReverseGeocodeContext()\" outside of the \"ReverseGeocodeContext\" context.',\n )\n }\n return reverseGeocodeContext\n}\n"]}
1
+ {"version":3,"file":"ReverseGeocode.js","sourceRoot":"","sources":["../../../src/components/renderer/ReverseGeocode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAA;AAC5E,OAAO,sBAAsB,MAAM,2CAA2C,CAAA;AAC9E,OAAO,iBAAiB,MAAM,+BAA+B,CAAA;AAC7D,OAAO,iBAAiB,MAAM,+BAA+B,CAAA;AAE7D,OAAO,YAAY,MAAM,0BAA0B,CAAA;AAOnD,MAAM,qBAAqB,GAAG,KAAK,CAAC,aAAa,CAA6B;IAC5E,kBAAkB,EAAE,KAAK;CAC1B,CAAC,CAAA;AAEF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,KAAK,EACL,OAAO,EACP,QAAQ,EACR,QAAQ,GAKR;;IACA,MAAM,MAAM,GAAG,KAA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KAAK,GAAG,EAAE;oBAC9D,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAA;iBACrB;gBAED,IAAI,SAAS,EAAE;oBACb,QAAQ;wBACN,oFAAoF,CAAA;iBACvF;gBACD,wBAAwB,CAAC;oBACvB,kBAAkB,EAAE,KAAK;oBACzB,wBAAwB,EAAE,QAAQ;iBACnC,CAAC,CAAA;aACH;QACH,CAAC,CAAA;QAED,IAAI,CAAC,cAAc,EAAE;YACnB,MAAM,EAAE,CAAA;SACT;QAED,OAAO,GAAG,EAAE,CAAC,eAAe,CAAC,KAAK,EAAE,CAAA;IACtC,CAAC,EAAE;QACD,MAAM;QACN,OAAO,CAAC,gBAAgB;QACxB,cAAc,CAAC,EAAE;QACjB,cAAc,CAAC,cAAc;QAC7B,uBAAuB;QACvB,uBAAuB;QACvB,SAAS;QACT,cAAc;KACf,CAAC,CAAA;IAEF,OAAO,CACL,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,qBAAqB,IACzD,QAAQ,CACsB,CAClC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB;IACtC,MAAM,qBAAqB,GAAG,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAA;IACrE,IAAI,CAAC,qBAAqB,EAAE;QAC1B,MAAM,IAAI,SAAS,CACjB,iHAAiH,CAClH,CAAA;KACF;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC","sourcesContent":["import * as React from 'react'\n\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { formService, OneBlinkAppsError } from '@oneblink/apps'\nimport { formElementsService } from '@oneblink/sdk-core'\n\nimport { parseLocationValue } from '../../form-elements/FormElementLocation'\nimport useFormSubmissionModel from '../../hooks/useFormSubmissionModelContext'\nimport useFormDefinition from '../../hooks/useFormDefinition'\nimport useFormIsReadOnly from '../../hooks/useFormIsReadOnly'\nimport { FormElementLookupHandler } from '../../types/form'\nimport useIsOffline from '../../hooks/useIsOffline'\n\ntype ReverseGeocodeContextValue = {\n isReverseGeocoding: boolean\n reverseGeocodingErrorMsg?: string\n}\n\nconst ReverseGeocodeContext = React.createContext<ReverseGeocodeContextValue>({\n isReverseGeocoding: false,\n})\n\nexport default function ReverseGeocode({\n value,\n element,\n onLookup,\n children,\n}: React.PropsWithChildren<{\n value: unknown\n element: FormTypes.LocationElement\n onLookup: FormElementLookupHandler\n}>) {\n const coords = React.useMemo(() => parseLocationValue(value), [value])\n const [reverseGeocodingState, setReverseGeocodingState] =\n React.useState<ReverseGeocodeContextValue>({\n isReverseGeocoding: false,\n })\n const isOffline = useIsOffline()\n\n const formDefinition = useFormDefinition()\n const formSubmissionModel = useFormSubmissionModel()\n const formIsReadOnly = useFormIsReadOnly()\n\n const formattedAddressElement = React.useMemo(() => {\n if (element.reverseGeocoding?.formattedAddressElementId) {\n return formElementsService.findFormElement(\n formSubmissionModel.elements,\n (el) => el.id === element.reverseGeocoding?.formattedAddressElementId,\n )\n }\n }, [\n element.reverseGeocoding?.formattedAddressElementId,\n formSubmissionModel.elements,\n ])\n\n const mergeReverseGeocodeData = React.useCallback(\n (reverseGeocodeResult: SubmissionTypes.S3SubmissionData['submission']) => {\n onLookup(({ submission, elements, executedLookups }) => {\n return {\n elements,\n submission: {\n ...submission,\n ...reverseGeocodeResult,\n },\n executedLookups,\n }\n })\n },\n [onLookup],\n )\n\n React.useEffect(() => {\n const abortController = new AbortController()\n const effect = async () => {\n setReverseGeocodingState({ isReverseGeocoding: true })\n try {\n if (coords && formattedAddressElement) {\n if (element.reverseGeocoding && formattedAddressElement) {\n const mergeReverseGeocodeResult: SubmissionTypes.S3SubmissionData['submission'] =\n {}\n const reverseGeocodeResult =\n await formService.getGeoscapeReverseGeocoding({\n lat: coords.latitude,\n lng: coords.longitude,\n formId: formDefinition.id,\n abortSignal: abortController.signal,\n })\n switch (formattedAddressElement.type) {\n case 'text': {\n if (reverseGeocodeResult.addressDetails?.formattedAddress) {\n mergeReverseGeocodeResult[formattedAddressElement.name] =\n reverseGeocodeResult.addressDetails?.formattedAddress\n }\n break\n }\n case 'geoscapeAddress': {\n mergeReverseGeocodeResult[formattedAddressElement.name] =\n reverseGeocodeResult\n break\n }\n }\n if (!abortController.signal.aborted) {\n mergeReverseGeocodeData(mergeReverseGeocodeResult)\n }\n }\n }\n setReverseGeocodingState({\n isReverseGeocoding: false,\n })\n } catch (e) {\n let errorMsg = 'Could not find your address.'\n if (e instanceof OneBlinkAppsError && e.httpStatusCode !== 404) {\n errorMsg = e.message\n }\n\n if (isOffline) {\n errorMsg =\n 'It looks like you&apos;re offline. Please try again when connectivity is restored.'\n }\n setReverseGeocodingState({\n isReverseGeocoding: false,\n reverseGeocodingErrorMsg: errorMsg,\n })\n }\n }\n\n if (!formIsReadOnly) {\n effect()\n }\n\n return () => abortController.abort()\n }, [\n coords,\n element.reverseGeocoding,\n formDefinition.id,\n formDefinition.organisationId,\n formattedAddressElement,\n mergeReverseGeocodeData,\n isOffline,\n formIsReadOnly,\n ])\n\n return (\n <ReverseGeocodeContext.Provider value={reverseGeocodingState}>\n {children}\n </ReverseGeocodeContext.Provider>\n )\n}\n\nexport function useReverseGeocodeContext() {\n const reverseGeocodeContext = React.useContext(ReverseGeocodeContext)\n if (!reverseGeocodeContext) {\n throw new TypeError(\n 'You have attempted to run the hook \"useReverseGeocodeContext()\" outside of the \"ReverseGeocodeContext\" context.',\n )\n }\n return reverseGeocodeContext\n}\n"]}
@@ -15,6 +15,7 @@ export default function useConditionalLogic(definition, submission) {
15
15
  errorCallback,
16
16
  });
17
17
  }, [definition.elements, submission, errorCallback]);
18
+ console.log('formElementsConditionallyShown: ', formElementsConditionallyShown);
18
19
  return {
19
20
  conditionalLogicError,
20
21
  formElementsConditionallyShown,
@@ -1 +1 @@
1
- {"version":3,"file":"useConditionalLogic.js","sourceRoot":"","sources":["../../src/hooks/useConditionalLogic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAI5D,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,UAA0B,EAC1B,UAA0D;IAE1D,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,GAAG,KAAK,CAAC,QAAQ,EAErE,CAAA;IAEH,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAAY,EAAE,EAAE;QACvD,OAAO,CAAC,IAAI,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAA;QAC7D,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAC9B,wBAAwB,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,8BAA8B,GAClC,KAAK,CAAC,OAAO,CAAiC,GAAG,EAAE;QACjD,OAAO,uBAAuB,CAAC,sCAAsC,CAAC;YACpE,YAAY,EAAE,UAAU,CAAC,QAAQ;YACjC,UAAU;YACV,aAAa;SACd,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAA;IAEtD,OAAO;QACL,qBAAqB;QACrB,8BAA8B;KAC/B,CAAA;AACH,CAAC","sourcesContent":["import { Sentry } from '@oneblink/apps'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport { conditionalLogicService } from '@oneblink/sdk-core'\n\nimport { FormElementsConditionallyShown } from '../types/form'\n\nexport default function useConditionalLogic(\n definition: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n) {\n const [conditionalLogicError, setConditionalLogicError] = React.useState<\n Error | undefined\n >()\n\n const errorCallback = React.useCallback((error: Error) => {\n console.warn('Error while checking conditional logic', error)\n Sentry.captureException(error)\n setConditionalLogicError(error)\n }, [])\n\n const formElementsConditionallyShown =\n React.useMemo<FormElementsConditionallyShown>(() => {\n return conditionalLogicService.generateFormElementsConditionallyShown({\n formElements: definition.elements,\n submission,\n errorCallback,\n })\n }, [definition.elements, submission, errorCallback])\n\n return {\n conditionalLogicError,\n formElementsConditionallyShown,\n }\n}\n"]}
1
+ {"version":3,"file":"useConditionalLogic.js","sourceRoot":"","sources":["../../src/hooks/useConditionalLogic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAA;AAI5D,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,UAA0B,EAC1B,UAA0D;IAE1D,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,GAAG,KAAK,CAAC,QAAQ,EAErE,CAAA;IAEH,MAAM,aAAa,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAAY,EAAE,EAAE;QACvD,OAAO,CAAC,IAAI,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAA;QAC7D,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAC9B,wBAAwB,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,8BAA8B,GAClC,KAAK,CAAC,OAAO,CAAiC,GAAG,EAAE;QACjD,OAAO,uBAAuB,CAAC,sCAAsC,CAAC;YACpE,YAAY,EAAE,UAAU,CAAC,QAAQ;YACjC,UAAU;YACV,aAAa;SACd,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAA;IAEpD,OAAO,CAAC,GAAG,CAAC,kCAAkC,EAAE,8BAA8B,CAAC,CAAA;IACjF,OAAO;QACL,qBAAqB;QACrB,8BAA8B;KAC/B,CAAA;AACH,CAAC","sourcesContent":["import { Sentry } from '@oneblink/apps'\nimport { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport * as React from 'react'\nimport { conditionalLogicService } from '@oneblink/sdk-core'\n\nimport { FormElementsConditionallyShown } from '../types/form'\n\nexport default function useConditionalLogic(\n definition: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n) {\n const [conditionalLogicError, setConditionalLogicError] = React.useState<\n Error | undefined\n >()\n\n const errorCallback = React.useCallback((error: Error) => {\n console.warn('Error while checking conditional logic', error)\n Sentry.captureException(error)\n setConditionalLogicError(error)\n }, [])\n\n const formElementsConditionallyShown =\n React.useMemo<FormElementsConditionallyShown>(() => {\n return conditionalLogicService.generateFormElementsConditionallyShown({\n formElements: definition.elements,\n submission,\n errorCallback,\n })\n }, [definition.elements, submission, errorCallback])\n\n console.log('formElementsConditionallyShown: ', formElementsConditionallyShown)\n return {\n conditionalLogicError,\n formElementsConditionallyShown,\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oneblink/apps-react",
3
3
  "description": "Helper functions for OneBlink apps in ReactJS.",
4
- "version": "5.13.0-beta.2",
4
+ "version": "5.13.0-beta.4",
5
5
  "author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/oneblink/apps-react/issues"
@@ -10,7 +10,7 @@
10
10
  "@arcgis/core": "~4.29.10",
11
11
  "@emotion/react": "^11.11.3",
12
12
  "@emotion/styled": "^11.11.0",
13
- "@oneblink/sdk-core": "^6.1.0-beta.1",
13
+ "@oneblink/sdk-core": "^6.1.0-beta.2",
14
14
  "@react-google-maps/api": "2.19.2",
15
15
  "blueimp-load-image": "^5.16.0",
16
16
  "bulma": "^0.9.4",
@@ -46,7 +46,7 @@
46
46
  "@mui/lab": "^5.0.0-alpha.152",
47
47
  "@mui/material": "^5.15.6",
48
48
  "@mui/x-date-pickers": "^6.19.2",
49
- "@oneblink/apps": "^11.1.0-beta.3",
49
+ "@oneblink/apps": "^11.1.0-beta.11",
50
50
  "@oneblink/release-cli": "^3.1.0",
51
51
  "@oneblink/types": "github:oneblink/types",
52
52
  "@types/blueimp-load-image": "^5.16.6",