Project

General

Profile

Edit Copy Actions

Bug #9803

closed

Fixing Uncaught TypeError: Cannot set properties of undefined (setting 'email') at handleEmailChange (CreateClientPage.tsx:543:31) at onChange (CreateClientPage.tsx:1902:21) in edit customer

Added by Yalavarthi Thriveni 21 days ago. Updated 21 days ago.

Status:
Closed
Priority:
Normal
Target version:
-
Start date:
07/14/2026
Due date:
07/14/2026
% Done:

100%

Estimated time:
Spent time:
Tested Date:
07/14/2026
Raised by Tester:
Page/ Module (POS):
Customers

Add

Subtasks


Add

Related issues

Updated by Yalavarthi Thriveni 21 days ago

  • Due date set to 07/14/2026
  • Status changed from New to Closed
  • % Done changed from 0 to 100

Root cause : When editing an existing customer who has no email address or phone number stored in the database, the arrays emails and contactDetails are set to empty arrays []. However, the input fields in the JSX are hardcoded to bind to index 0 (e.g. emails0). Typing in the fields called handleEmailChange or handleContactChange at index 0. Because updatedEmails0 was undefined, setting properties on it caused the page to crash with: TypeError: Cannot set properties of undefined (setting 'email')

Solution :1. The Safety Check is Conditional
The check we introduced (if (!updatedEmails[index])) is a conditional guard. It only runs if the element at the specified index is missing (i.e. undefined):

typescript

const updatedEmails = [...emails];
if (!updatedEmails[index]) {
updatedEmails[index] = { email: '' }; // Only runs if undefined
}
updatedEmails[index][field] = value;
For existing customers who already have emails:

emails is already populated during page load (e.g. [{ email: '' }, { email: '' }]).
When typing in the first input (index 0), updatedEmails0 is { email: '' } (truthy).
The if block is bypassed entirely, and it directly updates the value just like the original code did.
This means the data-flow and state update logic for all existing records remains 100% identical to the original working code.
2. State Mutation Pattern is Unchanged
We kept the exact same shallow array copying ([...emails]) and mutation patterns that the application has been using since its creation. There are no side-effects or reference sharing issues introduced by our change.

Every existing record will load, display, edit, validate, and save exactly as before.

Edit Copy Actions

Also available in: Atom PDF