aboutsummaryrefslogtreecommitdiff
path: root/src/client/Update/LoggedIn
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Update/LoggedIn')
-rw-r--r--src/client/Update/LoggedIn/Account.elm31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/client/Update/LoggedIn/Account.elm b/src/client/Update/LoggedIn/Account.elm
index ab07c2e..2d9cd87 100644
--- a/src/client/Update/LoggedIn/Account.elm
+++ b/src/client/Update/LoggedIn/Account.elm
@@ -3,13 +3,21 @@ module Update.LoggedIn.Account
, updateAccount
) where
+import Maybe
+
import Model.User exposing (UserId)
import Model.Payers exposing (..)
import Model.View.LoggedIn.Account exposing (..)
+import Utils.Maybe exposing (isJust)
+
type AccountAction =
ToggleDetail
| UpdatePayer UserId Int
+ | ToggleIncomeEdition
+ | UpdateIncomeEdition String
+ | UpdateEditionError String
+ | UpdateIncome Int
updateAccount : AccountAction -> Account -> Account
updateAccount action account =
@@ -18,3 +26,26 @@ updateAccount action account =
{ account | visibleDetail <- not account.visibleDetail }
UpdatePayer userId cost ->
{ account | payers <- updatePayers account.payers userId cost }
+ ToggleIncomeEdition ->
+ { account | incomeEdition <-
+ if isJust account.incomeEdition
+ then Nothing
+ else Just (initIncomeEdition (Maybe.withDefault 0 account.income))
+ }
+ UpdateIncomeEdition income ->
+ case account.incomeEdition of
+ Just incomeEdition ->
+ { account | incomeEdition <- Just { incomeEdition | income <- income } }
+ Nothing ->
+ account
+ UpdateEditionError error ->
+ case account.incomeEdition of
+ Just incomeEdition ->
+ { account | incomeEdition <- Just { incomeEdition | error <- Just error } }
+ Nothing ->
+ account
+ UpdateIncome amount ->
+ { account
+ | income <- Just amount
+ , incomeEdition <- Nothing
+ }