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
|
module View.Payment.Delete
( view
, DeleteIn(..)
, DeleteOut(..)
) where
import Data.Text (Text)
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.Either as EitherUtil
import qualified Util.WaitFor as WaitFor
data DeleteIn t = DeleteIn
{ _deleteIn_id :: Dynamic t PaymentId
}
data DeleteOut t = DeleteOut
{ _deleteOut_cancel :: Event t ()
, _deleteOut_validate :: Event t PaymentId
}
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
R.divClass "deleteContent" $ do
(deletedPayment, cancel) <- R.divClass "buttons" $ do
rec
confirm <- Component._buttonOut_clic <$> (Component.button $
(Component.defaultButtonIn (R.text $ Msg.get Msg.Dialog_Confirm))
{ _buttonIn_class = R.constDyn "confirm"
, _buttonIn_submit = True
, _buttonIn_waiting = waiting
})
let url = flip fmap (_deleteIn_id deleteIn) (\id ->
T.concat ["/payment/", T.pack . show $ id]
)
(result, waiting) <- WaitFor.waitFor
(Ajax.delete url)
confirm
cancel <- Component._buttonOut_clic <$> (Component.button $
(Component.defaultButtonIn (R.text $ Msg.get Msg.Dialog_Undo))
{ _buttonIn_class = R.constDyn "undo" })
return (R.fmapMaybe EitherUtil.eitherToMaybe result, cancel)
return DeleteOut
{ _deleteOut_cancel = cancel
, _deleteOut_validate = R.tag (R.current $ _deleteIn_id deleteIn) deletedPayment
}
|