2026-03-17 07:31:09 +00:00
|
|
|
import { Suspense, lazy } from "react";
|
2026-03-02 11:59:47 +00:00
|
|
|
import { Navigate, Route, Routes } from "react-router-dom";
|
2026-03-17 07:31:09 +00:00
|
|
|
import AppLayout from "@/layouts/AppLayout";
|
|
|
|
|
import { useAuth } from "@/hooks/useAuth";
|
|
|
|
|
import { menuRoutes,extraRoutes } from "./routes";
|
|
|
|
|
|
|
|
|
|
const Login = lazy(() => import("@/pages/auth/login"));
|
|
|
|
|
const ResetPassword = lazy(() => import("@/pages/auth/reset-password"));
|
|
|
|
|
|
|
|
|
|
function RouteFallback() {
|
|
|
|
|
return <div className="app-page__empty-state" style={{ minHeight: 320 }}>Loading...</div>;
|
|
|
|
|
}
|
2026-02-10 09:48:44 +00:00
|
|
|
|
|
|
|
|
function RequireAuth({ children }: { children: JSX.Element }) {
|
2026-02-26 10:10:14 +00:00
|
|
|
const { isAuthed, profile } = useAuth();
|
2026-03-17 07:31:09 +00:00
|
|
|
|
2026-02-10 09:48:44 +00:00
|
|
|
if (!isAuthed) {
|
|
|
|
|
return <Navigate to="/login" replace />;
|
|
|
|
|
}
|
2026-03-17 07:31:09 +00:00
|
|
|
|
2026-02-26 10:10:14 +00:00
|
|
|
if (profile?.pwdResetRequired === 1) {
|
|
|
|
|
return <Navigate to="/reset-password" replace />;
|
|
|
|
|
}
|
2026-03-17 07:31:09 +00:00
|
|
|
|
2026-02-10 09:48:44 +00:00
|
|
|
return children;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function AppRoutes() {
|
|
|
|
|
return (
|
2026-03-17 07:31:09 +00:00
|
|
|
<Suspense fallback={<RouteFallback />}>
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path="/login" element={<Login />} />
|
|
|
|
|
<Route path="/reset-password" element={<ResetPassword />} />
|
|
|
|
|
<Route
|
|
|
|
|
path="/"
|
|
|
|
|
element={
|
|
|
|
|
<RequireAuth>
|
|
|
|
|
<AppLayout />
|
|
|
|
|
</RequireAuth>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{menuRoutes.map((route) => (
|
|
|
|
|
<Route key={route.path} index={route.path === "/"} path={route.path === "/" ? undefined : route.path.slice(1)} element={route.element} />
|
|
|
|
|
))}
|
|
|
|
|
{extraRoutes && extraRoutes.map((route) => (
|
|
|
|
|
<Route key={route.path} path={route.path.startsWith('/') ? route.path.slice(1) : route.path} element={route.element} />
|
|
|
|
|
))}
|
|
|
|
|
</Route>
|
|
|
|
|
<Route path="*" element={<Navigate to="/" replace />} />
|
|
|
|
|
</Routes>
|
|
|
|
|
</Suspense>
|
2026-02-10 09:48:44 +00:00
|
|
|
);
|
|
|
|
|
}
|