aboutsummaryrefslogtreecommitdiff
path: root/client/src/View
diff options
context:
space:
mode:
authorJoris2018-10-28 17:57:58 +0100
committerJoris2018-10-28 17:57:58 +0100
commit40b4994797a797b1fa86cafda789a5c488730c6d (patch)
treead195b31fa442821b9de8f99364e254f0f41935f /client/src/View
parentdf83b634006c699cfa1e921bf74ce951a906a62f (diff)
Delete payment
Diffstat (limited to 'client/src/View')
-rw-r--r--client/src/View/Payment/Add.hs6
-rw-r--r--client/src/View/Payment/Delete.hs40
-rw-r--r--client/src/View/Payment/Header.hs4
-rw-r--r--client/src/View/Payment/Table.hs2
-rw-r--r--client/src/View/SignIn.hs6
5 files changed, 33 insertions, 25 deletions
diff --git a/client/src/View/Payment/Add.hs b/client/src/View/Payment/Add.hs
index 5ff09dd..8b1b56e 100644
--- a/client/src/View/Payment/Add.hs
+++ b/client/src/View/Payment/Add.hs
@@ -23,7 +23,7 @@ import Component (ButtonIn (..), InputIn (..),
SelectOut (..))
import qualified Component as Component
import qualified Util.Ajax as Ajax
-import qualified Util.WaitFor as Util
+import qualified Util.WaitFor as WaitFor
data AddIn = AddIn
{ _addIn_categories :: [Category]
@@ -83,8 +83,8 @@ view addIn = do
, _buttonIn_submit = True
})
- (_, waiting) <- Util.waitFor
- (Ajax.post "/payment")
+ (_, waiting) <- WaitFor.waitFor
+ (Ajax.postJson "/payment")
validate
payment
diff --git a/client/src/View/Payment/Delete.hs b/client/src/View/Payment/Delete.hs
index a1be16d..03cf267 100644
--- a/client/src/View/Payment/Delete.hs
+++ b/client/src/View/Payment/Delete.hs
@@ -4,24 +4,27 @@ module View.Payment.Delete
, DeleteOut(..)
) where
-import Reflex.Dom (Event, MonadWidget)
-import qualified Reflex.Dom as R
-
-import qualified Common.Msg as Msg
-import Component (ButtonIn (..), ButtonOut (..))
-import qualified Component as Component
--- import qualified Util.Ajax as Ajax
--- import qualified Util.WaitFor as Util
-
-data DeleteIn = DeleteIn
- {}
+import qualified Data.Text as T
+import Reflex.Dom (Dynamic, Event, MonadWidget)
+import qualified Reflex.Dom as R
+
+import Common.Model.Payment (PaymentId)
+import qualified Common.Msg as Msg
+import Component (ButtonIn (..), ButtonOut (..))
+import qualified Component as Component
+import qualified Util.Ajax as Ajax
+-- import qualified Util.WaitFor as WaitFor
+
+data DeleteIn t = DeleteIn
+ { _deleteIn_id :: Dynamic t PaymentId
+ }
data DeleteOut t = DeleteOut
{ _deleteOut_cancel :: Event t ()
}
-view :: forall t m. MonadWidget t m => DeleteIn -> m (DeleteOut t)
-view _ =
+view :: forall t m. MonadWidget t m => (DeleteIn t) -> m (DeleteOut t)
+view deleteIn =
R.divClass "delete" $ do
R.divClass "deleteHeader" $ R.text $ Msg.get Msg.Payment_DeleteConfirm
@@ -29,14 +32,19 @@ view _ =
cancel <- R.divClass "buttons" $ do
rec
- _ <- Component._buttonOut_clic <$> (Component.button $
+ confirm <- Component._buttonOut_clic <$> (Component.button $
(Component.defaultButtonIn (R.text $ Msg.get Msg.Dialog_Confirm))
{ _buttonIn_class = R.constDyn "confirm"
, _buttonIn_submit = True
})
- -- (_, waiting) <- Util.waitFor
- -- (Ajax.post "/payment")
+ let url = flip fmap (_deleteIn_id deleteIn) (\id ->
+ T.concat ["/payment/", T.pack . show $ id]
+ )
+ Ajax.delete url confirm
+
+ -- (_, waiting) <- WaitFor.waitFor
+ -- (Ajax.delete "/payment")
-- validate
-- payment
diff --git a/client/src/View/Payment/Header.hs b/client/src/View/Payment/Header.hs
index fd46c25..be7f6d5 100644
--- a/client/src/View/Payment/Header.hs
+++ b/client/src/View/Payment/Header.hs
@@ -86,7 +86,7 @@ payerAndAdd incomes payments users categories currency = do
R.text "+ "
R.text . Format.price currency $ _exceedingPayer_amount p
)
- addPayment <- _buttonOut_clic <$> (Component.button $ ButtonIn
+ addPaymentClic <- _buttonOut_clic <$> (Component.button $ ButtonIn
{ _buttonIn_class = R.constDyn "addPayment"
, _buttonIn_content = R.text $ Msg.get Msg.Payment_Add
, _buttonIn_waiting = R.never
@@ -95,7 +95,7 @@ payerAndAdd incomes payments users categories currency = do
})
rec
modalOut <- Component.modal $ ModalIn
- { _modalIn_show = addPayment
+ { _modalIn_show = addPaymentClic
, _modalIn_hide = _addOut_cancel . _modalOut_content $ modalOut
, _modalIn_content = Add.view $ AddIn { _addIn_categories = categories }
}
diff --git a/client/src/View/Payment/Table.hs b/client/src/View/Payment/Table.hs
index 23d7225..13cedda 100644
--- a/client/src/View/Payment/Table.hs
+++ b/client/src/View/Payment/Table.hs
@@ -118,7 +118,7 @@ paymentRow init payment =
modalOut <- Component.modal $ ModalIn
{ _modalIn_show = deletePayment
, _modalIn_hide = _deleteOut_cancel . _modalOut_content $ modalOut
- , _modalIn_content = Delete.view (DeleteIn {})
+ , _modalIn_content = Delete.view (DeleteIn { _deleteIn_id = fmap _payment_id payment })
}
return ()
diff --git a/client/src/View/SignIn.hs b/client/src/View/SignIn.hs
index 21d0fcc..24e5be0 100644
--- a/client/src/View/SignIn.hs
+++ b/client/src/View/SignIn.hs
@@ -16,7 +16,7 @@ import Component (ButtonIn (..), ButtonOut (..), InputIn (..),
InputOut (..))
import qualified Component as Component
import qualified Util.Ajax as Ajax
-import qualified Util.WaitFor as Util
+import qualified Util.WaitFor as WaitFor
data SignInMessage =
SuccessMessage Text
@@ -43,8 +43,8 @@ view signInMessage =
, _buttonIn_submit = True
}
- (signInResult, waiting) <- Util.waitFor
- (\email -> Ajax.post "/askSignIn" (SignIn <$> email))
+ (signInResult, waiting) <- WaitFor.waitFor
+ (\email -> Ajax.postJson "/askSignIn" (SignIn <$> email))
(_buttonOut_clic button)
(_inputOut_value input)