Skip to content

Commit 323f12a

Browse files
committed
feat(ui): improve login modal
- add error message handling - overall nicer ui
1 parent 95a8fb6 commit 323f12a

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

src/main/parts/frontend/components/login_modal.cljs

+27-18
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,31 @@
1515
[loading set-loading] (use-state false)
1616
{:keys [login]} (ctx/use-auth)
1717

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 ""))
1825
handle-submit (fn [e]
1926
(.preventDefault e)
2027
(set-loading true)
2128
(set-error nil)
2229
(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)))))]
3238

3339
($ modal
3440
{:show show
35-
:on-close on-close}
41+
:on-close handle-close
42+
:title "Log in"}
3643

3744
($ :<>
3845
(when error
@@ -49,17 +56,15 @@
4956
:value csrf-token}))
5057

5158
($ :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"}
5560
($ :div {:class "form-control mb-3"}
5661
($ :label {:class "fieldset-label" :for "email"}
5762
"Email")
5863
($ :input
5964
{:type "email"
6065
:id "email"
6166
:placeholder "[email protected]"
62-
:class "input input-bordered w-full"
67+
:class "input w-full"
6368
:value email
6469
:disabled loading
6570
:on-change #(set-email (.. % -target -value))
@@ -71,20 +76,24 @@
7176
($ :input
7277
{:type "password"
7378
:id "password"
74-
:class "input input-bordered w-full"
79+
:class "input w-full"
7580
:value password
7681
:disabled loading
7782
:on-change #(set-password (.. % -target -value))
7883
:required true}))
7984
($ :div {:class "modal-action mt-6 space-x-2 flex"}
8085
($ :button
8186
{:type "button"
82-
:class "btn btn-outline flex-1"
87+
:class "btn flex-1"
8388
:disabled loading
8489
:on-click on-close}
8590
"Cancel")
8691
($ :button
8792
{:type "submit"
8893
: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")))))))))

src/main/parts/frontend/components/modal.cljs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
($ :div
2727
{:class "modal-box"
2828
: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+
"")
3333
(when title
34-
($ :h3 {:class "text-lg font-bold"} title))
34+
($ :h3 {:class "text-lg font-bold mb-4"} title))
3535
children))))

0 commit comments

Comments
 (0)