aboutsummaryrefslogtreecommitdiff
path: root/src/client/Model/View
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Model/View')
-rw-r--r--src/client/Model/View/LoggedIn/Account.elm27
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))