use dioxus::prelude::*; use crate::app::Route; use crate::components::help_chat::HelpChat; use crate::components::no_access::{NoAccess, ReadOnlyBanner}; use crate::components::notification_bell::NotificationBell; use crate::components::sidebar::Sidebar; use crate::components::support::{SupportBanner, SupportPicker}; use crate::components::toast::{ToastContainer, Toasts}; use crate::infrastructure::auth_check::check_auth; use crate::infrastructure::platform::fetch_platform_info; /// How often an open page checks that the sign-in is still valid. #[cfg(feature = "web")] const SIGN_IN_CHECK_MS: u32 = 60_000; #[component] pub fn AppShell() -> Element { use_context_provider(Toasts::new); crate::i18n::provide_lang(); // Agent contract handshake (features such as `source_only`), provided // app-wide so pages can hide runtime-only surfaces. Read on the server // before the first render, so a page never shows a feature first and // then takes it away; an unreachable agent reads as the full set. let platform = use_server_future(fetch_platform_info)?; let auth = use_server_future(check_auth)?; let platform_now = platform().and_then(Result::ok).unwrap_or_default(); use_context_provider(|| Signal::new(platform_now)); // A sign-in can run out while a page stays open: check now and then, and // send the browser to the login rather than letting every page fail. use_future(move || async move { #[cfg(feature = "web")] loop { gloo_timers::future::TimeoutFuture::new(SIGN_IN_CHECK_MS).await; if let Ok(info) = check_auth().await { if !info.authenticated { crate::infrastructure::auth_check::go_to_login(); break; } } } }); match auth() { // BreakPilot support chooses a tenant first: every page asks the agent // for one, and without it would only be refused. Some(Ok(info)) if info.authenticated && info.staff && info.support_tenant.is_none() => { rsx! { SupportPicker {} ToastContainer {} } } // A member the workspace blocked (portal#74): the agent refuses // everything, so the app shows only that. Some(Ok(info)) if info.authenticated && info.member_blocked => { rsx! { NoAccess { portal_url: info.portal_url.clone(), blocked: true } } } // A role without access to Prüfwerk (FINANCE, or none): no navigation // and no page, so nothing is fetched or shown. Some(Ok(info)) if info.authenticated && !info.access.can_read() => { rsx! { NoAccess { portal_url: info.portal_url.clone() } } } Some(Ok(info)) if info.authenticated => { use_context_provider(|| Signal::new(info.clone())); let read_only = !info.access.can_write(); rsx! { div { class: "app-shell", Sidebar {} main { class: "main-content", if let Some(tenant) = info.support_tenant.clone() { SupportBanner { tenant } } if read_only { ReadOnlyBanner {} } Outlet:: {} } NotificationBell {} ToastContainer {} HelpChat {} } } } Some(Ok(_)) | Some(Err(_)) => { // Not authenticated — redirect to Keycloak login rsx! { document::Script { "window.location.href = '/auth';" } } } None => { rsx! { div { class: "flex items-center justify-center h-screen bg-gray-950", p { class: "text-gray-400", "Loading..." } } } } } }