diff --git a/package-lock.json b/package-lock.json index 03ff7025..1f589619 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8117,9 +8117,8 @@ }, "node_modules/@oneblink/types": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/oneblink/types.git#79d9b22b0c234fed9763f8fd0c7b686070064d23", + "resolved": "git+ssh://git@github.com/oneblink/types.git#f38620ad985e92324d3963af73d01e5247b6d36a", "dev": true, - "license": "GPL-3.0-only", "dependencies": { "@types/google.maps": "^3.55.9" }, diff --git a/src/form-elements/FormElementGoogleAddress.tsx b/src/form-elements/FormElementGoogleAddress.tsx index ec048608..f84f494d 100644 --- a/src/form-elements/FormElementGoogleAddress.tsx +++ b/src/form-elements/FormElementGoogleAddress.tsx @@ -63,26 +63,39 @@ function FormElementGoogleAddress({ }, (predictions, status) => { switch (status) { + case google.maps.places.PlacesServiceStatus.OK: case google.maps.places.PlacesServiceStatus.ZERO_RESULTS: { - resolve([]) + resolve(predictions ?? []) break } - case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: { + case google.maps.places.PlacesServiceStatus.OVER_QUERY_LIMIT: { reject( new OneBlinkAppsError( - 'Google Maps API key has not been configured correctly', + 'This application has gone over its Google Address querying quota. Please contact an administrator to rectify the issue or try again later.', ), ) break } - case google.maps.places.PlacesServiceStatus.OK: { - resolve(predictions ?? []) + case google.maps.places.PlacesServiceStatus.INVALID_REQUEST: { + 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.', + ), + ) + break + } + case google.maps.places.PlacesServiceStatus.REQUEST_DENIED: { + reject( + new OneBlinkAppsError( + 'Google Maps API key has not been configured correctly. Please contact an administrator to rectify the issue.', + ), + ) break } default: { reject( new OneBlinkAppsError( - 'An unknown error has occurred. Please contact support if the problem persists.', + 'An unknown error has occurred. Please try again and contact support if the problem persists.', ), ) } @@ -140,7 +153,7 @@ function FormElementGoogleAddress({ } const placeService = new google.maps.places.PlacesService(dummyMap) - const place = await new Promise( + const place = await new Promise( (resolve, reject) => { placeService.getDetails( { @@ -169,7 +182,17 @@ function FormElementGoogleAddress({ ) }, ) - onChange(element, { value: place }) + onChange(element, { + value: { + place_id: place.place_id, + formatted_address: place.formatted_address, + address_components: place.address_components, + geometry: { + location: place.geometry?.location?.toJSON(), + viewport: place.geometry?.viewport?.toJSON(), + }, + }, + }) } catch (newError) { if (isMounted.current) { setError(newError as Error)