123 lines
4.0 KiB
TypeScript
123 lines
4.0 KiB
TypeScript
import { TCrudRoute, TMenuItem } from "./types/App";
|
|
import { FaHome, FaMoneyBill } from "react-icons/fa";
|
|
import React from "react";
|
|
const Dummy = React.lazy(() => import("./Pages/Home/Dummy"));
|
|
|
|
const Subject = React.lazy(() => import("./Pages/subject/Table/Page"));
|
|
|
|
const Tags = React.lazy(() => import("./Pages/Tags/Page"));
|
|
|
|
const Unit = React.lazy(() => import("./Pages/Unit/Page"));
|
|
const Lesson = React.lazy(() => import("./Pages/lesson/Page"));
|
|
const Question = React.lazy(() => import("./Pages/question/Page"));
|
|
const AddQuestionPage = React.lazy(() => import("./Pages/question/AddPage"));
|
|
const EditQuestionPage = React.lazy(() => import("./Pages/question/EditPage"));
|
|
|
|
import { hasAbility } from "./utils/hasAbility";
|
|
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "./enums/abilities";
|
|
import { ParamsEnum } from "./enums/params";
|
|
|
|
export const menuItems: TMenuItem[] = [
|
|
{
|
|
header: "page_header.dashboard",
|
|
element: <Dummy />,
|
|
icon: <FaHome />,
|
|
text: "sidebar.dashboard",
|
|
path: "/",
|
|
abilities: ABILITIES_ENUM?.PASS,
|
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
|
prevPath: 0,
|
|
},
|
|
|
|
{
|
|
header: "page_header.subject",
|
|
element: <Subject />,
|
|
icon: <FaMoneyBill />,
|
|
text: "sidebar.subject",
|
|
path: `/${ABILITIES_ENUM?.SUBJECT}`,
|
|
abilities: ABILITIES_ENUM?.SUBJECT,
|
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
|
prevPath: 0,
|
|
},
|
|
{
|
|
header: "page_header.tags",
|
|
element: <Tags />,
|
|
icon: <FaMoneyBill />,
|
|
text: "sidebar.tags",
|
|
path: `/${ABILITIES_ENUM?.TAG}`,
|
|
abilities: ABILITIES_ENUM?.TAG,
|
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
|
prevPath: 0,
|
|
},
|
|
];
|
|
|
|
export const CrudRoute: TCrudRoute[] = [
|
|
{
|
|
header: "page_header.subject_details",
|
|
element: <Unit />,
|
|
path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}`,
|
|
abilities: ABILITIES_ENUM?.UNIT,
|
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
|
prevPath: 1,
|
|
},
|
|
{
|
|
header: "page_header.unit_details",
|
|
element: <Lesson />,
|
|
path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}`,
|
|
abilities: ABILITIES_ENUM?.LESSON,
|
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
|
prevPath: 2,
|
|
},
|
|
|
|
{
|
|
header: "page_header.lesson_details",
|
|
element: <Question />,
|
|
path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}`,
|
|
abilities: ABILITIES_ENUM?.QUESTION,
|
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
|
prevPath: 2,
|
|
},
|
|
{
|
|
header: "page_header.add_Question",
|
|
element: <AddQuestionPage />,
|
|
path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/add`,
|
|
abilities: ABILITIES_ENUM?.QUESTION,
|
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
|
prevPath: 2,
|
|
},
|
|
{
|
|
header: "page_header.edit_Question",
|
|
element: <EditQuestionPage />,
|
|
path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/:${ParamsEnum?.QUESTION_ID}`,
|
|
abilities: ABILITIES_ENUM?.QUESTION,
|
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
|
prevPath: 2,
|
|
},
|
|
];
|
|
|
|
export const AppRoutes: Record<string, string> = Object.fromEntries(
|
|
menuItems.map((route) => [
|
|
route.path,
|
|
route.header ? route.header : route.text,
|
|
]),
|
|
);
|
|
|
|
export const CrudRoutes: any = Object.fromEntries(
|
|
CrudRoute.map((route) => [route?.path, route?.header]),
|
|
);
|
|
export const search_array: { label: string; value: string }[] = menuItems
|
|
?.filter((item: TMenuItem) => {
|
|
return hasAbility(item.abilities, item.abilities_value);
|
|
})
|
|
.map((item: TMenuItem) => ({
|
|
label: item.header as string,
|
|
value: item.path as string,
|
|
}));
|
|
|
|
const AllRoute = [...menuItems, ...CrudRoute];
|
|
|
|
export const PrevRoutes: any = AllRoute.map((route) => ({
|
|
path: route.path,
|
|
prevPath: route.prevPath,
|
|
}));
|