import { PageID } from "codes/page";
import { UserRole } from "codes/user";
import LoadingScreen from "components/LoadingScreen";
import { AppContextProvider } from "contexts/AppContext";
import useAuth from "hooks/useAuth";
import DashboardLayout from "layouts/dashbord";
import SimpleLayout from "layouts/simple";
import { ElementType, Suspense, lazy, useMemo } from "react";
import { RouteObject, useRoutes } from "react-router-dom";
import { getRoute } from "./path";
const Loadable = (Component: ElementType) => (props: any) => {
return (
}>
);
};
const AuthRoutes = (): RouteObject => ({
element: ,
children: [
{
path: getRoute(PageID.LOGIN),
element: ,
},
{
path: getRoute(PageID.LOGOUT),
element: ,
},
],
});
const AppRoutes = (): RouteObject => ({
element: (
),
children: [
{
path: getRoute(PageID.APP_RECEIPT_ISSUING_ORDER_INDEX),
element: ,
},
],
});
const DashboardRoutes = (): RouteObject => {
const { canAccess } = useAuth();
const allChildren = [
{
pageId: PageID.DASHBOARD_OVERVIEW,
element: ,
target: UserRole.NORMAL_ADMIN,
},
{
pageId: PageID.DASHBOARD_CONTRACT_LIST,
element: ,
target: UserRole.SUPER_ADMIN,
},
{
pageId: PageID.DASHBOARD_CONTRACT_DETAIL,
element: ,
target: UserRole.SUPER_ADMIN,
},
{
pageId: PageID.DASHBOARD_RECEIPT_ISSUING_ORDER_CREATE,
element: ,
target: UserRole.NORMAL_ADMIN,
},
{
pageId: PageID.DASHBOARD_RECEIPT_ISSUING_ORDER_LIST,
element: ,
target: UserRole.NORMAL_ADMIN,
},
];
const children: RouteObject[] = useMemo(() => {
return allChildren
.filter(({ pageId }) => canAccess(pageId))
.map(({ pageId, ...others }) => ({
...others,
path: getRoute(pageId),
}));
}, [canAccess]);
return {
element: ,
children,
};
};
export function Routes() {
const { initialized } = useAuth();
return useRoutes([
AuthRoutes(),
AppRoutes(),
DashboardRoutes(),
{
path: "403",
element: ,
},
{
path: "*",
element: initialized ? : ,
},
]);
}
// 認証関連 -------------------------------
const Login = Loadable(lazy(() => import("pages/auth/login")));
const Logout = Loadable(lazy(() => import("pages/auth/logout")));
// App ---------------------------
const ReceiptIssuingOrder = Loadable(
lazy(() => import("pages/app/ReceiptIssuingOrder"))
);
//ダッシュボード ----------------------------
const Dashboard = Loadable(lazy(() => import("pages/dashboard")));
// 契約関連
const ContractList = Loadable(
lazy(() => import("pages/dashboard/contract/list"))
);
const ContractDetail = Loadable(
lazy(() => import("pages/dashboard/contract/detail"))
);
// 領収証発行依頼
const ReceiptIssuingOrderCreate = Loadable(
lazy(() => import("pages/dashboard/receipt-issuing-order/create"))
);
const ReceiptIssuingOrderList = Loadable(
lazy(() => import("pages/dashboard/receipt-issuing-order/list"))
);
// その他 ---------------------------------
const Page403 = Loadable(lazy(() => import("pages/common/Page403")));
const Page404 = Loadable(lazy(() => import("pages/common/Page404")));