From 8c2c7bf960cf5332a887dcb4ddb75cc533931a92 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Thu, 21 Nov 2024 08:01:07 -0600 Subject: [PATCH] Generate URLs with current accountListId --- .../[accountListId]/contacts/ContactsWrapper.tsx | 7 ++++--- .../[accountListId]/tasks/useTasksContactContext.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pages/accountLists/[accountListId]/contacts/ContactsWrapper.tsx b/pages/accountLists/[accountListId]/contacts/ContactsWrapper.tsx index 7dc20b293..d1412545e 100644 --- a/pages/accountLists/[accountListId]/contacts/ContactsWrapper.tsx +++ b/pages/accountLists/[accountListId]/contacts/ContactsWrapper.tsx @@ -45,6 +45,7 @@ export const ContactsWrapper: React.FC = ({ }) => { const router = useRouter(); const { query, replace, pathname } = router; + const { accountListId } = query; // Extract the initial contact id from the URL const [contactId, setContactId] = useState(() => @@ -92,7 +93,7 @@ export const ContactsWrapper: React.FC = ({ }, [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 @@ -120,12 +121,12 @@ export const ContactsWrapper: React.FC = ({ 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({ diff --git a/pages/accountLists/[accountListId]/tasks/useTasksContactContext.ts b/pages/accountLists/[accountListId]/tasks/useTasksContactContext.ts index 7349fa4b0..0c45e97d7 100644 --- a/pages/accountLists/[accountListId]/tasks/useTasksContactContext.ts +++ b/pages/accountLists/[accountListId]/tasks/useTasksContactContext.ts @@ -74,7 +74,7 @@ export const useTasksContactContext = (): ContactsContextProps => { const urlQuery = useMemo(() => { return getContactHrefObject(contactId).query; - }, [accountListId, contactId, activeFilters, searchTerm]); + }, [contactId, getContactHrefObject]); useEffect(() => { replace({