Files
CoHaiSe/frontend/crm/src/App.tsx
T
Esiah 09cf07d79b feat: migrate showcase to Next.js and overhaul CRM UI
- rebuild the public site on the Next.js App Router with static export,
  per-section SEO pages, metadata, sitemap, robots and a generated OG image
- add full-screen scroll-snap regions, staged scroll reveals, a hash-free
  tab navigation with a sliding indicator and region-by-region menu scrolling
- replace the theme text toggle with animated sun/moon icons
- restructure the CRM API into config, middleware, models, routes, services
  and utils layers
- redesign the CRM shell with a single surface, tab rail, full-width blurred
  DataTable, record dialogs and mask-based icons
- update Docker/Nginx publishing, Makefile targets, shared UI polish and docs
2026-11-16 00:52:29 +01:00

64 lines
1.8 KiB
TypeScript

import { useCallback, useEffect, useState } from "react";
import { Spinner } from "@cohaise/ui";
import { ApiError, api, type User } from "./lib/api.js";
import { FaultyTerminalBackdrop } from "./components/FaultyTerminalBackdrop.js";
import { Login } from "./pages/Login.js";
import { ChangePassword } from "./pages/ChangePassword.js";
import { Crm } from "./pages/Crm.js";
type Session =
| { state: "loading" }
| { state: "guest" }
| { state: "ready"; user: User };
export const App = () => {
const [session, setSession] = useState<Session>({ state: "loading" });
const refresh = useCallback(async () => {
try {
const { user } = await api.me();
setSession({ state: "ready", user });
} catch (error) {
// 401 = simplement deconnecte, ce n'est pas une panne.
if (error instanceof ApiError && error.status === 401) setSession({ state: "guest" });
else setSession({ state: "guest" });
}
}, []);
useEffect(() => {
void refresh();
}, [refresh]);
const logout = useCallback(async () => {
await api.logout().catch(() => undefined);
setSession({ state: "guest" });
}, []);
if (session.state === "loading") {
return (
<div className="relative flex min-h-dvh items-center justify-center bg-background">
<FaultyTerminalBackdrop />
<div className="relative z-10">
<Spinner size="md" />
</div>
</div>
);
}
if (session.state === "guest") {
return <Login onAuthenticated={(user) => setSession({ state: "ready", user })} />;
}
if (session.user.must_change_password) {
return (
<ChangePassword
user={session.user}
onCompleted={refresh}
onLogout={() => void logout()}
/>
);
}
return <Crm user={session.user} onLogout={() => void logout()} />;
};