diff options
author | Joris | 2015-09-13 14:38:08 +0200 |
---|---|---|
committer | Joris | 2015-09-13 14:38:08 +0200 |
commit | 6ca60e32f0cbde913d171cd84ed7009ab4281284 (patch) | |
tree | 9d365a0e94cbcbfbc0b4e88d8e6cec7ada75fd28 /src/client/Model | |
parent | 5babf01323bcb62a9880593165af70732f22751b (diff) |
Adding UI to modify the income
Diffstat (limited to 'src/client/Model')
-rw-r--r-- | src/client/Model/View/LoggedIn/Account.elm | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/client/Model/View/LoggedIn/Account.elm b/src/client/Model/View/LoggedIn/Account.elm index 410345c..7f0fbe3 100644 --- a/src/client/Model/View/LoggedIn/Account.elm +++ b/src/client/Model/View/LoggedIn/Account.elm @@ -1,14 +1,28 @@ module Model.View.LoggedIn.Account ( Account + , IncomeEdition , initAccount + , initIncomeEdition + , validateIncome ) where +import Result as Result exposing (Result(..)) + +import Utils.Validation exposing (..) + +import Model.Translations exposing (..) import Model.Payers exposing (..) type alias Account = { payers : Payers , income : Maybe Int , visibleDetail : Bool + , incomeEdition : Maybe IncomeEdition + } + +type alias IncomeEdition = + { income : String + , error : Maybe String } initAccount : Payers -> Maybe Int -> Account @@ -16,4 +30,17 @@ initAccount payers income = { payers = payers , income = income , visibleDetail = False + , incomeEdition = Nothing } + +initIncomeEdition : Int -> IncomeEdition +initIncomeEdition income = + { income = toString income + , error = Nothing + } + +validateIncome : String -> Translations -> Result String Int +validateIncome amount translations = + amount + |> validateNonEmpty (getMessage "IncomeRequired" translations) + |> flip Result.andThen (validateNumber (getMessage "IncomeMustBeNonNullNumber" translations) ((/=) 0)) |