diff --git a/.changeset/wise-wolves-hammer.md b/.changeset/wise-wolves-hammer.md new file mode 100644 index 000000000..cf8d39730 --- /dev/null +++ b/.changeset/wise-wolves-hammer.md @@ -0,0 +1,5 @@ +--- +'wingman-fe': minor +--- + +LocationSuggest: Reset on hirer change diff --git a/fe/lib/components/LocationSuggest/LocationSuggest.stories.tsx b/fe/lib/components/LocationSuggest/LocationSuggest.stories.tsx index 6c919b2c7..f95efcbb7 100644 --- a/fe/lib/components/LocationSuggest/LocationSuggest.stories.tsx +++ b/fe/lib/components/LocationSuggest/LocationSuggest.stories.tsx @@ -8,6 +8,7 @@ export default { args: { id: 'locationSuggest', label: 'Location', + hirerId: 'seekAnzPublicTest:organization:seek:93WyyF1h', message: 'undefined', reserveMessageSpace: false, showBreadcrumbs: false, diff --git a/fe/lib/components/LocationSuggest/LocationSuggest.tsx b/fe/lib/components/LocationSuggest/LocationSuggest.tsx index 76e113c81..f3771ff5f 100644 --- a/fe/lib/components/LocationSuggest/LocationSuggest.tsx +++ b/fe/lib/components/LocationSuggest/LocationSuggest.tsx @@ -80,6 +80,7 @@ export const LocationSuggest = forwardRef< data: suggestData, previousData: previousSuggestData, error: suggestError, + variables: previousSuggestVariables, } = useQuery( LOCATION_SUGGEST, { @@ -107,6 +108,18 @@ export const LocationSuggest = forwardRef< }, ); + useEffect(() => { + /** + * Location suggestions vary depending on the hirer. + * Hence, we should clear the selected location when the hirer changes. + */ + if (selectedLocation && hirerId !== previousSuggestVariables?.hirerId) { + setSelectedLocation(undefined); + setPlaceholder(''); + onClear?.(); + } + }, [hirerId, onClear, previousSuggestVariables, selectedLocation]); + const { data: initialLocation } = useQuery< LocationQuery, LocationQueryVariables