@@ -36,43 +36,22 @@ placeOrder st =
36
36
Dialog. argsOptic = # modelPlaceOrder,
37
37
Dialog. argsAction = PushUpdate ,
38
38
Dialog. argsContent =
39
- [ button_
40
- [ onClick
41
- . either impureThrow openBrowser
42
- $ teleUri st
43
- ]
44
- [ icon Icon. IconTelegram ,
45
- text " Telegram"
46
- ],
47
- button_
48
- [ onClick
49
- . either impureThrow openBrowser
50
- $ whatsUri st
51
- ]
52
- [ icon Icon. IconWhatsApp ,
53
- text " WhatsApp"
54
- ],
55
- button_
56
- [ onClick
57
- . either impureThrow openBrowser
58
- $ emailUri st
59
- ]
60
- [ icon Icon. IconEmail ,
61
- text " Email"
62
- ],
63
- button_
64
- [ onClick . PushUpdate . EffectUpdate $ do
65
- let doc = st ^. # modelState
66
- imgs <- Jsm. fetchBlobUris doc
67
- file <- Xlsx. xlsxFile
68
- Jsm. saveFileShare file Xlsx. xlsxMime
69
- . from @ BL. ByteString @ ByteString
70
- $ Xlsx. newXlsx doc imgs
71
- ]
72
- [ icon Icon. IconDownload ,
73
- text " Share Excel file"
74
- ]
75
- ]
39
+ teleBtn st
40
+ <> whatsBtn st
41
+ <> emailBtn st
42
+ <> [ button_
43
+ [ onClick . PushUpdate . EffectUpdate $ do
44
+ let doc = st ^. # modelState
45
+ imgs <- Jsm. fetchBlobUris doc
46
+ file <- Xlsx. xlsxFile
47
+ Jsm. saveFileShare file Xlsx. xlsxMime
48
+ . from @ BL. ByteString @ ByteString
49
+ $ Xlsx. newXlsx doc imgs
50
+ ]
51
+ [ icon Icon. IconDownload ,
52
+ text " Share Excel file"
53
+ ]
54
+ ]
76
55
}
77
56
78
57
openBrowser :: URI -> Action
@@ -81,16 +60,25 @@ openBrowser =
81
60
. EffectUpdate
82
61
. Jsm. openBrowserPage
83
62
84
- teleUri :: (MonadThrow m ) => Model -> m URI
85
- teleUri st = do
63
+ teleBtn :: Model -> [View Action ]
64
+ teleBtn st =
65
+ case st ^. # modelState . # stMerchantTele . # fieldOutput of
66
+ user | null user -> mempty
67
+ user ->
68
+ [ button_
69
+ [ onClick
70
+ . either impureThrow openBrowser
71
+ $ teleUri user
72
+ ]
73
+ [ icon Icon. IconTelegram ,
74
+ text " Telegram"
75
+ ]
76
+ ]
77
+
78
+ teleUri :: (MonadThrow m ) => Unicode -> m URI
79
+ teleUri raw = do
86
80
base <- URI. mkURI " https://t.me"
87
- user <-
88
- URI. mkPathPiece
89
- . from @ Unicode @ Text
90
- $ st
91
- ^. # modelState
92
- . # stMerchantTele
93
- . # fieldOutput
81
+ user <- URI. mkPathPiece $ from @ Unicode @ Text raw
94
82
key <- URI. mkQueryKey " text"
95
83
val <- URI. mkQueryValue placeOrderMessage
96
84
pure
@@ -99,16 +87,25 @@ teleUri st = do
99
87
URI. uriQuery = [URI. QueryParam key val]
100
88
}
101
89
102
- whatsUri :: (MonadThrow m ) => Model -> m URI
103
- whatsUri st = do
90
+ whatsBtn :: Model -> [View Action ]
91
+ whatsBtn st =
92
+ case st ^. # modelState . # stMerchantWhats . # fieldOutput of
93
+ user | null user -> mempty
94
+ user ->
95
+ [ button_
96
+ [ onClick
97
+ . either impureThrow openBrowser
98
+ $ whatsUri user
99
+ ]
100
+ [ icon Icon. IconWhatsApp ,
101
+ text " WhatsApp"
102
+ ]
103
+ ]
104
+
105
+ whatsUri :: (MonadThrow m ) => Unicode -> m URI
106
+ whatsUri raw = do
104
107
base <- URI. mkURI " https://wa.me"
105
- user <-
106
- URI. mkPathPiece
107
- . from @ Unicode @ Text
108
- $ st
109
- ^. # modelState
110
- . # stMerchantWhats
111
- . # fieldOutput
108
+ user <- URI. mkPathPiece $ from @ Unicode @ Text raw
112
109
key <- URI. mkQueryKey " text"
113
110
val <- URI. mkQueryValue placeOrderMessage
114
111
pure
@@ -117,15 +114,24 @@ whatsUri st = do
117
114
URI. uriQuery = [URI. QueryParam key val]
118
115
}
119
116
120
- emailUri :: (MonadThrow m ) => Model -> m URI
121
- emailUri st = do
122
- user <-
123
- URI. mkPathPiece
124
- . from @ Unicode @ Text
125
- $ st
126
- ^. # modelState
127
- . # stMerchantEmail
128
- . # fieldOutput
117
+ emailBtn :: Model -> [View Action ]
118
+ emailBtn st =
119
+ case st ^. # modelState . # stMerchantEmail . # fieldOutput of
120
+ user | null user -> mempty
121
+ user ->
122
+ [ button_
123
+ [ onClick
124
+ . either impureThrow openBrowser
125
+ $ emailUri user
126
+ ]
127
+ [ icon Icon. IconEmail ,
128
+ text " Email"
129
+ ]
130
+ ]
131
+
132
+ emailUri :: (MonadThrow m ) => Unicode -> m URI
133
+ emailUri raw = do
134
+ user <- URI. mkPathPiece $ from @ Unicode @ Text raw
129
135
base <- URI. mkURI $ " mailto:" <> URI. unRText user
130
136
subjKey <- URI. mkQueryKey " subject"
131
137
subjVal <- URI. mkQueryValue " Delivery Calculator"
0 commit comments