Skip to content

Commit 6331788

Browse files
committed
fix(app): customize unauthenticated error for org_selector_menu
1 parent d6364c5 commit 6331788

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

crates/app/src/components/org_selector.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::{
1818
components::{
1919
form_result::form_rejection, icons::*, text_data::org_descriptor,
2020
},
21-
ctx::{Ctx, RequireAuth, ResponseSeed},
22-
form_feedback_text::INTERNAL_ERROR_MESSAGE,
21+
ctx::{Ctx, MaybeAuth, RequireAuth, ResponseSeed},
22+
form_feedback_text::{INTERNAL_ERROR_MESSAGE, UNAUTHENTICATED_MESSAGE},
2323
hooks::OrgUrlHook,
2424
};
2525

@@ -85,12 +85,25 @@ fn org_selector_trigger(ctx: Ctx<RequireAuth>) -> Markup {
8585
}
8686
}
8787

88-
async fn org_selector_menu(
89-
ResponseSeed(ctx, resp): ResponseSeed<RequireAuth>,
90-
) -> impl IntoResponse {
88+
fn popover_wrapper(children: Markup) -> Markup {
9189
const POPOVER_CLASS: &str =
9290
"absolute right-0 top-[calc(100%+(var(--spacing)*4))] min-w-56 \
9391
elevation-lv1 z-50 p-2 flex flex-col gap-1 leading-none";
92+
html! {
93+
div data-popover class=(POPOVER_CLASS) {
94+
(children)
95+
}
96+
}
97+
}
98+
99+
async fn org_selector_menu(
100+
ResponseSeed(ctx, resp): ResponseSeed<MaybeAuth>,
101+
) -> impl IntoResponse {
102+
// upgrade to RequireAuth with custom error
103+
let Some(ctx) = ctx.into_require_auth() else {
104+
return resp
105+
.into_stream(popover_wrapper(form_rejection(UNAUTHENTICATED_MESSAGE)));
106+
};
94107

95108
let auth_user = ctx.auth_user();
96109
let active_org = auth_user.active_org();
@@ -100,15 +113,15 @@ async fn org_selector_menu(
100113
.collect::<Vec<_>>();
101114

102115
resp.into_stream(html! {
103-
div data-popover class=(POPOVER_CLASS) {
116+
(popover_wrapper(html! {
104117
@ for org_row in org_rows {
105118
(org_row)
106119
}
107120
div class="p-1" {
108121
div class="h-0 border-t-2 border-base-6/75" {}
109122
}
110123
(extra_rows(ctx))
111-
}
124+
}))
112125
})
113126
}
114127

0 commit comments

Comments
 (0)