Quiz_dashboard/src/Routes.tsx
2024-11-12 14:10:49 +03:00

491 lines
16 KiB
TypeScript

import { TCrudRoute, TMenuItem } from "./types/App";
import { FaCashRegister, FaCity, FaHome, FaMonero, FaMoneyBill, FaPaperclip, FaSellcast, FaTag, FaUser, FaUserShield } from "react-icons/fa";
import { GoDotFill } from "react-icons/go";
import { MdOutlineSell } from "react-icons/md";
import { CgProfile } from "react-icons/cg";
import { GrGroup } from "react-icons/gr";
import React from "react";
const Dummy = React.lazy(() => import("./Pages/Home/Dummy"));
const Grade = React.lazy(() => import("./Pages/Admin/Grade/Page"));
const City = React.lazy(() => import("./Pages/Admin/City/Page"));
const Area = React.lazy(() => import("./Pages/Admin/Area/Page"));
const Subject = React.lazy(() => import("./Pages/Admin/subject/Table/Page"));
const Tags = React.lazy(() => import("./Pages/Admin/Tags/Page"));
const Unit = React.lazy(() => import("./Pages/Admin/Unit/Page"));
const Lesson = React.lazy(() => import("./Pages/Admin/lesson/Page"));
const Question = React.lazy(() => import("./Pages/Admin/question/Page"));
const AddQuestionPage = React.lazy(
() => import("./Pages/Admin/question/AddPage"),
);
const EditQuestionPage = React.lazy(
() => import("./Pages/Admin/question/EditPage"),
);
const Student = React.lazy(() => import("./Pages/Admin/Student/Page"));
const ShowStudent = React.lazy(() => import("./Pages/Admin/Student/show/Page"));
const Manager = React.lazy(() => import("./Pages/Admin/Manager/Page"));
const AddManager = React.lazy(() => import("./Pages/Admin/Manager/Add/Page"));
const EditManager = React.lazy(() => import("./Pages/Admin/Manager/Edit/Page"));
const FinancialCollection = React.lazy(() => import("./Pages/Admin/FinancialCollection/Page"));
const ReSeller = React.lazy(() => import("./Pages/Admin/Reseller/Page"));
const ShowReSeller = React.lazy(() => import("./Pages/Admin/Reseller/show/Page"));
const AddReSeller = React.lazy(() => import("./Pages/Admin/Reseller/Add/Page"));
const EditReSeller = React.lazy(() => import("./Pages/Admin/Reseller/Edit/Page"),);
const User = React.lazy(() => import("./Pages/Admin/User/Page"));
const QuestionBank = React.lazy(() => import("./Pages/Admin/QuestionBank/Page"));
const AllNotifications = React.lazy(() => import("./Pages/Admin/Notifications/Page"));
const Notifications = React.lazy(() => import("./Pages/Admin/Notifications/AddNotification/Page"));
const AddNotification = React.lazy(() => import("./Pages/Admin/Notifications/AddNotification/Add/Page"));
const Profile = React.lazy(() => import("./Pages/Admin/Profile/Page"));
const Setting = React.lazy(() => import("./Pages/Admin/Setting/Page"));
const Permissions = React.lazy(() => import("./Pages/Admin/Roles/Permissions/Page"));
const Roles = React.lazy(() => import("./Pages/Admin/Roles/Page"));
const Coupon = React.lazy(() => import("./Pages/Admin/Coupon/Page"));
const Report = React.lazy(() => import("./Pages/Admin/Report/Page"));
const ShowReport = React.lazy(() => import("./Pages/Admin/Report/Show/Page"));
const Param = React.lazy(() => import("./Pages/Admin/Param/Page"));
/// RESELLER ///
const Sales = React.lazy(() => import("./Pages/ReSeller/Sales/Page"));
const Collections = React.lazy(() => import("./Pages/ReSeller/Collections/Page"));
const ShowCollection = React.lazy(() => import("./Pages/ReSeller/Collections/Show/Page"));
const NotificationReSeller = React.lazy(() => import("./Pages/ReSeller/Notifications/Page"));
const ProfileReSeller = React.lazy(() => import("./Pages/ReSeller/Profile/Page"));
import { hasAbility } from "./utils/hasAbility";
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "./enums/abilities";
import { ParamsEnum } from "./enums/params";
import { TbCategory } from "react-icons/tb";
import { UserTypeEnum } from "./enums/UserType";
import { FaTags } from "react-icons/fa6";
import { CiSquareQuestion } from "react-icons/ci";
import { IoNotifications } from "react-icons/io5";
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,
type: UserTypeEnum?.PASS,
prevPath: 0,
},
{
header: "page_header.grade",
element: <Grade />,
icon: <TbCategory />,
text: "sidebar.grade",
path: `/${ABILITIES_ENUM?.GRADE}`,
abilities: ABILITIES_ENUM?.GRADE,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.user",
element: <User />,
icon: <FaUser />,
text: "sidebar.users",
path: `/${ABILITIES_ENUM?.USER}`,
abilities: ABILITIES_ENUM?.USER,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
children: [
{
header: "page_header.student",
element: <Student />,
icon: <GoDotFill className="transparent_bg" />,
text: "sidebar.student",
path: `/${ABILITIES_ENUM?.STUDENT}`,
abilities: ABILITIES_ENUM?.STUDENT,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.managers",
element: <Manager />,
icon: <GoDotFill className="transparent_bg" />,
text: "sidebar.managers",
path: `/${ABILITIES_ENUM?.MANAGERS}`,
abilities: ABILITIES_ENUM?.MANAGERS,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
]
},
{
header: "page_header.tags",
element: <Tags />,
icon: <FaTags />,
text: "sidebar.tags",
path: `/${ABILITIES_ENUM?.TAG}`,
abilities: ABILITIES_ENUM?.TAG,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.reSeller",
element: <ReSeller />,
icon: <FaCashRegister />,
text: "sidebar.reseller",
path: `/${ABILITIES_ENUM?.RE_SELLER}`,
abilities: ABILITIES_ENUM?.RE_SELLER,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.city",
element: <City />,
icon: <FaCity />,
text: "sidebar.city",
path: `/${ABILITIES_ENUM?.CITY}`,
abilities: ABILITIES_ENUM?.CITY,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.report",
element: <Report />,
icon: <FaPaperclip />,
text: "sidebar.report",
path: `/${ABILITIES_ENUM?.Report}` ,
abilities: ABILITIES_ENUM?.Report,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.add_notification",
element: <Notifications />,
icon: <IoNotifications />,
text: "sidebar.notification",
path: `/add_${ABILITIES_ENUM?.NOTIFICATIONS}`,
abilities: ABILITIES_ENUM?.NOTIFICATIONS,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
// {
// header: "page_header.param",
// element: <Param />,
// icon: <FaSellcast />,
// text: "sidebar.param",
// path: `/${ABILITIES_ENUM?.PARAM}`,
// abilities: ABILITIES_ENUM?.PARAM,
// abilities_value: ABILITIES_VALUES_ENUM.INDEX,
// prevPath: 0,
// },
{
header: "page_header.questionBank",
element: <QuestionBank />,
icon: <CiSquareQuestion />,
text: "sidebar.questionBank",
path: `/${ABILITIES_ENUM?.QUESTION}`,
abilities: ABILITIES_ENUM?.QUESTION,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.roles",
element: <Roles />,
icon: <FaUserShield />,
text: "sidebar.role",
path: `/${ABILITIES_ENUM?.ROLE}`,
abilities: ABILITIES_ENUM?.ROLE,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.coupon",
element: <Coupon />,
icon: <FaMoneyBill />,
text: "sidebar.coupon",
path: `/${ABILITIES_ENUM?.COUPON}`,
abilities: ABILITIES_ENUM?.COUPON,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.financial_collection",
element: <FinancialCollection />,
icon: <FaMoneyBill />,
text: "sidebar.financial_collection",
path: `/${ABILITIES_ENUM?.Financial_Collection}`,
abilities: ABILITIES_ENUM?.Financial_Collection,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
/// RESELLER /////
{
header: "page_header.sales",
element: <Sales />,
icon: <MdOutlineSell />,
text: "sidebar.sales",
path: `/${ABILITIES_ENUM?.Sales}`,
abilities: ABILITIES_ENUM?.Sales,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
type: UserTypeEnum.RE_SELLER,
},
{
header: "page_header.collections",
element: <Collections />,
icon: <FaMoneyBill />,
text: "sidebar.collections",
path: `/${ABILITIES_ENUM?.Collections}`,
abilities: ABILITIES_ENUM?.Collections,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
type: UserTypeEnum.RE_SELLER,
},
// {
// header: "page_header.profile",
// element: <ProfileReSeller />,
// icon: <CgProfile />,
// text: "sidebar.profile",
// path: `/${ABILITIES_ENUM?.PROFILE}`,
// abilities: ABILITIES_ENUM?.Profile_RE_SELLER,
// abilities_value: ABILITIES_VALUES_ENUM.INDEX,
// prevPath: 0,
// type: UserTypeEnum.RE_SELLER,
// },
];
export const CrudRoute: TCrudRoute[] = [
{
header: "page_header.Subject",
element: <Subject />,
path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}`,
abilities: ABILITIES_ENUM?.SUBJECT,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 1,
},
{
header: "page_header.unit",
element: <Unit />,
path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}`,
abilities: ABILITIES_ENUM?.UNIT,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 2,
},
{
header: "page_header.lesson",
element: <Lesson />,
path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${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.question",
element: <Question />,
path: `/${ABILITIES_ENUM?.GRADE}/:${ParamsEnum?.GRADE_ID}/${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?.GRADE}/:${ParamsEnum?.GRADE_ID}/${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?.GRADE}/:${ParamsEnum?.GRADE_ID}/${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,
},
{
header: "page_header.add_reseller",
element: <AddReSeller />,
path: `/${ABILITIES_ENUM?.RE_SELLER}/add`,
abilities: ABILITIES_ENUM?.RE_SELLER,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.edit_reseller",
element: <EditReSeller />,
path: `/${ABILITIES_ENUM?.RE_SELLER}/:${ParamsEnum?.RE_SELLER_ID}/edit`,
abilities: ABILITIES_ENUM?.RE_SELLER,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.reSeller",
element: <ShowReSeller />,
path: `/${ABILITIES_ENUM?.RE_SELLER}/:${ParamsEnum?.RE_SELLER_ID}`,
abilities: ABILITIES_ENUM?.RE_SELLER,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.student",
element: <ShowStudent />,
path: `/${ABILITIES_ENUM?.STUDENT}/:${ParamsEnum?.STUDENT_ID}`,
abilities: ABILITIES_ENUM?.STUDENT,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.profile",
element: <Profile />,
path: `/${ABILITIES_ENUM?.PROFILE}`,
abilities: ABILITIES_ENUM?.PROFILE,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.permissions",
element: <Permissions />,
path: `/${ABILITIES_ENUM?.ROLE}/:${ParamsEnum?.ROLE_ID}/${ABILITIES_ENUM?.PERMISSIONS}`,
abilities: ABILITIES_ENUM?.ROLE,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.notifications",
element: <AllNotifications />,
path: `/${ABILITIES_ENUM?.NOTIFICATIONS}`,
abilities: ABILITIES_ENUM?.NOTIFICATIONS,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.add_manager",
element: <AddManager />,
path: `/${ABILITIES_ENUM?.MANAGERS}/add`,
abilities: ABILITIES_ENUM?.MANAGERS,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
{
header: "page_header.edit_manager",
element: <EditManager />,
path: `/${ABILITIES_ENUM?.MANAGERS}/:${ParamsEnum?.Manager_ID}/edit`,
abilities: ABILITIES_ENUM?.MANAGERS,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
// {
// header: "page_header.setting",
// element: <Setting />,
// path: `/${ABILITIES_ENUM?.SETTING}`,
// abilities: ABILITIES_ENUM?.SETTING,
// abilities_value: ABILITIES_VALUES_ENUM.INDEX,
// prevPath: 0,
// },
{
header: "page_header.add_notification",
element: <AddNotification />,
path: `/${ABILITIES_ENUM?.NOTIFICATIONS}/add`,
abilities: ABILITIES_ENUM?.NOTIFICATIONS,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
//// RE_SELLER
{
header: "page_header.notifications",
element: <NotificationReSeller />,
path: `/${ABILITIES_ENUM?.NOTIFICATIONS}`,
abilities: ABILITIES_ENUM?.NOTIFICATIONS_RE_SELLER,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
type: UserTypeEnum.RE_SELLER,
},
{
header: "page_header.Area",
element: <Area />,
path: `/${ABILITIES_ENUM?.CITY}/:${ParamsEnum?.CITY_ID}`,
abilities: ABILITIES_ENUM?.AREA,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 1,
},
{
header: "page_header.collection",
element: <ShowCollection />,
path: `/${ABILITIES_ENUM?.Collections}/:${ParamsEnum?.Collection_ID}`,
abilities: ABILITIES_ENUM?.Collections,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
type:UserTypeEnum.RE_SELLER
},
{
header: "page_header.report",
element: <ShowReport />,
path: `/${ABILITIES_ENUM?.Report}/:${ParamsEnum?.REPORT_ID}/:${ParamsEnum?.QUESTION_ID}`,
abilities: ABILITIES_ENUM?.Report,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
// report based on question id
{
header: "page_header.report",
element: <Report />,
path: `/${ABILITIES_ENUM?.Report}/${ParamsEnum?.QUESTION_ID}` ,
abilities: ABILITIES_ENUM?.Report,
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
prevPath: 0,
},
];
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; type: 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,
type: item.type ? item.type : "admin",
}))
const AllRoute = [...menuItems, ...CrudRoute];
export const PrevRoutes: any = AllRoute.map((route) => ({
path: route.path,
prevPath: route.prevPath,
}));