aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm')
-rw-r--r--src/client/elm/Model/Action/LoggedInAction.elm4
-rw-r--r--src/client/elm/Model/Communication.elm4
-rw-r--r--src/client/elm/ServerCommunication.elm11
-rw-r--r--src/client/elm/Update.elm10
-rw-r--r--src/client/elm/Update/LoggedIn.elm31
-rw-r--r--src/client/elm/View/LoggedIn/AddPayment.elm6
6 files changed, 29 insertions, 37 deletions
diff --git a/src/client/elm/Model/Action/LoggedInAction.elm b/src/client/elm/Model/Action/LoggedInAction.elm
index 22a7d3d..00e0a3e 100644
--- a/src/client/elm/Model/Action/LoggedInAction.elm
+++ b/src/client/elm/Model/Action/LoggedInAction.elm
@@ -6,12 +6,12 @@ import Model.Payment exposing (Payments, Payment, PaymentId)
import Model.Action.MonthlyAction exposing (MonthlyAction)
import Model.Action.AccountAction exposing (AccountAction)
import Model.Action.AddPaymentAction exposing (AddPaymentAction)
+import Model.View.LoggedIn.AddPayment exposing (Frequency)
type LoggedInAction =
UpdateAdd AddPaymentAction
| UpdatePayments Payments
- | AddPayment PaymentId String Int
- | AddMonthlyPayment PaymentId String Int
+ | AddPayment PaymentId String Int Frequency
| ToggleEdit PaymentId
| DeletePayment Payment
| UpdatePage Int
diff --git a/src/client/elm/Model/Communication.elm b/src/client/elm/Model/Communication.elm
index a7ec7a5..616d78f 100644
--- a/src/client/elm/Model/Communication.elm
+++ b/src/client/elm/Model/Communication.elm
@@ -6,11 +6,11 @@ import Time exposing (Time)
import Model.User exposing (UserId)
import Model.Payment exposing (..)
+import Model.View.LoggedIn.AddPayment exposing (Frequency)
type Communication =
SignIn String
- | AddPayment String Int
- | AddMonthlyPayment String Int
+ | AddPayment String Int Frequency
| SetIncome Time Int
| DeletePayment Payment Int
| DeleteMonthlyPayment PaymentId
diff --git a/src/client/elm/ServerCommunication.elm b/src/client/elm/ServerCommunication.elm
index bc8d59f..1cabda5 100644
--- a/src/client/elm/ServerCommunication.elm
+++ b/src/client/elm/ServerCommunication.elm
@@ -33,15 +33,10 @@ sendRequest communication =
post ("/signIn?assertion=" ++ assertion)
|> flip Task.andThen (always initViewAction)
- AddPayment name cost ->
- post (addPaymentURL name cost Punctual)
+ AddPayment name cost frequency ->
+ post (addPaymentURL name cost frequency)
|> flip Task.andThen (decodeHttpValue <| "id" := paymentIdDecoder)
- |> Task.map (\paymentId -> (U.UpdateLoggedIn (UL.AddPayment paymentId name cost)))
-
- AddMonthlyPayment name cost ->
- post (addPaymentURL name cost Monthly)
- |> flip Task.andThen (decodeHttpValue <| "id" := paymentIdDecoder)
- |> Task.map (\id -> U.UpdateLoggedIn (UL.AddMonthlyPayment id name cost))
+ |> Task.map (\paymentId -> (U.UpdateLoggedIn (UL.AddPayment paymentId name cost frequency)))
DeletePayment payment currentPage ->
post (deletePaymentURL payment.id)
diff --git a/src/client/elm/Update.elm b/src/client/elm/Update.elm
index 46c1b01..73dde9b 100644
--- a/src/client/elm/Update.elm
+++ b/src/client/elm/Update.elm
@@ -39,6 +39,11 @@ update action model =
|> Effects.task
)
+ GoLoggedInView users me monthlyPayments payments paymentsCount payers ->
+ ( { model | view = V.LoggedInView (initLoggedInView users me monthlyPayments payments paymentsCount payers) }
+ , Effects.none
+ )
+
ServerCommunication communication ->
( model
, sendRequest communication
@@ -52,11 +57,6 @@ update action model =
GoSignInView ->
({ model | view = V.SignInView initSignInView }, Effects.none)
- GoLoggedInView users me monthlyPayments payments paymentsCount payers ->
- ( { model | view = V.LoggedInView (initLoggedInView users me monthlyPayments payments paymentsCount payers) }
- , Effects.none
- )
-
UpdateSignIn signInAction ->
(applySignIn model signInAction, Effects.none)
diff --git a/src/client/elm/Update/LoggedIn.elm b/src/client/elm/Update/LoggedIn.elm
index 1553141..ca4690b 100644
--- a/src/client/elm/Update/LoggedIn.elm
+++ b/src/client/elm/Update/LoggedIn.elm
@@ -25,22 +25,23 @@ updateLoggedIn model action loggedInView =
{ loggedInView | add = updateAddPayment addPaymentAction loggedInView.add }
UpdatePayments payments ->
{ loggedInView | payments = payments }
- AddPayment paymentId name cost ->
+ AddPayment paymentId name cost frequency ->
let newPayment = Payment paymentId (Date.fromTime model.currentTime) name cost loggedInView.account.me
- in { loggedInView
- | currentPage = 1
- , add = initAddPayment Punctual
- , account = updateAccount (UpdatePayer loggedInView.account.me model.currentTime cost) loggedInView.account
- , payments = newPayment :: loggedInView.payments
- , paymentsCount = loggedInView.paymentsCount + 1
- }
- AddMonthlyPayment id name cost ->
- { loggedInView
- | add = initAddPayment Monthly
- , monthly =
- let payment = Payment id (Date.fromTime model.currentTime) name cost loggedInView.account.me
- in updateMonthly (Monthly.AddPayment payment) loggedInView.monthly
- }
+ newAdd = initAddPayment frequency
+ in if frequency == Punctual
+ then
+ { loggedInView
+ | currentPage = 1
+ , add = newAdd
+ , account = updateAccount (UpdatePayer loggedInView.account.me model.currentTime cost) loggedInView.account
+ , payments = newPayment :: loggedInView.payments
+ , paymentsCount = loggedInView.paymentsCount + 1
+ }
+ else
+ { loggedInView
+ | add = newAdd
+ , monthly = updateMonthly (Monthly.AddPayment newPayment) loggedInView.monthly
+ }
ToggleEdit id ->
{ loggedInView | paymentEdition = if loggedInView.paymentEdition == Just id then Nothing else Just id }
DeletePayment payment ->
diff --git a/src/client/elm/View/LoggedIn/AddPayment.elm b/src/client/elm/View/LoggedIn/AddPayment.elm
index 0fbe28e..cbc93a1 100644
--- a/src/client/elm/View/LoggedIn/AddPayment.elm
+++ b/src/client/elm/View/LoggedIn/AddPayment.elm
@@ -31,11 +31,7 @@ addPayment address model loggedInView =
H.form
[ case (validateName loggedInView.add.name model.translations, validateCost loggedInView.add.cost model.translations) of
(Ok name, Ok cost) ->
- let action =
- case loggedInView.add.frequency of
- Punctual -> Communication.AddPayment name cost
- Monthly -> Communication.AddMonthlyPayment name cost
- in onSubmitPrevDefault address (ServerCommunication action)
+ onSubmitPrevDefault address (ServerCommunication (Communication.AddPayment name cost loggedInView.add.frequency))
(resName, resCost) ->
onSubmitPrevDefault address (UpdateLoggedIn <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost))
, class "addPayment"