From 2853954cbc5a2ff4ede3e34a65a5018e66cfae9b Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan Date: Thu, 7 May 2026 16:53:23 +0700 Subject: [PATCH] Add optional chaining for party and people props Guard against null/undefined values by adding optional chaining to property accesses. In AssignmentDetailComponent.tsx, use party?.name, party?.photo, party?.description and make initials accept a possibly undefined name (name?.split...). In AssignedPeople.tsx, check people?.length and use people?.slice and people?.length in the UI so rendering won't crash when the people prop is missing or undefined. These changes prevent runtime errors when props are absent. --- .../[assignment_id]/AssignmentDetailComponent.tsx | 12 ++++++------ .../project-detail/[project_id]/AssignedPeople.tsx | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx index 4beb224..a6c112c 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx @@ -244,7 +244,7 @@ function MetaTile({ icon: Icon, label, value }: { icon: typeof Briefcase; label: function PartyCard({ label, party, accent }: { label: string; party: any; accent: string }) { function initials(name: string) { - return name.split(" ").map((n) => n[0]).filter(Boolean).slice(0, 2).join("").toUpperCase(); + return name?.split(" ").map((n) => n[0]).filter(Boolean).slice(0, 2).join("").toUpperCase(); } return ( @@ -254,17 +254,17 @@ function PartyCard({ label, party, accent }: { label: string; party: any; accent
- {party.photo ? - + {party?.photo ? + :
- {initials(party.name)} + {initials(party?.name)}
}
-

{party.name}

-

{party.description ?? 'No description available.'}

+

{party?.name}

+

{party?.description ?? 'No description available.'}

diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx index 5047b2a..4b31389 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx @@ -15,7 +15,7 @@ interface Props { const AssignedPeople = ({ people, defaultOpen = true }: Props) => { const [isOpen, setIsOpen] = useState(defaultOpen); - if (people.length === 0) { + if (people?.length === 0) { return (
No team assigned yet @@ -29,17 +29,17 @@ const AssignedPeople = ({ people, defaultOpen = true }: Props) => {
- {people.slice(0, 5).map((user, i) => + {people?.slice(0, 5).map((user, i) => )} - {people.length > 5 && + {people?.length > 5 &&
- +{people.length - 5} + +{people?.length - 5}
}
-

{people.length} People

+

{people?.length} People

assigned to this work order