@oneblink/apps-react 5.13.0-beta.3 → 5.13.0-beta.5
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
|
-
|
23
|
-
|
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.
|
49
|
-
const
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
64
|
-
|
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(
|
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.
|
102
|
+
element.reverseGeocoding,
|
105
103
|
formDefinition.id,
|
106
104
|
formDefinition.organisationId,
|
107
105
|
formattedAddressElement,
|
@@ -1 +1 @@
|
|
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
|
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,MA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AAC,CAAA;yBACnD;qBACF;iBACF;gBACD,wBAAwB,CAAC;oBACvB,kBAAkB,EAAE,KAAK;iBAC1B,CAAC,CAAA;aACH;YAAC,OAAO,CAAC,EAAE;gBACV,IAAI,QAAQ,GAAG,8BAA8B,CAAA;gBAC7C,IAAI,CAAC,YAAY,iBAAiB,IAAI,CAAC,CAAC,cAAc,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'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"]}
|
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.
|
4
|
+
"version": "5.13.0-beta.5",
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
6
6
|
"bugs": {
|
7
7
|
"url": "https://github.com/oneblink/apps-react/issues"
|
@@ -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.
|
49
|
+
"@oneblink/apps": "^11.1.0-beta.13",
|
50
50
|
"@oneblink/release-cli": "^3.1.0",
|
51
51
|
"@oneblink/types": "github:oneblink/types",
|
52
52
|
"@types/blueimp-load-image": "^5.16.6",
|