From 0993db11014e1ab89eb0d2dcb59313ee5c06c27a Mon Sep 17 00:00:00 2001 From: secondl1ght <85003930+secondl1ght@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:25:27 -0600 Subject: [PATCH] feat: close contact modal and reset form on success (#8) --- src/views/contacts/AddContact.tsx | 9 +++++++-- src/views/contacts/Contacts.tsx | 11 ++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/views/contacts/AddContact.tsx b/src/views/contacts/AddContact.tsx index e016cb77..f55c8e76 100644 --- a/src/views/contacts/AddContact.tsx +++ b/src/views/contacts/AddContact.tsx @@ -2,7 +2,7 @@ import { zodResolver } from '@hookform/resolvers/zod'; import { Loader2 } from 'lucide-react'; -import { FC } from 'react'; +import { Dispatch, FC, SetStateAction } from 'react'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; @@ -35,7 +35,10 @@ const formSchema = z.object({ // .email('This is not a valid email.'), }); -export const AddContact: FC<{ walletId: string }> = ({ walletId }) => { +export const AddContact: FC<{ + walletId: string; + setOpenDialog: Dispatch>; +}> = ({ walletId, setOpenDialog }) => { const { toast } = useToast(); const form = useForm>({ @@ -47,11 +50,13 @@ export const AddContact: FC<{ walletId: string }> = ({ walletId }) => { const [create, { loading }] = useCreateContactMutation({ onCompleted: () => { + setOpenDialog(false); toast({ variant: 'default', title: 'Contact Added', description: 'New contact has been added successfully', }); + form.reset(); }, onError: err => { const messages = handleApolloError(err); diff --git a/src/views/contacts/Contacts.tsx b/src/views/contacts/Contacts.tsx index ee33f221..000ef698 100644 --- a/src/views/contacts/Contacts.tsx +++ b/src/views/contacts/Contacts.tsx @@ -64,7 +64,8 @@ const ContactCard: FC<{ contact: ContactType; cbk?: () => void }> = ({ }; export const Contacts = () => { - const [open, setOpen] = useState(false); + const [openDrawer, setOpenDrawer] = useState(false); + const [openDialog, setOpenDialog] = useState(false); const currentContact = useContactStore(s => s.currentContact); const setContact = useContactStore(s => s.setCurrentContact); @@ -95,7 +96,7 @@ export const Contacts = () => {

Contacts

- + - +