@oneblink/apps-react 6.1.0-beta.4 → 6.1.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.
@@ -30,20 +30,25 @@ function FormElementGoogleAddress({ id, element, value, displayValidationMessage
30
30
  input,
31
31
  }, (predictions, status) => {
32
32
  switch (status) {
33
+ case google.maps.places.PlacesServiceStatus.OK:
33
34
  case google.maps.places.PlacesServiceStatus.ZERO_RESULTS: {
34
- resolve([]);
35
+ resolve(predictions !== null && predictions !== void 0 ? predictions : []);
35
36
  break;
36
37
  }
37
- case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: {
38
- reject(new OneBlinkAppsError('Google Maps API key has not been configured correctly'));
38
+ case google.maps.places.PlacesServiceStatus.OVER_QUERY_LIMIT: {
39
+ reject(new OneBlinkAppsError('This application has gone over its Google Address querying quota. Please contact an administrator to rectify the issue or try again later.'));
39
40
  break;
40
41
  }
41
- case google.maps.places.PlacesServiceStatus.OK: {
42
- resolve(predictions !== null && predictions !== void 0 ? predictions : []);
42
+ case google.maps.places.PlacesServiceStatus.INVALID_REQUEST: {
43
+ reject(new OneBlinkAppsError('Google Maps API key may not have been configured correctly, the request to retrieve address suggestions is invalid. Please contact an administrator to rectify the issue.'));
44
+ break;
45
+ }
46
+ case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: {
47
+ reject(new OneBlinkAppsError('Google Maps API key has not been configured correctly. Please contact an administrator to rectify the issue.'));
43
48
  break;
44
49
  }
45
50
  default: {
46
- reject(new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.'));
51
+ reject(new OneBlinkAppsError('An unknown error has occurred. Please try again and contact support if the problem persists.'));
47
52
  }
48
53
  }
49
54
  });
@@ -68,6 +73,7 @@ function FormElementGoogleAddress({ id, element, value, displayValidationMessage
68
73
  throw new OneBlinkAppsError('An unknown error has occurred. Please contact support if the problem persists.');
69
74
  }, [autocompleteService]);
70
75
  const handleChange = React.useCallback(async (placeId) => {
76
+ var _a, _b, _c, _d;
71
77
  if (!placeId) {
72
78
  onChange(element, { value: undefined });
73
79
  return;
@@ -99,7 +105,17 @@ function FormElementGoogleAddress({ id, element, value, displayValidationMessage
99
105
  resolve(place);
100
106
  });
101
107
  });
102
- onChange(element, { value: place });
108
+ onChange(element, {
109
+ value: {
110
+ place_id: place.place_id,
111
+ formatted_address: place.formatted_address,
112
+ address_components: place.address_components,
113
+ geometry: {
114
+ location: (_b = (_a = place.geometry) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.toJSON(),
115
+ viewport: (_d = (_c = place.geometry) === null || _c === void 0 ? void 0 : _c.viewport) === null || _d === void 0 ? void 0 : _d.toJSON(),
116
+ },
117
+ },
118
+ });
103
119
  }
104
120
  catch (newError) {
105
121
  if (isMounted.current) {
@@ -1 +1 @@
1
- {"version":3,"file":"FormElementGoogleAddress.js","sourceRoot":"","sources":["../../src/form-elements/FormElementGoogleAddress.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAC9E,OAAO,yBAAyB,MAAM,kDAAkD,CAAA;AACxF,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAC1C,OAAO,YAAY,MAAM,uBAAuB,CAAA;AAChD,OAAO,yBAAyB,MAAM,oCAAoC,CAAA;AAa1E,SAAS,wBAAwB,CAAC,EAChC,EAAE,EACF,OAAO,EACP,KAAK,EACL,wBAAwB,EACxB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,UAAU,GACJ;IACN,MAAM,eAAe,GAAG,yBAAyB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IAC9D,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,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AK,IAAI,CACR,6BAAK,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,kBAAkB;YAC5C,6BAAK,SAAS,EAAC,6EAA6E,IACzF,KAAK,CAAC,OAAO,CACV,CACF,CACP,CACG,CACP,CAAA;AACH,CAAC;AAED,eAAe,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { FormTypes, GoogleTypes } from '@oneblink/types'\nimport { OneBlinkAppsError, Sentry } from '@oneblink/apps'\n\nimport AutocompleteDropdown from '../components/renderer/AutocompleteDropdown'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport useGoogle from '../hooks/useGoogle'\nimport useIsMounted from '../hooks/useIsMounted'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\n\ntype Props = {\n formId: number\n id: string\n element: FormTypes.GoogleAddressElement\n value: GoogleTypes.GoogleMapsAddress | undefined\n displayValidationMessage: boolean\n validationMessage: string | undefined\n onChange: FormElementValueChangeHandler<GoogleTypes.GoogleMapsAddress>\n} & IsDirtyProps\n\nfunction FormElementGoogleAddress({\n id,\n element,\n value,\n displayValidationMessage,\n validationMessage,\n onChange,\n isDirty,\n setIsDirty,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const isMounted = useIsMounted()\n const [label, setLabel] = React.useState('')\n const [error, setError] = React.useState<Error | undefined>()\n const [isLoadingAddressDetails, setIsLoadingAddressDetails] =\n React.useState(false)\n\n const { isLoaded } = useGoogle()\n\n const autocompleteService = React.useMemo(() => {\n if (isLoaded) {\n return new google.maps.places.AutocompleteService()\n }\n }, [isLoaded])\n\n const dummyMap = React.useMemo(() => {\n if (isLoaded) {\n return new google.maps.Map(document.createElement('div'))\n }\n }, [isLoaded])\n\n const handleSearch = React.useCallback(\n async (input: string, abortSignal: AbortSignal) => {\n setError(undefined)\n if (autocompleteService) {\n const predictions = await new Promise<\n google.maps.places.QueryAutocompletePrediction[]\n >((resolve, reject) => {\n autocompleteService.getQueryPredictions(\n {\n input,\n },\n (predictions, status) => {\n switch (status) {\n case google.maps.places.PlacesServiceStatus.ZERO_RESULTS: {\n resolve([])\n break\n }\n case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: {\n reject(\n new OneBlinkAppsError(\n 'Google Maps API key has not been configured correctly',\n ),\n )\n break\n }\n case google.maps.places.PlacesServiceStatus.OK: {\n resolve(predictions ?? [])\n break\n }\n default: {\n reject(\n new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n ),\n )\n }\n }\n },\n )\n }).catch((e) => {\n if (!abortSignal.aborted) {\n Sentry.captureException(e)\n }\n throw e\n })\n\n if (!abortSignal.aborted) {\n return predictions.reduce<Array<{ value: string; label: string }>>(\n (results, prediction) => {\n if (prediction.place_id) {\n results.push({\n value: prediction.place_id,\n label: prediction.description,\n })\n }\n return results\n },\n [],\n )\n }\n }\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n )\n },\n [autocompleteService],\n )\n\n const handleChange = React.useCallback(\n async (placeId: string | undefined) => {\n if (!placeId) {\n onChange(element, { value: undefined })\n return\n }\n\n setIsLoadingAddressDetails(true)\n try {\n //this should not happen, we can't get a place Id without google being present\n if (!isLoaded || !dummyMap) {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: new Error(\n 'Google Places library has not be initialised',\n ),\n },\n )\n }\n\n const placeService = new google.maps.places.PlacesService(dummyMap)\n const place = await new Promise<GoogleTypes.GoogleMapsAddress>(\n (resolve, reject) => {\n placeService.getDetails(\n {\n placeId,\n fields: [\n 'place_id',\n 'formatted_address',\n 'geometry',\n 'address_components',\n ],\n },\n (place, status) => {\n if (\n status !== google.maps.places.PlacesServiceStatus.OK ||\n !place\n ) {\n reject(\n new OneBlinkAppsError(\n `Could not find address details for place with id: ${placeId}`,\n ),\n )\n return\n }\n resolve(place)\n },\n )\n },\n )\n onChange(element, { value: place })\n } catch (newError) {\n if (isMounted.current) {\n setError(newError as Error)\n }\n }\n if (isMounted.current) {\n setIsLoadingAddressDetails(false)\n }\n },\n [isMounted, onChange, element, isLoaded, dummyMap],\n )\n\n // Ensure the label is set if the value is set outside of this component\n React.useEffect(() => {\n if (value) {\n const newLabel = value.formatted_address || value.place_id\n setLabel(newLabel ?? '')\n }\n }, [value])\n\n return (\n <div className=\"cypress-google-address-element\">\n <FormElementLabelContainer\n className=\"ob-google-address ob-autocomplete\"\n element={element}\n id={id}\n required={element.required}\n >\n <AutocompleteDropdown\n id={id}\n label={label}\n disabled={element.readOnly || isLoadingAddressDetails}\n placeholder={element.placeholderValue}\n required={element.required}\n value={value}\n validationMessage={validationMessage}\n displayValidationMessage={displayValidationMessage}\n onChangeValue={handleChange}\n isLoading={isLoadingAddressDetails}\n hasError={!!error}\n onChangeLabel={setLabel}\n searchDebounceMs={750}\n searchMinCharacters={4}\n onSearch={handleSearch}\n isDirty={isDirty}\n setIsDirty={setIsDirty}\n aria-describedby={ariaDescribedby}\n branding={\n <a className=\"dropdown-item cypress-powered-by-google ob-autocomplete__drop-down-item-powered-by-google\">\n powered by{' '}\n <img src=\"https://developers.google.com/static/maps/documentation/images/google_on_white.png\" />\n </a>\n }\n />\n </FormElementLabelContainer>\n\n {error && (\n <div role=\"alert\" className=\"has-margin-top-8\">\n <div className=\"has-text-danger ob-error__text cypress-google-address-details-error-message\">\n {error.message}\n </div>\n </div>\n )}\n </div>\n )\n}\n\nexport default React.memo(FormElementGoogleAddress)\n"]}
1
+ {"version":3,"file":"FormElementGoogleAddress.js","sourceRoot":"","sources":["../../src/form-elements/FormElementGoogleAddress.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,oBAAoB,MAAM,6CAA6C,CAAA;AAC9E,O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,KAAK,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAA","sourcesContent":["import * as React from 'react'\nimport { FormTypes, GoogleTypes } from '@oneblink/types'\nimport { OneBlinkAppsError, Sentry } from '@oneblink/apps'\n\nimport AutocompleteDropdown from '../components/renderer/AutocompleteDropdown'\nimport FormElementLabelContainer from '../components/renderer/FormElementLabelContainer'\nimport useGoogle from '../hooks/useGoogle'\nimport useIsMounted from '../hooks/useIsMounted'\nimport useElementAriaDescribedby from '../hooks/useElementAriaDescribedby'\nimport { FormElementValueChangeHandler, IsDirtyProps } from '../types/form'\n\ntype Props = {\n formId: number\n id: string\n element: FormTypes.GoogleAddressElement\n value: GoogleTypes.GoogleMapsAddress | undefined\n displayValidationMessage: boolean\n validationMessage: string | undefined\n onChange: FormElementValueChangeHandler<GoogleTypes.GoogleMapsAddress>\n} & IsDirtyProps\n\nfunction FormElementGoogleAddress({\n id,\n element,\n value,\n displayValidationMessage,\n validationMessage,\n onChange,\n isDirty,\n setIsDirty,\n}: Props) {\n const ariaDescribedby = useElementAriaDescribedby(id, element)\n const isMounted = useIsMounted()\n const [label, setLabel] = React.useState('')\n const [error, setError] = React.useState<Error | undefined>()\n const [isLoadingAddressDetails, setIsLoadingAddressDetails] =\n React.useState(false)\n\n const { isLoaded } = useGoogle()\n\n const autocompleteService = React.useMemo(() => {\n if (isLoaded) {\n return new google.maps.places.AutocompleteService()\n }\n }, [isLoaded])\n\n const dummyMap = React.useMemo(() => {\n if (isLoaded) {\n return new google.maps.Map(document.createElement('div'))\n }\n }, [isLoaded])\n\n const handleSearch = React.useCallback(\n async (input: string, abortSignal: AbortSignal) => {\n setError(undefined)\n if (autocompleteService) {\n const predictions = await new Promise<\n google.maps.places.QueryAutocompletePrediction[]\n >((resolve, reject) => {\n autocompleteService.getQueryPredictions(\n {\n input,\n },\n (predictions, status) => {\n switch (status) {\n case google.maps.places.PlacesServiceStatus.OK:\n case google.maps.places.PlacesServiceStatus.ZERO_RESULTS: {\n resolve(predictions ?? [])\n break\n }\n case google.maps.places.PlacesServiceStatus.OVER_QUERY_LIMIT: {\n reject(\n new OneBlinkAppsError(\n 'This application has gone over its Google Address querying quota. Please contact an administrator to rectify the issue or try again later.',\n ),\n )\n break\n }\n case google.maps.places.PlacesServiceStatus.INVALID_REQUEST: {\n reject(\n new OneBlinkAppsError(\n 'Google Maps API key may not have been configured correctly, the request to retrieve address suggestions is invalid. Please contact an administrator to rectify the issue.',\n ),\n )\n break\n }\n case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: {\n reject(\n new OneBlinkAppsError(\n 'Google Maps API key has not been configured correctly. Please contact an administrator to rectify the issue.',\n ),\n )\n break\n }\n default: {\n reject(\n new OneBlinkAppsError(\n 'An unknown error has occurred. Please try again and contact support if the problem persists.',\n ),\n )\n }\n }\n },\n )\n }).catch((e) => {\n if (!abortSignal.aborted) {\n Sentry.captureException(e)\n }\n throw e\n })\n\n if (!abortSignal.aborted) {\n return predictions.reduce<Array<{ value: string; label: string }>>(\n (results, prediction) => {\n if (prediction.place_id) {\n results.push({\n value: prediction.place_id,\n label: prediction.description,\n })\n }\n return results\n },\n [],\n )\n }\n }\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n )\n },\n [autocompleteService],\n )\n\n const handleChange = React.useCallback(\n async (placeId: string | undefined) => {\n if (!placeId) {\n onChange(element, { value: undefined })\n return\n }\n\n setIsLoadingAddressDetails(true)\n try {\n //this should not happen, we can't get a place Id without google being present\n if (!isLoaded || !dummyMap) {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: new Error(\n 'Google Places library has not be initialised',\n ),\n },\n )\n }\n\n const placeService = new google.maps.places.PlacesService(dummyMap)\n const place = await new Promise<google.maps.places.PlaceResult>(\n (resolve, reject) => {\n placeService.getDetails(\n {\n placeId,\n fields: [\n 'place_id',\n 'formatted_address',\n 'geometry',\n 'address_components',\n ],\n },\n (place, status) => {\n if (\n status !== google.maps.places.PlacesServiceStatus.OK ||\n !place\n ) {\n reject(\n new OneBlinkAppsError(\n `Could not find address details for place with id: ${placeId}`,\n ),\n )\n return\n }\n resolve(place)\n },\n )\n },\n )\n onChange(element, {\n value: {\n place_id: place.place_id,\n formatted_address: place.formatted_address,\n address_components: place.address_components,\n geometry: {\n location: place.geometry?.location?.toJSON(),\n viewport: place.geometry?.viewport?.toJSON(),\n },\n },\n })\n } catch (newError) {\n if (isMounted.current) {\n setError(newError as Error)\n }\n }\n if (isMounted.current) {\n setIsLoadingAddressDetails(false)\n }\n },\n [isMounted, onChange, element, isLoaded, dummyMap],\n )\n\n // Ensure the label is set if the value is set outside of this component\n React.useEffect(() => {\n if (value) {\n const newLabel = value.formatted_address || value.place_id\n setLabel(newLabel ?? '')\n }\n }, [value])\n\n return (\n <div className=\"cypress-google-address-element\">\n <FormElementLabelContainer\n className=\"ob-google-address ob-autocomplete\"\n element={element}\n id={id}\n required={element.required}\n >\n <AutocompleteDropdown\n id={id}\n label={label}\n disabled={element.readOnly || isLoadingAddressDetails}\n placeholder={element.placeholderValue}\n required={element.required}\n value={value}\n validationMessage={validationMessage}\n displayValidationMessage={displayValidationMessage}\n onChangeValue={handleChange}\n isLoading={isLoadingAddressDetails}\n hasError={!!error}\n onChangeLabel={setLabel}\n searchDebounceMs={750}\n searchMinCharacters={4}\n onSearch={handleSearch}\n isDirty={isDirty}\n setIsDirty={setIsDirty}\n aria-describedby={ariaDescribedby}\n branding={\n <a className=\"dropdown-item cypress-powered-by-google ob-autocomplete__drop-down-item-powered-by-google\">\n powered by{' '}\n <img src=\"https://developers.google.com/static/maps/documentation/images/google_on_white.png\" />\n </a>\n }\n />\n </FormElementLabelContainer>\n\n {error && (\n <div role=\"alert\" className=\"has-margin-top-8\">\n <div className=\"has-text-danger ob-error__text cypress-google-address-details-error-message\">\n {error.message}\n </div>\n </div>\n )}\n </div>\n )\n}\n\nexport default React.memo(FormElementGoogleAddress)\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": "6.1.0-beta.4",
4
+ "version": "6.1.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"