From 6ca60e32f0cbde913d171cd84ed7009ab4281284 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 13 Sep 2015 14:38:08 +0200 Subject: Adding UI to modify the income --- src/client/Update/LoggedIn/Account.elm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/client/Update/LoggedIn') 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 + } -- cgit v1.2.3