From 7c67af41c34510d8643e6da8763ed5054c6a0bcc Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Sun, 18 May 2025 17:13:58 +0530 Subject: [PATCH] Uncommented reset logic on component unmount for cleanup --- src/components/Directory/UpdateContact.jsx | 40 +++++++++++++--------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/components/Directory/UpdateContact.jsx b/src/components/Directory/UpdateContact.jsx index 8e702949..cb2310c4 100644 --- a/src/components/Directory/UpdateContact.jsx +++ b/src/components/Directory/UpdateContact.jsx @@ -31,7 +31,8 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => { const { contactCategory, loading: contactCategoryLoading } = useContactCategory(); const { contactTags, loading: Tagloading } = useContactTags(); - const [IsSubmitting, setSubmitting] = useState(false); + const [ IsSubmitting, setSubmitting ] = useState( false ); + const [isInitialized, setIsInitialized] = useState(false); const dispatch = useDispatch(); const methods = useForm({ @@ -74,15 +75,6 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => { remove: removePhone, } = useFieldArray({ control, name: "contactPhones" }); - useEffect(() => { - if (emailFields.length === 0) { - appendEmail({ label: "Work", emailAddress: "" }); - } - if (phoneFields.length === 0) { - appendPhone({ label: "Office", phoneNumber: "" }); - } - }, [emailFields.length, phoneFields.length]); - const handleAddEmail = async () => { const emails = getValues("contactEmails"); const lastIndex = emails.length - 1; @@ -133,7 +125,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => { setSubmitting(true); await submitContact({ ...cleaned, id: existingContact.id }); setSubmitting(false); - // reset() + }; const handleClosed = () => { @@ -145,7 +137,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => { typeof existingContact === "object" && !Array.isArray(existingContact); - if (isValidContact && TagsData) { + if (!isInitialized &&isValidContact && TagsData) { reset({ name: existingContact.name || "", organization: existingContact.organization || "", @@ -157,15 +149,28 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => { projectIds: existingContact.projectIds || null, tags: existingContact.tags || [], bucketIds: existingContact.bucketIds || [], - }); + } ); + + if (!existingContact.contactPhones || existingContact.contactPhones.length === 0) { + appendPhone({ label: "Office", phoneNumber: "" }); } - }, [existingContact, buckets, projects]); + + if (!existingContact.contactEmails || existingContact.contactEmails.length === 0) { + appendEmail({ label: "Work", emailAddress: "" }); + } + setIsInitialized(true) + } + + return()=> reset() + }, [ existingContact, buckets, projects ] ); + + return (
{" "} -
Create New Contact
+
Update Contact
@@ -430,13 +435,14 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
-