diff options
Diffstat (limited to 'src/client/elm/Update')
-rw-r--r-- | src/client/elm/Update/LoggedIn.elm | 12 | ||||
-rw-r--r-- | src/client/elm/Update/LoggedIn/Account.elm | 1 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/client/elm/Update/LoggedIn.elm b/src/client/elm/Update/LoggedIn.elm index 134aec2..dfc2a1b 100644 --- a/src/client/elm/Update/LoggedIn.elm +++ b/src/client/elm/Update/LoggedIn.elm @@ -6,6 +6,7 @@ import Date import Dict import Debug import Task +import String import Effects exposing (Effects) import Http exposing (Error(..)) @@ -21,6 +22,7 @@ import Model.Action.MonthlyAction as Monthly import Model.Action.AddPaymentAction as AddPayment import Model.View.LoggedInView exposing (..) import Model.View.LoggedIn.AddPayment exposing (..) +import Model.Translations exposing (Translations, getMessage) import Update.LoggedIn.AddPayment exposing (updateAddPayment, addPaymentError) import Update.LoggedIn.Monthly exposing (updateMonthly) @@ -44,7 +46,14 @@ updateLoggedIn model action loggedInView = AddPayment name cost frequency -> ( { loggedInView | add = updateAddPayment AddPayment.WaitingServer loggedInView.add } - , Server.addPayment model.translations name cost frequency + , Server.addPayment name cost frequency + |> Task.map (\paymentId -> + case String.toInt cost of + Err _ -> + UpdateAdd (AddPayment.AddError Nothing (Just (getMessage "CostRequired" model.translations))) + Ok costNumber -> + ValidateAddPayment paymentId name costNumber frequency + ) |> flip Task.onError (\err -> case err of BadResponse 400 jsonErr -> @@ -89,6 +98,7 @@ updateLoggedIn model action loggedInView = DeletePayment payment frequency -> ( loggedInView , Server.deletePayment payment frequency + |> Task.map (always (ValidateDeletePayment payment frequency)) |> flip Task.onError (always <| Task.succeed NoOp) |> Effects.task ) diff --git a/src/client/elm/Update/LoggedIn/Account.elm b/src/client/elm/Update/LoggedIn/Account.elm index 16d67ac..1773b9a 100644 --- a/src/client/elm/Update/LoggedIn/Account.elm +++ b/src/client/elm/Update/LoggedIn/Account.elm @@ -67,6 +67,7 @@ updateAccount action account = UpdateIncome currentTime amount -> ( account , Server.setIncome currentTime amount + |> Task.map (always (ValidateUpdateIncome currentTime amount)) |> flip Task.onError (always <| Task.succeed NoOp) |> Effects.task ) |