diff options
author | Joris Guyonvarch | 2015-08-01 00:31:36 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-08-01 00:31:36 +0200 |
commit | c345f9daa28e0c174b35413addf78df0a793f8c1 (patch) | |
tree | 206f1d9aeed76b5c9e6f6abd24c00a50ec6c54fd /src/client/Model/View | |
parent | 043d315c4b15608e04a07cd709e4caf5c3758c61 (diff) |
Adding error feedbacks when adding a payment
Diffstat (limited to 'src/client/Model/View')
-rw-r--r-- | src/client/Model/View/Payment/Add.elm | 36 | ||||
-rw-r--r-- | src/client/Model/View/PaymentView.elm | 7 |
2 files changed, 39 insertions, 4 deletions
diff --git a/src/client/Model/View/Payment/Add.elm b/src/client/Model/View/Payment/Add.elm new file mode 100644 index 0000000..ff64388 --- /dev/null +++ b/src/client/Model/View/Payment/Add.elm @@ -0,0 +1,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 name 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.") diff --git a/src/client/Model/View/PaymentView.elm b/src/client/Model/View/PaymentView.elm index 8de005d..07bd2ec 100644 --- a/src/client/Model/View/PaymentView.elm +++ b/src/client/Model/View/PaymentView.elm @@ -4,18 +4,17 @@ module Model.View.PaymentView ) where import Model.Payment exposing (Payments) +import Model.View.Payment.Add exposing (..) type alias PaymentView = { userName : String - , name : String - , cost : String + , add : AddPayment , payments : Payments } initPaymentView : String -> Payments -> PaymentView initPaymentView userName payments = { userName = userName - , name = "" - , cost = "" + , add = initAddPayment , payments = payments } |