Add contacts referal after creating from dialer

This commit is contained in:
J Francisco Rader committed 2021-02-21 19:34:36 -05:00
1 parent 1650929eed
commit 3171052963
3 files changed
+13 -7

No files matched your search

@@ -21,7 +21,8 @@ interface ContactInfoRouteParams {
} }
interface ContactInfoRouteQuery { interface ContactInfoRouteQuery {
addNumber: string; addNumber?: string;
referal?: string;
} }
const useStyles = makeStyles((theme: Theme) => ({ const useStyles = makeStyles((theme: Theme) => ({
@@ -59,7 +60,7 @@ const ContactsInfoPage = () => {
const { getContact } = useContacts(); const { getContact } = useContacts();
const { id } = useParams<ContactInfoRouteParams>(); const { id } = useParams<ContactInfoRouteParams>();
const { addNumber } = useQueryParams<ContactInfoRouteQuery>(); const { addNumber, referal } = useQueryParams<ContactInfoRouteQuery>({ referal: '/contacts' });
const contact = getContact(parseInt(id)); const contact = getContact(parseInt(id));
@@ -87,7 +88,7 @@ const ContactsInfoPage = () => {
number, number,
avatar, avatar,
}); });
history.replace('/contacts'); history.replace(referal);
}; };
const handleContactSave = () => { const handleContactSave = () => {
@@ -39,7 +39,7 @@ export const DialerInput = () => {
}; };
const handleNewContact = (number: string) => { const handleNewContact = (number: string) => {
history.push(`/contacts/-1/?addNumber=${number}`) history.push(`/contacts/-1/?addNumber=${number}&referal=/phone/contacts`)
} }
return ( return (
+8 -3
View File
@@ -10,7 +10,12 @@ import { useLocation } from 'react-router-dom';
* *
* const { id, title } = useQueryParams<{ id: string, title: string }>(); * const { id, title } = useQueryParams<{ id: string, title: string }>();
*/ */
export function useQueryParams<T = Record<string, string>>() { export function useQueryParams<T = Record<string, string>>(
return qs.parse(useLocation().search, { ignoreQueryPrefix: true }) as T & defaultValues: T = null
Partial<ParsedQs>; ) {
const query = qs.parse(useLocation().search, { ignoreQueryPrefix: true });
if (!defaultValues) {
return query as T & Partial<ParsedQs>;
}
return { ...defaultValues, ...query } as T & Partial<ParsedQs>;
} }