Skip to content

Commit

Permalink
feat(LocationSuggest): Reset location on hirer change (#1016)
Browse files Browse the repository at this point in the history
* feat: Reset location suggest when hirerId changes

* Format

* Changeset

* Tweak changeset

* Only clear when hirerId changes

* Fix dependency array

---------

Co-authored-by: Ryan Ling <[email protected]>
  • Loading branch information
tbolg and 72636c authored Oct 9, 2023
1 parent 7c99f63 commit 2539142
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-wolves-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wingman-fe': minor
---

LocationSuggest: Reset on hirer change
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default {
args: {
id: 'locationSuggest',
label: 'Location',
hirerId: 'seekAnzPublicTest:organization:seek:93WyyF1h',
message: 'undefined',
reserveMessageSpace: false,
showBreadcrumbs: false,
Expand Down
13 changes: 13 additions & 0 deletions fe/lib/components/LocationSuggest/LocationSuggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const LocationSuggest = forwardRef<
data: suggestData,
previousData: previousSuggestData,
error: suggestError,
variables: previousSuggestVariables,
} = useQuery<SuggestLocationsQuery, SuggestLocationsQueryVariables>(
LOCATION_SUGGEST,
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2539142

Please sign in to comment.