From 9fde03f17f39cee337018508dd7c4f4f62b48cd7 Mon Sep 17 00:00:00 2001 From: ColinBuyck <53269332+ColinBuyck@users.noreply.github.com> Date: Thu, 2 Jan 2025 09:28:13 -0800 Subject: [PATCH] fix: household member delete + order (#4510) * fix: household member delete + order * fix: clean up * fix: consistent naming * fix: handle null order id --- .../sections/DetailsHouseholdMembers.tsx | 5 ++++- .../PaperApplicationForm/PaperApplicationForm.tsx | 9 ++++++++- .../sections/FormHouseholdMembers.tsx | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sites/partners/src/components/applications/PaperApplicationDetails/sections/DetailsHouseholdMembers.tsx b/sites/partners/src/components/applications/PaperApplicationDetails/sections/DetailsHouseholdMembers.tsx index 05a92b5390..2bb9530fe9 100644 --- a/sites/partners/src/components/applications/PaperApplicationDetails/sections/DetailsHouseholdMembers.tsx +++ b/sites/partners/src/components/applications/PaperApplicationDetails/sections/DetailsHouseholdMembers.tsx @@ -31,7 +31,10 @@ const DetailsHouseholdMembers = ({ setMembersDrawer }: DetailsHouseholdMembersPr return t("t.n/a") } - return application?.householdMember?.map((item) => ({ + const orderedHouseholdMembers = application?.householdMember?.sort( + (a, b) => a.orderId - b.orderId + ) + return orderedHouseholdMembers?.map((item) => ({ name: { content: `${item.firstName} ${item.middleName} ${item.lastName}` }, relationship: { content: item.relationship diff --git a/sites/partners/src/components/applications/PaperApplicationForm/PaperApplicationForm.tsx b/sites/partners/src/components/applications/PaperApplicationForm/PaperApplicationForm.tsx index 5cfe2864b0..8a8aa221d3 100644 --- a/sites/partners/src/components/applications/PaperApplicationForm/PaperApplicationForm.tsx +++ b/sites/partners/src/components/applications/PaperApplicationForm/PaperApplicationForm.tsx @@ -77,7 +77,14 @@ const ApplicationForm = ({ listingId, editMode, application }: ApplicationFormPr useEffect(() => { if (application?.householdMember) { - setHouseholdMembers(application.householdMember) + const householdMemberNum = application.householdMember.length + const orderedHouseholdMembers = application.householdMember + //reset order ids to show members in order user added them + .map((member, idx) => { + return { ...member, orderId: householdMemberNum - idx } + }) + .sort((a, b) => a.orderId - b.orderId) + setHouseholdMembers(orderedHouseholdMembers) } }, [application, setHouseholdMembers]) diff --git a/sites/partners/src/components/applications/PaperApplicationForm/sections/FormHouseholdMembers.tsx b/sites/partners/src/components/applications/PaperApplicationForm/sections/FormHouseholdMembers.tsx index 8570787636..f9987b0acf 100644 --- a/sites/partners/src/components/applications/PaperApplicationForm/sections/FormHouseholdMembers.tsx +++ b/sites/partners/src/components/applications/PaperApplicationForm/sections/FormHouseholdMembers.tsx @@ -167,7 +167,7 @@ const FormHouseholdMembers = ({ setMembersDeleteModal(null)}