Skip to content

Commit

Permalink
ON-40696 # Fixed autosave google address data not saving with class p…
Browse files Browse the repository at this point in the history
…roperties
  • Loading branch information
mymattcarroll committed May 27, 2024
1 parent 135b819 commit 5d6b25f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 31 additions & 8 deletions src/form-elements/FormElementGoogleAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
),
)
}
Expand Down Expand Up @@ -140,7 +153,7 @@ function FormElementGoogleAddress({
}

const placeService = new google.maps.places.PlacesService(dummyMap)
const place = await new Promise<GoogleTypes.GoogleMapsAddress>(
const place = await new Promise<google.maps.places.PlaceResult>(
(resolve, reject) => {
placeService.getDetails(
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5d6b25f

Please sign in to comment.