Skip to content

Fix waysToContact not displaying when API returns a string value#412

Merged
need4deed merged 2 commits intoneed4deed-org:developfrom
Cy-fox:fix/opportunity-contact-waystocontact-399
Apr 28, 2026
Merged

Fix waysToContact not displaying when API returns a string value#412
need4deed merged 2 commits intoneed4deed-org:developfrom
Cy-fox:fix/opportunity-contact-waystocontact-399

Conversation

@Cy-fox
Copy link
Copy Markdown
Collaborator

@Cy-fox Cy-fox commented Apr 27, 2026

Closes #399
The API returns waysToContact as a plain string (e.g. "mobilePhone") instead of an array. The existing guard only checked Array.isArray, so a string value was silently dropped and the field always displayed "–" even when data existed.
Changes:

  • OpportunityContactDetails.tsx: handle waysToContact as either a PreferredCommunicationType[] or a single string, wrapping the string case in a one-element array
  • Made the other contact fields (name, phone, email) explicitly default to "" instead of relying on the spread to avoid undefined values slipping through

Copy link
Copy Markdown
Collaborator

@nadavosa nadavosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #412 Review: Fix waysToContact not displaying when API returns a string

The core fix is correct — wrapping a bare string in an array so it renders. A few issues worth addressing:

1. No enum validation before the cast (correctness)
The typeof raw === "string" && raw guard only checks non-empty, not that the value is a valid PreferredCommunicationType. An unexpected value (wrong casing, deprecated key) gets cast and silently reaches the form or API. Consider:

const isValid = (v: string): v is PreferredCommunicationType =>
  Object.values(PreferredCommunicationType).includes(v as PreferredCommunicationType);
const waysToContact = Array.isArray(raw)
  ? raw.filter(isValid)
  : isValid(raw) ? [raw] : [];

This would protect the array branch too.

2. Explicit field listing may drift from schema
The old spread (...opportunity.contact) included all contact fields automatically. The new explicit list (name, phone, email, waysToContact) will silently miss any new fields added to OpportunityContactDetailsFormData. A comment noting the list must stay in sync with the schema would help.

3. createOpportunityContactDetailsSchema(t) called outside useMemo (pre-existing)
This creates a new schema object on every render, causing the useForm resolver to change each render. Not introduced by this PR but it's in the touched area — worth fixing in a follow-up.

Copy link
Copy Markdown
Collaborator

@nadavosa nadavosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both issues addressed correctly:

  • Enum validation now uses new Set<string>(COMMUNICATION_TYPES) — covers both the string and array branches cleanly
  • Sync comment added to the explicit field list

Approving.

@need4deed need4deed merged commit d2d2e39 into need4deed-org:develop Apr 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Opportunity profile: contact details section missing phone number

3 participants