Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

186 Zeilen
4.8KB

  1. import { PageID } from "codes/page";
  2. import { UserRole } from "codes/user";
  3. import LoadingScreen from "components/LoadingScreen";
  4. import { AppContextProvider } from "contexts/AppContext";
  5. import useAuth from "hooks/useAuth";
  6. import DashboardLayout from "layouts/dashbord";
  7. import SimpleLayout from "layouts/simple";
  8. import { ElementType, Suspense, lazy, useMemo } from "react";
  9. import { RouteObject, useRoutes } from "react-router-dom";
  10. import { getRoute } from "./path";
  11. const Loadable = (Component: ElementType) => (props: any) => {
  12. return (
  13. <Suspense fallback={<LoadingScreen />}>
  14. <Component {...props} />
  15. </Suspense>
  16. );
  17. };
  18. const AuthRoutes = (): RouteObject => ({
  19. element: <SimpleLayout />,
  20. children: [
  21. {
  22. path: getRoute(PageID.LOGIN),
  23. element: <Login />,
  24. },
  25. {
  26. path: getRoute(PageID.LOGOUT),
  27. element: <Logout />,
  28. },
  29. ],
  30. });
  31. const AppRoutes = (): RouteObject => ({
  32. element: (
  33. <AppContextProvider>
  34. <SimpleLayout />
  35. </AppContextProvider>
  36. ),
  37. children: [
  38. {
  39. path: getRoute(PageID.APP_RECEIPT_ISSUING_ORDER_INDEX),
  40. element: <ReceiptIssuingOrder />,
  41. },
  42. {
  43. path: getRoute(PageID.APP_RECEIPT_ISSUING_ORDER_MAIL_ORDER),
  44. element: <MailOrder />,
  45. },
  46. ],
  47. });
  48. const DashboardRoutes = (): RouteObject => {
  49. const { canAccess } = useAuth();
  50. const allChildren = [
  51. {
  52. pageId: PageID.DASHBOARD_OVERVIEW,
  53. element: <Dashboard />,
  54. },
  55. {
  56. pageId: PageID.DASHBOARD_CONTRACT_LIST,
  57. element: <ContractList />,
  58. },
  59. {
  60. pageId: PageID.DASHBOARD_CONTRACT_DETAIL,
  61. element: <ContractDetail />,
  62. },
  63. {
  64. pageId: PageID.DASHBOARD_CONTRACT_CREATE,
  65. element: <ContractCreate />,
  66. },
  67. {
  68. pageId: PageID.DASHBOARD_RECEIPT_ISSUING_ORDER_CREATE_CUSTOM_HELLO_TECHNO,
  69. element: <ReceiptIssuingOrderCreateHelloTechno />,
  70. },
  71. {
  72. pageId: PageID.DASHBOARD_RECEIPT_ISSUING_ORDER_LIST_CUSTOM_HELLO_TECHNO,
  73. element: <ReceiptIssuingOrderListHelloTechno />,
  74. },
  75. {
  76. pageId: PageID.DASHBOARD_RECEIPT_ISSUING_ORDER_DETAIL_CUSTOM_HELLO_TECHNO,
  77. element: <ReceiptIssuingOrderDetailHelloTechno />,
  78. },
  79. {
  80. pageId: PageID.DASHBOARD_LOGIN_USER_LIST,
  81. element: <LoginUserList />,
  82. },
  83. {
  84. pageId: PageID.DASHBOARD_LOGIN_USER_CREATE,
  85. element: <LoginUserCreate />,
  86. },
  87. {
  88. pageId: PageID.DASHBOARD_LOGIN_USER_CHANGE_PASSWORD,
  89. element: <ChangePassword />,
  90. },
  91. ];
  92. const children: RouteObject[] = useMemo(() => {
  93. return allChildren
  94. .filter(({ pageId }) => canAccess(pageId))
  95. .map(({ pageId, ...others }) => ({
  96. ...others,
  97. path: getRoute(pageId),
  98. }));
  99. }, [canAccess]);
  100. return {
  101. element: <DashboardLayout />,
  102. children,
  103. };
  104. };
  105. export function Routes() {
  106. const { initialized } = useAuth();
  107. return useRoutes([
  108. AuthRoutes(),
  109. AppRoutes(),
  110. DashboardRoutes(),
  111. {
  112. path: "403",
  113. element: <Page403 />,
  114. },
  115. {
  116. path: "*",
  117. element: initialized ? <Page404 /> : <LoadingScreen />,
  118. },
  119. ]);
  120. }
  121. // 認証関連 -------------------------------
  122. const Login = Loadable(lazy(() => import("pages/auth/login")));
  123. const Logout = Loadable(lazy(() => import("pages/auth/logout")));
  124. // App ---------------------------
  125. const ReceiptIssuingOrder = Loadable(
  126. lazy(() => import("pages/app/ReceiptIssuingOrder"))
  127. );
  128. const MailOrder = Loadable(lazy(() => import("pages/app/MailOrder")));
  129. //ダッシュボード ----------------------------
  130. const Dashboard = Loadable(lazy(() => import("pages/dashboard")));
  131. // 契約関連
  132. const ContractList = Loadable(
  133. lazy(() => import("pages/dashboard/contract/list"))
  134. );
  135. const ContractDetail = Loadable(
  136. lazy(() => import("pages/dashboard/contract/detail"))
  137. );
  138. const ContractCreate = Loadable(
  139. lazy(() => import("pages/dashboard/contract/create"))
  140. );
  141. // 領収証発行依頼
  142. const ReceiptIssuingOrderCreateHelloTechno = Loadable(
  143. lazy(
  144. () =>
  145. import("pages/dashboard/receipt-issuing-order/custom/hello-techno/create")
  146. )
  147. );
  148. const ReceiptIssuingOrderListHelloTechno = Loadable(
  149. lazy(
  150. () =>
  151. import("pages/dashboard/receipt-issuing-order/custom/hello-techno/list")
  152. )
  153. );
  154. const ReceiptIssuingOrderDetailHelloTechno = Loadable(
  155. lazy(
  156. () =>
  157. import("pages/dashboard/receipt-issuing-order/custom/hello-techno/detail")
  158. )
  159. );
  160. // ログインユーザー管理
  161. const LoginUserList = Loadable(
  162. lazy(() => import("pages/dashboard/login-user/list"))
  163. );
  164. const LoginUserCreate = Loadable(
  165. lazy(() => import("pages/dashboard/login-user/create"))
  166. );
  167. const ChangePassword = Loadable(
  168. lazy(() => import("pages/dashboard/login-user/change-password"))
  169. );
  170. // その他 ---------------------------------
  171. const Page403 = Loadable(lazy(() => import("pages/common/Page403")));
  172. const Page404 = Loadable(lazy(() => import("pages/common/Page404")));