blob: 4665180ea62b97edfd0a7537962848292eb59570 (
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
|
module Model.View.Payment.Add
( AddPayment
, initAddPayment
, validateName
, validateCost
) where
import Result as Result exposing (Result(..))
import Utils.Validation exposing (..)
type alias AddPayment =
{ name : String
, nameError : Maybe String
, cost : String
, costError : Maybe String
}
initAddPayment : AddPayment
initAddPayment =
{ name = ""
, nameError = Nothing
, cost = ""
, costError = Nothing
}
validateName : String -> Result String String
validateName name =
name
|> validateNonEmpty "The category is required."
validateCost : String -> Result String Int
validateCost cost =
cost
|> validateNonEmpty "The cost is required."
|> flip Result.andThen (validateNumber "The cost must be a number.")
|