diff --git a/phone/src/apps/contacts/components/views/ContactInfo.tsx b/phone/src/apps/contacts/components/views/ContactInfo.tsx index c5dac5f..bdd2e3f 100644 --- a/phone/src/apps/contacts/components/views/ContactInfo.tsx +++ b/phone/src/apps/contacts/components/views/ContactInfo.tsx @@ -21,7 +21,8 @@ interface ContactInfoRouteParams { } interface ContactInfoRouteQuery { - addNumber: string; + addNumber?: string; + referal?: string; } const useStyles = makeStyles((theme: Theme) => ({ @@ -59,7 +60,7 @@ const ContactsInfoPage = () => { const { getContact } = useContacts(); const { id } = useParams(); - const { addNumber } = useQueryParams(); + const { addNumber, referal } = useQueryParams({ referal: '/contacts' }); const contact = getContact(parseInt(id)); @@ -87,7 +88,7 @@ const ContactsInfoPage = () => { number, avatar, }); - history.replace('/contacts'); + history.replace(referal); }; const handleContactSave = () => { diff --git a/phone/src/apps/dialer/components/DialerInput.tsx b/phone/src/apps/dialer/components/DialerInput.tsx index 45a95a7..2ab6f73 100644 --- a/phone/src/apps/dialer/components/DialerInput.tsx +++ b/phone/src/apps/dialer/components/DialerInput.tsx @@ -39,7 +39,7 @@ export const DialerInput = () => { }; const handleNewContact = (number: string) => { - history.push(`/contacts/-1/?addNumber=${number}`) + history.push(`/contacts/-1/?addNumber=${number}&referal=/phone/contacts`) } return ( diff --git a/phone/src/common/hooks/useQueryParams.ts b/phone/src/common/hooks/useQueryParams.ts index 7512025..105984e 100644 --- a/phone/src/common/hooks/useQueryParams.ts +++ b/phone/src/common/hooks/useQueryParams.ts @@ -10,7 +10,12 @@ import { useLocation } from 'react-router-dom'; * * const { id, title } = useQueryParams<{ id: string, title: string }>(); */ -export function useQueryParams>() { - return qs.parse(useLocation().search, { ignoreQueryPrefix: true }) as T & - Partial; +export function useQueryParams>( + defaultValues: T = null +) { + const query = qs.parse(useLocation().search, { ignoreQueryPrefix: true }); + if (!defaultValues) { + return query as T & Partial; + } + return { ...defaultValues, ...query } as T & Partial; }