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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
module View.Payment.HeaderForm
( view
, In(..)
, Out(..)
) where
import qualified Data.Map as M
import Data.Text (Text)
import qualified Data.Validation as V
import Reflex.Dom (Dynamic, Event, MonadWidget)
import qualified Reflex.Dom as R
import Common.Model (Category, Currency, Frequency (..),
Income (..), Payment (..), User (..))
import qualified Common.Msg as Msg
import qualified Component.Button as Button
import qualified Component.Input as Input
import qualified Component.Modal as Modal
import qualified Component.Select as Select
import qualified Util.Reflex as ReflexUtil
import qualified View.Payment.Form as Form
data In t = In
{ _in_reset :: Event t ()
, _in_categories :: [Category]
}
data Out t = Out
{ _out_search :: Event t Text
, _out_frequency :: Event t Frequency
, _out_addPayment :: Event t Payment
}
view :: forall t m. MonadWidget t m => In t -> m (Out t)
view input =
R.divClass "g-PaymentHeaderForm" $ do
(searchName, frequency) <- R.el "div" $ do
searchName <- Input._out_raw <$> (Input.view
( Input.defaultIn { Input._in_label = Msg.get Msg.Search_Name })
("" <$ _in_reset input)
R.never)
let frequencies = M.fromList
[ (Punctual, Msg.get Msg.Payment_PunctualMale)
, (Monthly, Msg.get Msg.Payment_MonthlyMale)
]
frequency <- Select._out_raw <$> (Select.view $ Select.In
{ Select._in_label = ""
, Select._in_initialValue = Punctual
, Select._in_value = R.never
, Select._in_values = R.constDyn frequencies
, Select._in_reset = R.never
, Select._in_isValid = V.Success
, Select._in_validate = R.never
})
return (searchName, frequency)
addPaymentButton <- Button._out_clic <$>
(Button.view $
(Button.defaultIn (R.text $ Msg.get Msg.Payment_Add))
{ Button._in_class = R.constDyn "addPayment"
})
addPayment <-
(R.dyn . R.ffor frequency $ \frequency ->
Modal.view $ Modal.In
{ Modal._in_show = addPaymentButton
, Modal._in_content =
Form.view $ Form.In
{ Form._in_categories = _in_categories input
, Form._in_operation = Form.New
, Form._in_frequency = frequency
}
}) >>= ReflexUtil.flatten
return $ Out
{ _out_search = R.updated searchName
, _out_frequency = R.updated frequency
, _out_addPayment = addPayment
}
|