aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Model/View/Payment/Add.elm5
-rw-r--r--src/client/Update/Payment/Add.elm7
-rw-r--r--src/client/View/Payments/Add.elm15
3 files changed, 26 insertions, 1 deletions
diff --git a/src/client/Model/View/Payment/Add.elm b/src/client/Model/View/Payment/Add.elm
index 5ab7a40..da5d0f2 100644
--- a/src/client/Model/View/Payment/Add.elm
+++ b/src/client/Model/View/Payment/Add.elm
@@ -1,5 +1,6 @@
module Model.View.Payment.Add
( AddPayment
+ , Frequency(..)
, initAddPayment
, validateName
, validateCost
@@ -16,6 +17,7 @@ type alias AddPayment =
, nameError : Maybe String
, cost : String
, costError : Maybe String
+ , frequency : Frequency
}
initAddPayment : AddPayment
@@ -24,6 +26,7 @@ initAddPayment =
, nameError = Nothing
, cost = ""
, costError = Nothing
+ , frequency = Punctual
}
validateName : String -> Translations -> Result String String
@@ -36,3 +39,5 @@ 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/Update/Payment/Add.elm b/src/client/Update/Payment/Add.elm
index 3ccce73..27f2af0 100644
--- a/src/client/Update/Payment/Add.elm
+++ b/src/client/Update/Payment/Add.elm
@@ -3,12 +3,13 @@ module Update.Payment.Add
, updateAddPayment
) where
-import Model.View.Payment.Add exposing (AddPayment)
+import Model.View.Payment.Add exposing (..)
type AddPaymentAction =
UpdateName String
| UpdateCost String
| AddError (Maybe String) (Maybe String)
+ | ToggleFrequency
updateAddPayment : AddPaymentAction -> AddPayment -> AddPayment
updateAddPayment action addPayment =
@@ -22,3 +23,7 @@ updateAddPayment action addPayment =
| nameError <- nameError
, costError <- costError
}
+ ToggleFrequency ->
+ { addPayment
+ | frequency <- if addPayment.frequency == Punctual then Monthly else Punctual
+ }
diff --git a/src/client/View/Payments/Add.elm b/src/client/View/Payments/Add.elm
index 77d40ea..085b16d 100644
--- a/src/client/View/Payments/Add.elm
+++ b/src/client/View/Payments/Add.elm
@@ -37,6 +37,7 @@ addPayment model loggedView =
]
[ addPaymentName loggedView.add
, addPaymentCost model loggedView.add
+ , paymentFrequency model loggedView.add
, button
[ type' "submit" ]
[ text (getMessage "Add" model.translations)]
@@ -83,3 +84,17 @@ addPaymentCost model addPayment =
Nothing ->
text ""
]
+
+paymentFrequency : Model -> AddPayment -> Html
+paymentFrequency model addPayment =
+ div
+ [ class "frequency"
+ , onClick actions.address (UpdatePayment << UpdateAdd <| ToggleFrequency)
+ ]
+ [ div
+ [ class ("punctual" ++ if addPayment.frequency == Punctual then " selected" else "") ]
+ [ text (getMessage "Punctual" model.translations) ]
+ , div
+ [ class ("monthly" ++ if addPayment.frequency == Monthly then " selected" else "") ]
+ [ text (getMessage "Monthly" model.translations) ]
+ ]