Skip to content

Commit

Permalink
Merge pull request #1208 from CruGlobal/8472-wrong-account-list
Browse files Browse the repository at this point in the history
[MPDX-8472] Generate URLs with current accountListId
  • Loading branch information
canac authored Nov 22, 2024
2 parents 45df179 + 8c2c7bf commit d3c5364
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const ContactsWrapper: React.FC<Props> = ({
}) => {
const router = useRouter();
const { query, replace, pathname } = router;
const { accountListId } = query;

// Extract the initial contact id from the URL
const [contactId, setContactId] = useState<string | undefined>(() =>
Expand Down Expand Up @@ -92,7 +93,7 @@ export const ContactsWrapper: React.FC<Props> = ({
}, [viewMode, activeFiltersRaw]);

const getContactHrefObject: GetContactHrefObject = useCallback(
(contactId) => {
(contactId?: string) => {
// Omit the filters and searchTerm from the previous query because we don't want them in the URL
// if they are empty and Next.js will still add them to the URL query even if they are undefined.
// i.e. { filters: undefined, searchTerm: '' } results in a querystring of ?filters=&searchTerm
Expand Down Expand Up @@ -120,12 +121,12 @@ export const ContactsWrapper: React.FC<Props> = ({
query: newQuery,
};
},
[viewMode, activeFilters, searchTerm, pathname],
[accountListId, viewMode, activeFilters, searchTerm, pathname],
);

const urlQuery = useMemo(() => {
return getContactHrefObject(contactId).query;
}, [contactId, viewMode, activeFilters, searchTerm]);
}, [contactId, getContactHrefObject]);

useEffect(() => {
replace({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const useTasksContactContext = (): ContactsContextProps => {

const urlQuery = useMemo(() => {
return getContactHrefObject(contactId).query;
}, [accountListId, contactId, activeFilters, searchTerm]);
}, [contactId, getContactHrefObject]);

useEffect(() => {
replace({
Expand Down

0 comments on commit d3c5364

Please sign in to comment.