From 76ce07d4d3a1758d3cb0c67f00df665b16770777 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Mon, 19 May 2025 11:24:27 +0530 Subject: [PATCH] it send properly existen phone and email id if existen data --- src/components/Directory/UpdateContact.jsx | 37 ++++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/components/Directory/UpdateContact.jsx b/src/components/Directory/UpdateContact.jsx index cb2310c4..dc748035 100644 --- a/src/components/Directory/UpdateContact.jsx +++ b/src/components/Directory/UpdateContact.jsx @@ -111,19 +111,29 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => { }; const onSubmit = async (data) => { - debugger; - const cleaned = { - ...data, - contactEmails: (data.contactEmails || []).filter( - (e) => e.emailAddress?.trim() !== "" - ), - contactPhones: (data.contactPhones || []).filter( - (p) => p.phoneNumber?.trim() !== "" - ), - }; +const cleaned = { + ...data, + contactEmails: (data.contactEmails || []) + .filter((e) => e.emailAddress?.trim() !== "") + .map((email, index) => { + const existingEmail = existingContact.contactEmails?.[index]; + return existingEmail + ? { ...email, id: existingEmail.id } + : email; + }), + contactPhones: (data.contactPhones || []) + .filter((p) => p.phoneNumber?.trim() !== "") + .map((phone, index) => { + const existingPhone = existingContact.contactPhones?.[index]; + return existingPhone + ? { ...phone, id: existingPhone.id } + : phone; + }), +}; + +setSubmitting(true); +await submitContact({ ...cleaned, id: existingContact.id }); - setSubmitting(true); - await submitContact({ ...cleaned, id: existingContact.id }); setSubmitting(false); }; @@ -161,7 +171,7 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => { setIsInitialized(true) } - return()=> reset() + // return()=> reset() }, [ existingContact, buckets, projects ] ); @@ -169,7 +179,6 @@ const UpdateContact = ({ submitContact, existingContact, onCLosed }) => {
- {" "}
Update Contact