1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
module View.Payment.Add
( view
, Input(..)
) where
import Control.Monad (join)
import Control.Monad.IO.Class (liftIO)
import qualified Data.Text as T
import qualified Data.Time.Clock as Time
import Reflex.Dom (Dynamic, Event, MonadWidget)
import qualified Reflex.Dom as R
import Common.Model (Category (..), CreatePayment (..),
Frequency (..), Payment (..),
PaymentCategory (..),
SavedPayment (..))
import qualified Common.Msg as Msg
import qualified Common.Util.Time as TimeUtil
import qualified Common.Validation.Payment as PaymentValidation
import qualified Component.Modal as Modal
import qualified Util.Reflex as ReflexUtil
import qualified View.Payment.Form as Form
data Input t = Input
{ _input_categories :: [Category]
, _input_paymentCategories :: Dynamic t [PaymentCategory]
, _input_frequency :: Dynamic t Frequency
}
view :: forall t m. MonadWidget t m => Input t -> Modal.Content t m SavedPayment
view input cancel = do
currentDay <- liftIO $ Time.getCurrentTime >>= TimeUtil.timeToDay
formOutput <- R.dyn $ do
paymentCategories <- _input_paymentCategories input
frequency <- _input_frequency input
return $ Form.view $ Form.Input
{ Form._input_cancel = cancel
, Form._input_headerLabel = Msg.get Msg.Payment_Add
, Form._input_categories = _input_categories input
, Form._input_paymentCategories = paymentCategories
, Form._input_name = ""
, Form._input_cost = ""
, Form._input_date = currentDay
, Form._input_category = -1
, Form._input_frequency = frequency
, Form._input_mkPayload = CreatePayment
, Form._input_httpMethod = Form.Post
}
hide <- ReflexUtil.flatten (Form._output_hide <$> formOutput)
addPayment <- ReflexUtil.flatten (Form._output_addPayment <$> formOutput)
return (hide, addPayment)
|