diff options
author | Joris | 2016-01-01 13:00:51 +0100 |
---|---|---|
committer | Joris | 2016-01-01 13:00:51 +0100 |
commit | 5f3d75406ef36924616e3289342647f4939d5004 (patch) | |
tree | e19bfce420ef53ee93548f2e0ee1e248b7630e89 /src/client/elm/Update | |
parent | b73ba24f3440b81698c9d5c370739d03f958f059 (diff) |
Fix add and delete payment
Diffstat (limited to 'src/client/elm/Update')
-rw-r--r-- | src/client/elm/Update/LoggedIn.elm | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/client/elm/Update/LoggedIn.elm b/src/client/elm/Update/LoggedIn.elm index 2dc65c3..38901b2 100644 --- a/src/client/elm/Update/LoggedIn.elm +++ b/src/client/elm/Update/LoggedIn.elm @@ -19,7 +19,7 @@ import Update.LoggedIn.Account as UA type LoggedAction = UpdateAdd AddPaymentAction | UpdatePayments Payments - | AddPayment UserId String Int + | AddPayment PaymentId String Int | AddMonthlyPayment PaymentId String Int | ToggleEdit PaymentId | DeletePayment Payment @@ -34,13 +34,15 @@ updateLoggedIn model action loggedInView = { loggedInView | add = updateAddPayment addPaymentAction loggedInView.add } UpdatePayments payments -> { loggedInView | payments = payments } - AddPayment userId name cost -> - { loggedInView - | currentPage = 1 - , add = initAddPayment Punctual - , account = UA.updateAccount (UA.UpdatePayer userId model.currentTime cost) loggedInView.account - , paymentsCount = loggedInView.paymentsCount + 1 - } + AddPayment paymentId name cost -> + let newPayment = Payment paymentId (Date.fromTime model.currentTime) name cost loggedInView.account.me + in { loggedInView + | currentPage = 1 + , add = initAddPayment Punctual + , account = UA.updateAccount (UA.UpdatePayer loggedInView.account.me model.currentTime cost) loggedInView.account + , payments = newPayment :: loggedInView.payments + , paymentsCount = loggedInView.paymentsCount + 1 + } AddMonthlyPayment id name cost -> { loggedInView | add = initAddPayment Monthly @@ -53,6 +55,7 @@ updateLoggedIn model action loggedInView = DeletePayment payment -> { loggedInView | account = UA.updateAccount (UA.UpdatePayer payment.userId (Date.toTime payment.creation) -payment.cost) loggedInView.account + , payments = deletePayment payment.id loggedInView.payments , paymentsCount = loggedInView.paymentsCount - 1 } UpdatePage page -> |