blob: 7f0fbe32e86e976082f3c7b497cc5cd6c6f9c99d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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
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))
|