I started working on the card cloning functionality yesterday and then spent this evening working on it to complete it. I thought it was going to be more difficult, although I did have some trouble with Sequelize and how to clone the expense records.
Cloning expense cards
In order to clone an expense card, we need a button. I added a button next to the archive button in the bottom left corner:
With a click of this button, it clones that chosen expense card:
Now, the most difficult part about this functionality was figuring out how to use SequelizeJS to clone the expense card and its expenses. The other code that I needed to write in my React project wasn't that difficult to figure out since it's been fairly straight forward which I love.
I had to use Sequelize's bulkCreate function to insert multiple lines at once. But to get it to work, I had to create an array with the objects in them. So I started with a for loop that creates this array of expense objects with the new (cloned) expense card's id. THEN the bulkCreate function finally worked. Initially I had created a for loop that would call Sequelize's create function. That caused an issue with the expenses not appearing because they would get inserted AFTER the call to find the new expense card and its expenses.