From d380238f1c3f77460164c5723897af823af72995 Mon Sep 17 00:00:00 2001 From: Cy-fox Date: Mon, 27 Apr 2026 15:11:37 +0100 Subject: [PATCH 1/2] Fix waysToContact not displaying when API returns a string value Closes #399 --- .../opportunity/OpportunityContactDetails.tsx | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/Dashboard/Profile/sections/ContactDetails/opportunity/OpportunityContactDetails.tsx b/src/components/Dashboard/Profile/sections/ContactDetails/opportunity/OpportunityContactDetails.tsx index b80f8b6e..5edcacaa 100644 --- a/src/components/Dashboard/Profile/sections/ContactDetails/opportunity/OpportunityContactDetails.tsx +++ b/src/components/Dashboard/Profile/sections/ContactDetails/opportunity/OpportunityContactDetails.tsx @@ -39,13 +39,20 @@ export const OpportunityContactDetails = forwardRef(f const schema = createOpportunityContactDetailsSchema(t); - const initialFormValues = useMemo( - () => ({ - ...opportunity.contact, - waysToContact: Array.isArray(opportunity.contact.waysToContact) ? opportunity.contact.waysToContact : [], - }), - [opportunity.contact], - ); + const initialFormValues = useMemo(() => { + const raw = opportunity.contact.waysToContact; + const waysToContact: PreferredCommunicationType[] = Array.isArray(raw) + ? raw + : typeof raw === "string" && raw + ? [raw as PreferredCommunicationType] + : []; + return { + name: opportunity.contact.name ?? "", + phone: opportunity.contact.phone ?? "", + email: opportunity.contact.email ?? "", + waysToContact, + }; + }, [opportunity.contact]); const methods = useForm({ resolver: zodResolver(schema), From 9c2c7e323ba715fab6df29a0a0b8ada8185fa1e0 Mon Sep 17 00:00:00 2001 From: Cy-fox Date: Tue, 28 Apr 2026 09:11:40 +0100 Subject: [PATCH 2/2] Address review feedback: validate waysToContact enum values and add sync comment --- .../opportunity/OpportunityContactDetails.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/Dashboard/Profile/sections/ContactDetails/opportunity/OpportunityContactDetails.tsx b/src/components/Dashboard/Profile/sections/ContactDetails/opportunity/OpportunityContactDetails.tsx index 5edcacaa..4bedabca 100644 --- a/src/components/Dashboard/Profile/sections/ContactDetails/opportunity/OpportunityContactDetails.tsx +++ b/src/components/Dashboard/Profile/sections/ContactDetails/opportunity/OpportunityContactDetails.tsx @@ -41,11 +41,16 @@ export const OpportunityContactDetails = forwardRef(f const initialFormValues = useMemo(() => { const raw = opportunity.contact.waysToContact; + const validTypes = new Set(COMMUNICATION_TYPES); + const waysToContact: PreferredCommunicationType[] = Array.isArray(raw) - ? raw - : typeof raw === "string" && raw + ? raw.filter((v): v is PreferredCommunicationType => validTypes.has(v)) + : typeof raw === "string" && validTypes.has(raw) ? [raw as PreferredCommunicationType] : []; + + // Fields are listed explicitly to stay in sync with OpportunityContactDetailsFormData. + // If the schema adds or removes fields, update this object accordingly. return { name: opportunity.contact.name ?? "", phone: opportunity.contact.phone ?? "",