Skip to content

Commit 4527347

Browse files
authored
Merge pull request #4506 from zeel2104/ui-rewrite-loading-page-clean
feat: add React loading page
2 parents 2babb3b + afcc8d5 commit 4527347

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

client/src/App.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ import { App } from "./App";
55
import { renderWithProviders } from "./test/test-utils";
66

77
describe("App", () => {
8+
it("renders the loading page without authentication", async () => {
9+
localStorage.clear();
10+
sessionStorage.clear();
11+
window.history.pushState({}, "", "/app/loading");
12+
13+
renderWithProviders(<App />);
14+
15+
expect(await screen.findByRole("status", { name: /loading/i })).toBeInTheDocument();
16+
expect(screen.queryByText(/loading/i)).not.toBeInTheDocument();
17+
});
18+
819
it("logs in and navigates to Gateways page via sidebar", async () => {
920
const user = userEvent.setup();
1021

client/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { RouterProvider, Route, Redirect, AuthGuard, useRouter } from "./router"
44
import { AppShell } from "./components/layout/AppShell";
55

66
import { Login } from "./pages/Login";
7+
import { Loading } from "./pages/Loading";
78
import { ForgotPassword } from "./pages/ForgotPassword";
89
import { ResetPassword } from "./pages/ResetPassword";
910
import { ChangePassword } from "./pages/ChangePassword";
@@ -34,6 +35,7 @@ import { NotFound } from "./pages/NotFound";
3435
function PublicRoutes() {
3536
return (
3637
<>
38+
<Route path="/app/loading" component={Loading} />
3739
<Route path="/app/login" component={Login} />
3840
<Route path="/app/forgot-password" component={ForgotPassword} />
3941
<Route path="/app/reset-password/:token" component={ResetPassword} />

client/src/pages/Loading.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useIntl } from "react-intl";
2+
import { MainNavIcon } from "../components/icons/MainNavIcon";
3+
4+
export function Loading() {
5+
const intl = useIntl();
6+
const label = intl.formatMessage({ id: "common.loading" });
7+
8+
return (
9+
<main className="min-h-screen bg-background text-foreground">
10+
<div className="flex min-h-screen items-center justify-center px-6">
11+
<div
12+
role="status"
13+
aria-live="polite"
14+
aria-label={label}
15+
className="flex size-24 items-center justify-center rounded-lg border border-border bg-card text-card-foreground shadow-sm"
16+
>
17+
<MainNavIcon className="h-12 w-14" />
18+
</div>
19+
</div>
20+
</main>
21+
);
22+
}

client/src/router/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ export function Redirect({ to }: { to: string }) {
201201
// ---------------------------------------------------------------------------
202202

203203
// Exact paths that are always public.
204-
const DEFAULT_PUBLIC_PATHS: readonly string[] = ["/app/login", "/app/forgot-password"];
204+
const DEFAULT_PUBLIC_PATHS: readonly string[] = [
205+
"/app/loading",
206+
"/app/login",
207+
"/app/forgot-password",
208+
];
205209

206210
// Path prefixes whose subtrees are always public.
207211
const DEFAULT_PUBLIC_PREFIXES: readonly string[] = ["/app/reset-password/"];
@@ -231,6 +235,6 @@ export function AuthGuard({
231235
}
232236
}, [authenticated, isPublic, navigate]);
233237

234-
if (!authenticated) return null;
238+
if (isPublic || !authenticated) return null;
235239
return <>{children}</>;
236240
}

0 commit comments

Comments
 (0)