aboutsummaryrefslogtreecommitdiff
path: root/src/client/Model/View/LoggedIn
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Model/View/LoggedIn')
-rw-r--r--src/client/Model/View/LoggedIn/Add.elm43
-rw-r--r--src/client/Model/View/LoggedIn/Edition.elm7
-rw-r--r--src/client/Model/View/LoggedIn/Monthly.elm17
3 files changed, 67 insertions, 0 deletions
diff --git a/src/client/Model/View/LoggedIn/Add.elm b/src/client/Model/View/LoggedIn/Add.elm
new file mode 100644
index 0000000..abd8a4d
--- /dev/null
+++ b/src/client/Model/View/LoggedIn/Add.elm
@@ -0,0 +1,43 @@
+module Model.View.LoggedIn.Add
+ ( AddPayment
+ , Frequency(..)
+ , initAddPayment
+ , validateName
+ , validateCost
+ ) where
+
+import Result as Result exposing (Result(..))
+
+import Utils.Validation exposing (..)
+
+import Model.Translations exposing (..)
+
+type alias AddPayment =
+ { name : String
+ , nameError : Maybe String
+ , cost : String
+ , costError : Maybe String
+ , frequency : Frequency
+ }
+
+initAddPayment : Frequency -> AddPayment
+initAddPayment frequency =
+ { name = ""
+ , nameError = Nothing
+ , cost = ""
+ , costError = Nothing
+ , frequency = frequency
+ }
+
+validateName : String -> Translations -> Result String String
+validateName name translations =
+ name
+ |> validateNonEmpty (getMessage "CategoryRequired" translations)
+
+validateCost : String -> Translations -> Result String Int
+validateCost cost translations =
+ cost
+ |> validateNonEmpty (getMessage "CostRequired" translations)
+ |> flip Result.andThen (validateNumber (getMessage "CostMustBeNumber" translations) (\number -> number >= 0))
+
+type Frequency = Punctual | Monthly
diff --git a/src/client/Model/View/LoggedIn/Edition.elm b/src/client/Model/View/LoggedIn/Edition.elm
new file mode 100644
index 0000000..da6d7b0
--- /dev/null
+++ b/src/client/Model/View/LoggedIn/Edition.elm
@@ -0,0 +1,7 @@
+module Model.View.LoggedIn.Edition
+ ( Edition
+ ) where
+
+import Model.Payment exposing (PaymentId)
+
+type alias Edition = PaymentId
diff --git a/src/client/Model/View/LoggedIn/Monthly.elm b/src/client/Model/View/LoggedIn/Monthly.elm
new file mode 100644
index 0000000..3c6f66a
--- /dev/null
+++ b/src/client/Model/View/LoggedIn/Monthly.elm
@@ -0,0 +1,17 @@
+module Model.View.LoggedIn.Monthly
+ ( Monthly
+ , initMonthly
+ ) where
+
+import Model.Payment exposing (Payments)
+
+type alias Monthly =
+ { payments : Payments
+ , visibleDetail : Bool
+ }
+
+initMonthly : Payments -> Monthly
+initMonthly payments =
+ { payments = payments
+ , visibleDetail = False
+ }