File tree 2 files changed +32
-23
lines changed
src/main/parts/frontend/components
2 files changed +32
-23
lines changed Original file line number Diff line number Diff line change 15
15
[loading set-loading] (use-state false )
16
16
{:keys [login]} (ctx/use-auth )
17
17
18
+ handle-close (fn [e]
19
+ (.preventDefault e)
20
+ (on-close )
21
+ (set-loading false )
22
+ (set-error nil )
23
+ (set-password " " )
24
+ (set-email " " ))
18
25
handle-submit (fn [e]
19
26
(.preventDefault e)
20
27
(set-loading true )
21
28
(set-error nil )
22
29
(go
23
- (try
24
- (let [_result (<! (login {:email email
25
- :password password}))]
26
- (set-loading false )
27
- (on-close ))
28
- (catch js/Error err
29
- (js/console.log " Login error:" , err)
30
- (set-loading false )
31
- (set-error " Invalid email or password" )))))]
30
+ (let [result (<! (login {:email email
31
+ :password password}))]
32
+ (set-loading false )
33
+ (if (= 401 (:status result))
34
+ (do
35
+ (set-error (get-in result [:body :error ]))
36
+ (println " Login error:" result (get-in result [:body :error ])))
37
+ (handle-close e)))))]
32
38
33
39
($ modal
34
40
{:show show
35
- :on-close on-close}
41
+ :on-close handle-close
42
+ :title " Log in" }
36
43
37
44
($ :<>
38
45
(when error
49
56
:value csrf-token}))
50
57
51
58
($ :fieldset
52
- {:class " fieldset w-full bg-base-200 border border-base-300 p-4 rounded-box" }
53
- ($ :legend {:class " fieldset-legend" } " Login" )
54
-
59
+ {:class " fieldset w-full" }
55
60
($ :div {:class " form-control mb-3" }
56
61
($ :label {:class " fieldset-label" :for " email" }
57
62
" Email" )
58
63
($ :input
59
64
{:type " email"
60
65
:id " email"
61
66
62
- :class " input input-bordered w-full"
67
+ :class " input w-full"
63
68
:value email
64
69
:disabled loading
65
70
:on-change #(set-email (.. % -target -value))
71
76
($ :input
72
77
{:type " password"
73
78
:id " password"
74
- :class " input input-bordered w-full"
79
+ :class " input w-full"
75
80
:value password
76
81
:disabled loading
77
82
:on-change #(set-password (.. % -target -value))
78
83
:required true }))
79
84
($ :div {:class " modal-action mt-6 space-x-2 flex" }
80
85
($ :button
81
86
{:type " button"
82
- :class " btn btn-outline flex-1"
87
+ :class " btn flex-1"
83
88
:disabled loading
84
89
:on-click on-close}
85
90
" Cancel" )
86
91
($ :button
87
92
{:type " submit"
88
93
:disabled loading
89
- :class (str " btn btn-primary flex-1" (when loading " loading" ))}
90
- (if loading " Logging in..." " Log in" )))))))))
94
+ :class " btn btn-primary flex-1" }
95
+ (if loading
96
+ ($ :<>
97
+ ($ :span {:class " loading loading-spinner" })
98
+ " Logging in..." )
99
+ " Log in" )))))))))
Original file line number Diff line number Diff line change 26
26
($ :div
27
27
{:class " modal-box"
28
28
:on-click #(.stopPropagation %)}
29
- ; ; ;; ($ :button
30
- ; ; ;; {:class "btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
31
- ; ; ;; :on-click on-close}
32
- ; ; "✕")
29
+ ($ :button
30
+ {:class " btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
31
+ :on-click on-close}
32
+ " ✕" )
33
33
(when title
34
- ($ :h3 {:class " text-lg font-bold" } title))
34
+ ($ :h3 {:class " text-lg font-bold mb-4 " } title))
35
35
children))))
You can’t perform that action at this time.
0 commit comments