luceroweb / karot-saving-smart

Millions of us are living paycheck to paycheck. It can be difficult to build a budget that helps you pay for your bills as well as plan for the future - without making you feel like you have to do without. You may have heard about the tried and true cash “Envelope Savings” system, which can help you to make sure you always have enough to pay your b
https://karot-saving-smart.netlify.app/
3 stars 13 forks source link

Can't edit same expense twice #123

Open luceroweb opened 2 years ago

luceroweb commented 2 years ago

Date Seen 6/6/22 11:50am

Versions Linux Chrome, Android Emulator (Pixel 4) https://github.com/luceroweb/karot-saving-smart/tree/develop

Bug Description When you edit an expense, and save your change, the edit is saved correctly. When you edit the same expense again, without leaving the expense detail view, the the expense data is not passed to the expense edit form, and submitting that form clears all of the expense data for that expense.

Steps to Reproduce

  1. Open the app
  2. Enter an expense
  3. Edit the expense and save
  4. Edit the same expense - you will see that the expense data was not passed into the expense edit modal.

Actual Behavior When you edit an expense, and save your change, the edit is saved correctly. When you edit the same expense again, without leaving the expense detail view, the the expense data is not passed to the expense edit form, and submitting that form clears all of the expense data for that expense.

Expected Behavior When editing an expense the second time, the expense data should be passed into the expense edit form, and when the form is saved, the expense data and the extra money values should all be updated to reflect the change.

Troubleshooting/Testing Steps Attempted We set the default value of the Expense slice to an object like the following:

  list: [
    {
      label: "Rent",
      saved: 1000,
      goal: 1000,
      date: Number(Date.now()),
      id: "1",
    },
    {
      label: "Date Night",
      saved: 150,
      goal: 150,
      date: Number(Date.now()),
      id: "2",
    },
    {
      label: "Electricty",
      saved: 100,
      goal: 100,
      date: Number(Date.now()),
      id: "3",
    },
  ],

Attempted to edit an expense by adding value and by subtracting value.

Workaround Delete the expense and re-enter it.

srosenberg74 commented 2 years ago

I was able to give somewhat of a solution by changing the value in the TextInput for Label in the ExpenseModal to value={appData?.modalMode === "add" ? undefined : label} and by removing the lines that reset the values of label and amount after editing an expense. There was still an issue, however, if a user were to click the add expense button while already in the expenseDetails screen. The recommended solution is to refactor so that the label and amount are taken from state by id rather than having them be based on states that are passed in from the Overview Screen. I was unable to figure this out so I am going to unassign myself and return the ticket back to accepted so another developer can work on it.