aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/AddPayment/Update.elm
diff options
context:
space:
mode:
authorJoris2016-03-28 17:51:14 +0200
committerJoris2016-03-28 17:51:14 +0200
commit166cd04e4b28770ede854dafc9ae30eae64102fe (patch)
tree2245a31243a165acc6f7355534da44cfd17e6038 /src/client/elm/LoggedIn/Home/AddPayment/Update.elm
parentb0d80a5458d7ba4546e5f01f5b6398ea6d23f981 (diff)
downloadbudget-166cd04e4b28770ede854dafc9ae30eae64102fe.tar.gz
budget-166cd04e4b28770ede854dafc9ae30eae64102fe.tar.bz2
budget-166cd04e4b28770ede854dafc9ae30eae64102fe.zip
Create an empty but reachable user page
Diffstat (limited to 'src/client/elm/LoggedIn/Home/AddPayment/Update.elm')
-rw-r--r--src/client/elm/LoggedIn/Home/AddPayment/Update.elm55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/client/elm/LoggedIn/Home/AddPayment/Update.elm b/src/client/elm/LoggedIn/Home/AddPayment/Update.elm
new file mode 100644
index 0000000..b8020f1
--- /dev/null
+++ b/src/client/elm/LoggedIn/Home/AddPayment/Update.elm
@@ -0,0 +1,55 @@
+module LoggedIn.Home.AddPayment.Update
+ ( update
+ , addPaymentError
+ ) where
+
+import Maybe
+import Json.Decode as Json exposing ((:=))
+
+import LoggedIn.Home.AddPayment.Action as AddPaymentAction
+import LoggedIn.Home.AddPayment.Model as AddPaymentModel
+
+import Model.Translations exposing (Translations, getMessage)
+import Model.Payment exposing (PaymentFrequency(..))
+
+update : AddPaymentAction.Action -> AddPaymentModel.Model -> AddPaymentModel.Model
+update action addPayment =
+ case action of
+
+ AddPaymentAction.NoOp ->
+ addPayment
+
+ AddPaymentAction.UpdateName name ->
+ { addPayment | name = name }
+
+ AddPaymentAction.UpdateCost cost ->
+ { addPayment | cost = cost }
+
+ AddPaymentAction.AddError nameError costError ->
+ { addPayment
+ | nameError = nameError
+ , costError = costError
+ , waitingServer = False
+ }
+
+ AddPaymentAction.ToggleFrequency ->
+ { addPayment
+ | frequency = if addPayment.frequency == Punctual then Monthly else Punctual
+ }
+
+ AddPaymentAction.WaitingServer ->
+ { addPayment | waitingServer = True }
+
+addPaymentError : Translations -> String -> Maybe AddPaymentAction.Action
+addPaymentError translations jsonErr =
+ let decoder =
+ Json.object2 (,)
+ (Json.maybe <| "name" := Json.string)
+ (Json.maybe <| "cost" := Json.string)
+ in case Json.decodeString decoder jsonErr of
+ Err _ ->
+ Nothing
+ Ok (mbNameKey, mbCostKey) ->
+ Just <| AddPaymentAction.AddError
+ (Maybe.map (flip getMessage translations) mbNameKey)
+ (Maybe.map (flip getMessage translations) mbCostKey)