Gary-Community-Ventures / benefits-calculator

MIT License
5 stars 3 forks source link

Step 4 - Household member amount not updating correctly #1345

Open Linda-Vu opened 3 days ago

Linda-Vu commented 3 days ago

When a user has filled out the screener with multiple family members, but goes back to change that they only have one family member in their household, the old data persists.

Expected behavior would be that the data gets updated properly and the "cards" displaying household should be updated accordingly. i.e. if the household was initially 2 members (head of household + child) but they go back and indicate that they only have one household member, the screener should get rid of the "card" for the child, keeping only the card for head of household.

Technical notes - @bespinosa01, @kbrey, @CalebPena, @msrezaie if possible could I get y'all to flesh out details or hints here about what the dev picking this ticket up should think about? Not sure if we are currently prop drilling in the frontend code or if we have a more robust library/approach for global state management in the frontend and how that answer might affect the solution here.

Screenshot 2024-10-24 120243.png Screenshot 2024-10-24 115848 (1).png
CalebPena commented 3 days ago

You can truncate the household members array when the household size is submitted.

The following will set the householdSize, and truncate the householdData array.

setFormData({
  ...formData,
  householdSize: newSize,
  householdData: formData.householdData.slice(0, newSize),
});

Household size is set in https://github.com/Gary-Community-Ventures/benefits-calculator/blob/main/src/Components/Steps/HouseholdSize.tsx