aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/View/LoggedIn/AddPayment.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/View/LoggedIn/AddPayment.elm')
-rw-r--r--src/client/elm/View/LoggedIn/AddPayment.elm29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/client/elm/View/LoggedIn/AddPayment.elm b/src/client/elm/View/LoggedIn/AddPayment.elm
index 5739a95..283d392 100644
--- a/src/client/elm/View/LoggedIn/AddPayment.elm
+++ b/src/client/elm/View/LoggedIn/AddPayment.elm
@@ -14,7 +14,7 @@ import Model exposing (Model)
import Model.Payment exposing (PaymentFrequency(..))
import Model.Translations exposing (getMessage)
import Model.Action exposing (..)
-import Model.Action.LoggedInAction exposing (..)
+import Model.Action.LoggedInAction as LoggedInAction exposing (..)
import Model.Action.AddPaymentAction exposing (..)
import Model.Communication as Communication
@@ -22,7 +22,7 @@ import Model.View.LoggedIn.AddPayment exposing (..)
import Model.View.LoggedInView exposing (LoggedInView)
import View.Events exposing (onSubmitPrevDefault)
-import View.Icon exposing (renderIcon)
+import View.Icon exposing (..)
import Utils.Maybe exposing (isJust)
import Utils.Either exposing (toMaybeError)
@@ -30,11 +30,16 @@ import Utils.Either exposing (toMaybeError)
addPayment : Address Action -> Model -> LoggedInView -> Html
addPayment address model loggedInView =
H.form
- [ case (validateName loggedInView.add.name model.translations, validateCost loggedInView.add.cost model.translations) of
- (Ok name, Ok cost) ->
- onSubmitPrevDefault address (ServerCommunication (Communication.AddPayment name cost loggedInView.add.frequency))
- (resName, resCost) ->
- onSubmitPrevDefault address (UpdateLoggedIn <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost))
+ [ let update =
+ if loggedInView.add.waitingServer
+ then NoOp
+ else
+ case (validateName loggedInView.add.name model.translations, validateCost loggedInView.add.cost model.translations) of
+ (Ok name, Ok cost) ->
+ UpdateLoggedIn <| LoggedInAction.AddPayment name cost loggedInView.add.frequency
+ (resName, resCost) ->
+ UpdateLoggedIn <| UpdateAdd <| AddError (toMaybeError resName) (toMaybeError resCost)
+ in onSubmitPrevDefault address update
, class "addPayment"
]
[ addPaymentName address loggedInView.add
@@ -42,8 +47,14 @@ addPayment address model loggedInView =
, paymentFrequency address model loggedInView.add
, button
[ type' "submit"
- , class "add" ]
- [ text (getMessage "Add" model.translations)]
+ , classList
+ [ ("add", True)
+ , ("waitingServer", loggedInView.add.waitingServer)
+ ]
+ ]
+ [ text (getMessage "Add" model.translations)
+ , if loggedInView.add.waitingServer then renderSpinIcon else text ""
+ ]
]
addPaymentName : Address Action -> AddPayment -> Html