From 5f3d75406ef36924616e3289342647f4939d5004 Mon Sep 17 00:00:00 2001 From: Joris Date: Fri, 1 Jan 2016 13:00:51 +0100 Subject: Fix add and delete payment --- src/client/elm/Update/LoggedIn.elm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/client/elm/Update') 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 -> -- cgit v1.2.3