aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Payment/Form.hs
diff options
context:
space:
mode:
authorJoris2019-10-06 19:28:54 +0200
committerJoris2019-10-06 19:28:54 +0200
commitf4c5df9e1b1afddeb5a482d4fbe654d0b321159c (patch)
tree206e02b4b0a6f78d5acf04ce89ff5fa4b07397a2 /client/src/View/Payment/Form.hs
parent2d79ab0e0a11f55255fc21a5dfab1598d3beeba3 (diff)
downloadbudget-f4c5df9e1b1afddeb5a482d4fbe654d0b321159c.tar.gz
budget-f4c5df9e1b1afddeb5a482d4fbe654d0b321159c.tar.bz2
budget-f4c5df9e1b1afddeb5a482d4fbe654d0b321159c.zip
Make payment edition to work on the frontend
Diffstat (limited to 'client/src/View/Payment/Form.hs')
-rw-r--r--client/src/View/Payment/Form.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/client/src/View/Payment/Form.hs b/client/src/View/Payment/Form.hs
index ba54957..9889638 100644
--- a/client/src/View/Payment/Form.hs
+++ b/client/src/View/Payment/Form.hs
@@ -1,6 +1,7 @@
module View.Payment.Form
( view
, Input(..)
+ , HttpMethod(..)
, Output(..)
) where
@@ -46,8 +47,11 @@ data Input t p = Input
, _input_category :: CategoryId
, _input_frequency :: Frequency
, _input_mkPayload :: Text -> Int -> Day -> CategoryId -> Frequency -> p
+ , _input_httpMethod :: HttpMethod
}
+data HttpMethod = Put | Post
+
data Output t = Output
{ _output_hide :: Event t ()
, _output_addPayment :: Event t SavedPayment
@@ -139,7 +143,7 @@ view input = do
})
(addPayment, waiting) <- WaitFor.waitFor
- (Ajax.postJson "/payment")
+ (ajax "/payment")
(ValidationUtil.fireValidation payment confirm)
return (R.fmapMaybe EitherUtil.eitherToMaybe addPayment, cancel, confirm)
@@ -150,14 +154,19 @@ view input = do
}
where
- frequencies = M.fromList
- [ (Punctual, Msg.get Msg.Payment_PunctualMale)
- , (Monthly, Msg.get Msg.Payment_MonthlyMale)
- ]
+ frequencies =
+ M.fromList
+ [ (Punctual, Msg.get Msg.Payment_PunctualMale)
+ , (Monthly, Msg.get Msg.Payment_MonthlyMale)
+ ]
categories = M.fromList . flip map (_input_categories input) $ \c ->
(_category_id c, _category_name c)
+ ajax =
+ case _input_httpMethod input of
+ Post -> Ajax.postJson
+ Put -> Ajax.putJson
findCategory :: Text -> [PaymentCategory] -> Maybe CategoryId
findCategory paymentName =