Compare commits
5 Commits
9530ea30e7
...
f5e0bebeb0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5e0bebeb0 | ||
|
|
4b9a4f4d23 | ||
|
|
2c77beab03 | ||
|
|
fe6ccaaee0 | ||
|
|
d721b8417c |
1
.vscode/settings.json
vendored
|
|
@ -18,6 +18,7 @@
|
||||||
"tagcontainer",
|
"tagcontainer",
|
||||||
"toastify",
|
"toastify",
|
||||||
"Viewelement",
|
"Viewelement",
|
||||||
|
"webp",
|
||||||
"zustand",
|
"zustand",
|
||||||
"مطلوب"
|
"مطلوب"
|
||||||
],
|
],
|
||||||
|
|
|
||||||
BIN
public/App/BackgroundHeader.webp
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
public/App/SyriaLogo.webp
Normal file
|
After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 962 B |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 619 KiB |
|
|
@ -1,5 +0,0 @@
|
||||||
<svg viewBox="0 0 377 446" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<ellipse opacity="0.1" cx="293" cy="326.206" rx="293" ry="326.206" fill="white" fill-opacity="0.66"/>
|
|
||||||
<ellipse opacity="0.1" cx="293" cy="326.207" rx="181.81" ry="202.415" fill="white" fill-opacity="0.66"/>
|
|
||||||
<ellipse opacity="0.1" cx="292.999" cy="326.206" rx="94.6615" ry="105.39" fill="white" fill-opacity="0.66"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 399 B |
|
Before Width: | Height: | Size: 8.9 KiB |
BIN
public/Layout/BackgroundHeader.webp
Normal file
|
After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 307 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 311 KiB |
|
Before Width: | Height: | Size: 665 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
|
|
@ -1,18 +0,0 @@
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1082" height="138" viewBox="0 0 1082 138">
|
|
||||||
<defs>
|
|
||||||
<clipPath id="clip-path">
|
|
||||||
<rect id="Rectangle_1" data-name="Rectangle 1" width="1082" height="138" transform="translate(419 362)" fill="#fff"/>
|
|
||||||
</clipPath>
|
|
||||||
</defs>
|
|
||||||
<g id="Mask_Group_1" data-name="Mask Group 1" transform="translate(-419 -362)" clip-path="url(#clip-path)">
|
|
||||||
<g id="cover" transform="translate(369 332)">
|
|
||||||
<g id="Group_1" data-name="Group 1">
|
|
||||||
<path id="Path_1" data-name="Path 1" d="M50,50A20,20,0,0,1,70,30H1112a20,20,0,0,1,20,20V170H50Z" fill="#3182ce"/>
|
|
||||||
</g>
|
|
||||||
<g id="Group_2" data-name="Group 2">
|
|
||||||
<rect id="Rectangle_1-2" data-name="Rectangle 1" width="280.439" height="275.13" rx="20" transform="translate(230.408 111.564)" fill="#fb7d5b"/>
|
|
||||||
<rect id="Rectangle_2" data-name="Rectangle 2" width="280.439" height="275.13" rx="20" transform="translate(92 61)" fill="#fcc43e"/>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.0 KiB |
|
|
@ -8,7 +8,6 @@ import { useChangeLanguage } from "./Hooks/useChangeLanguage";
|
||||||
import useAuthState from "./zustand/AuthState";
|
import useAuthState from "./zustand/AuthState";
|
||||||
import { TMenuItem } from "./types/App";
|
import { TMenuItem } from "./types/App";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useSetPage_title from "./Hooks/useSetPageTitle";
|
|
||||||
import SpinContainer from "./Components/Layout/SpinContainer";
|
import SpinContainer from "./Components/Layout/SpinContainer";
|
||||||
|
|
||||||
const Page404 = lazy(() => import("./Layout/Ui/NotFoundPage"));
|
const Page404 = lazy(() => import("./Layout/Ui/NotFoundPage"));
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,14 @@ const HeaderSection = () => {
|
||||||
);
|
);
|
||||||
const [, setActiveButton] = useState(0);
|
const [, setActiveButton] = useState(0);
|
||||||
const { setActiveTab, ActiveTab } = useButtonState((state) => state);
|
const { setActiveTab, ActiveTab } = useButtonState((state) => state);
|
||||||
const { set_param_to_send } = useObjectToEdit();
|
const { setParamToSend } = useObjectToEdit();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const handleButtonClick = (index: number) => {
|
const handleButtonClick = (index: number) => {
|
||||||
setActiveButton(index);
|
setActiveButton(index);
|
||||||
setActiveTab(index);
|
setActiveTab(index);
|
||||||
set_param_to_send({});
|
setParamToSend({});
|
||||||
navigate(`${location.pathname}`);
|
navigate(`${location.pathname}`);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,17 @@ import { DateEnum } from '../../../enums/Date';
|
||||||
|
|
||||||
const CustomDatePicker = () => {
|
const CustomDatePicker = () => {
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const { set_param_to_send, param_to_send } = useObjectToEdit();
|
const { setParamToSend, paramToSend } = useObjectToEdit();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const onChange: DatePickerProps["onChange"] = (date, dateString) => {
|
const onChange: DatePickerProps["onChange"] = (date, dateString) => {
|
||||||
// console.log(date, dateString);
|
// console.log(date, dateString);
|
||||||
const newObj = { ...param_to_send };
|
const newObj = { ...paramToSend };
|
||||||
newObj.date = dateString;
|
newObj.date = dateString;
|
||||||
set_param_to_send(newObj);
|
setParamToSend(newObj);
|
||||||
navigate(
|
navigate(
|
||||||
`${location.pathname}?${param_to_send?.state ?? "all"}=${dateString}`,
|
`${location.pathname}?${paramToSend?.state ?? "all"}=${dateString}`,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const Today = new Date() as any;
|
const Today = new Date() as any;
|
||||||
|
|
|
||||||
|
|
@ -8,19 +8,19 @@ import { QUESTION_OBJECT_KEY } from '../../config/AppKey';
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const { values, setFieldValue,setValues } = useFormikContext<any>();
|
const { values, setFieldValue,setValues } = useFormikContext<any>();
|
||||||
const {isBseQuestion,set_isBseQuestion} = useObjectToEdit()
|
const {isBseQuestion,setIsBseQuestion} = useObjectToEdit()
|
||||||
const {set_SavedQuestionData} = useObjectToEdit()
|
const {setSavedQuestionData} = useObjectToEdit()
|
||||||
const handleChange = () => {
|
const handleChange = () => {
|
||||||
set_SavedQuestionData(null)
|
setSavedQuestionData(null)
|
||||||
localStorage.removeItem(QUESTION_OBJECT_KEY)
|
localStorage.removeItem(QUESTION_OBJECT_KEY)
|
||||||
if (isBseQuestion) {
|
if (isBseQuestion) {
|
||||||
set_isBseQuestion(false)
|
setIsBseQuestion(false)
|
||||||
setValues(null)
|
setValues(null)
|
||||||
setFieldValue("isBase",0)
|
setFieldValue("isBase",0)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
set_isBseQuestion(true)
|
setIsBseQuestion(true)
|
||||||
setValues(null)
|
setValues(null)
|
||||||
setFieldValue("isBase",1)
|
setFieldValue("isBase",1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ const DeleteModels: React.FC<ModalFormProps> = ({
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
||||||
const { mutate, isLoading, isSuccess } = deleteMutation;
|
const { mutate, isLoading, isSuccess } = deleteMutation;
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
|
|
@ -33,14 +33,14 @@ const DeleteModels: React.FC<ModalFormProps> = ({
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
mutate({
|
mutate({
|
||||||
id: Number(object_to_edit?.id),
|
id: Number(objectToEdit?.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setInputValue("");
|
setInputValue("");
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
@ -48,7 +48,7 @@ const DeleteModels: React.FC<ModalFormProps> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
if (e.key === "Enter" && object_to_edit?.[objectValue] === inputValue) {
|
if (e.key === "Enter" && objectToEdit?.[objectValue] === inputValue) {
|
||||||
handleSubmit();
|
handleSubmit();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -71,7 +71,7 @@ const DeleteModels: React.FC<ModalFormProps> = ({
|
||||||
<div className="ValidationField w-100 mb-5">
|
<div className="ValidationField w-100 mb-5">
|
||||||
<label className="text ">
|
<label className="text ">
|
||||||
{t("practical.to_confirm_deletion_please_re_enter")}{" "}
|
{t("practical.to_confirm_deletion_please_re_enter")}{" "}
|
||||||
{t(`input.${objectValue}`)} ({object_to_edit?.[objectValue]})
|
{t(`input.${objectValue}`)} ({objectToEdit?.[objectValue]})
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
|
|
@ -88,11 +88,11 @@ const DeleteModels: React.FC<ModalFormProps> = ({
|
||||||
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
object_to_edit?.[objectValue] !== inputValue
|
objectToEdit?.[objectValue] !== inputValue
|
||||||
? "disabled_button"
|
? "disabled_button"
|
||||||
: ""
|
: ""
|
||||||
}
|
}
|
||||||
disabled={object_to_edit?.[objectValue] !== inputValue || isLoading}
|
disabled={objectToEdit?.[objectValue] !== inputValue || isLoading}
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ import { useUpdateAdmin } from "../../../api/users";
|
||||||
const ModalForm: React.FC = () => {
|
const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
const { mutate, isSuccess, isLoading } = useUpdateAdmin();
|
const { mutate, isSuccess, isLoading } = useUpdateAdmin();
|
||||||
const { set_object_to_edit } = useObjectToEdit();
|
const { setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
}
|
}
|
||||||
}, [setIsOpen, isSuccess]);
|
}, [setIsOpen, isSuccess]);
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ const ModalForm: React.FC = () => {
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ const FormField = ({ isLoading }: FormFieldType) => {
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
return (
|
return (
|
||||||
<Form className="AuthForm">
|
<Form className="AuthForm">
|
||||||
<Image src="../Layout/Logo.png" />
|
<Image src="../App/Logo.png" />
|
||||||
|
|
||||||
|
|
||||||
<div className="AuthInput">
|
<div className="AuthInput">
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ const Dummy = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="DammyHomePage">
|
<div className="DammyHomePage">
|
||||||
<Image src="/Layout/OLogo.png" />
|
<Image src="/App/SyriaLogo.webp" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ import ModelButtons from "../../../Components/models/ModelButtons";
|
||||||
const ModalForm: React.FC = () => {
|
const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
const { mutate, isSuccess, isLoading } = useAddTag();
|
const { mutate, isSuccess, isLoading } = useAddTag();
|
||||||
const { set_object_to_edit } = useObjectToEdit();
|
const { setObjectToEdit } = useObjectToEdit();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
setIsOpen("isSuccess");
|
setIsOpen("isSuccess");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
}
|
}
|
||||||
}, [setIsOpen, isSuccess]);
|
}, [setIsOpen, isSuccess]);
|
||||||
|
|
||||||
|
|
@ -31,7 +31,7 @@ const ModalForm: React.FC = () => {
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const ModalForm: React.FC = () => {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
||||||
const { mutate, isLoading, isSuccess } = useDeleteTag();
|
const { mutate, isLoading, isSuccess } = useDeleteTag();
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
|
|
@ -22,14 +22,14 @@ const ModalForm: React.FC = () => {
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
mutate({
|
mutate({
|
||||||
id: Number(object_to_edit?.id),
|
id: Number(objectToEdit?.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setInputValue("");
|
setInputValue("");
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
@ -49,7 +49,7 @@ const ModalForm: React.FC = () => {
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
{t("practical.delete")} ({object_to_edit?.name}){" "}
|
{t("practical.delete")} ({objectToEdit?.name}){" "}
|
||||||
</header>
|
</header>
|
||||||
<main className="main_modal">
|
<main className="main_modal">
|
||||||
<div className="ValidationField w-100 mb-5">
|
<div className="ValidationField w-100 mb-5">
|
||||||
|
|
@ -71,9 +71,9 @@ const ModalForm: React.FC = () => {
|
||||||
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
object_to_edit?.name !== inputValue ? "disabled_button" : ""
|
objectToEdit?.name !== inputValue ? "disabled_button" : ""
|
||||||
}
|
}
|
||||||
disabled={object_to_edit?.name !== inputValue || isLoading}
|
disabled={objectToEdit?.name !== inputValue || isLoading}
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
>
|
>
|
||||||
{t("practical.delete")}
|
{t("practical.delete")}
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ import ModelButtons from "../../../Components/models/ModelButtons";
|
||||||
|
|
||||||
const ModalForm: React.FC = () => {
|
const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit(
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit(
|
||||||
(state) => state,
|
(state) => state,
|
||||||
);
|
);
|
||||||
const { mutate, isSuccess, isLoading } = useUpdateTag();
|
const { mutate, isSuccess, isLoading } = useUpdateTag();
|
||||||
// console.log(object_to_edit,"object_to_edit");
|
// console.log(objectToEdit,"objectToEdit");
|
||||||
const handleSubmit = (values: any) => {
|
const handleSubmit = (values: any) => {
|
||||||
// const contactInformationJson = JSON.stringify({
|
// const contactInformationJson = JSON.stringify({
|
||||||
// phone_number: values?.number
|
// phone_number: values?.number
|
||||||
|
|
@ -27,7 +27,7 @@ const ModalForm: React.FC = () => {
|
||||||
};
|
};
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -45,10 +45,10 @@ const ModalForm: React.FC = () => {
|
||||||
open={isOpen === ModalEnum?.TAGS_EDIT}
|
open={isOpen === ModalEnum?.TAGS_EDIT}
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
>
|
>
|
||||||
{object_to_edit && (
|
{objectToEdit && (
|
||||||
<FormikForm
|
<FormikForm
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
initialValues={getInitialValues(object_to_edit)}
|
initialValues={getInitialValues(objectToEdit)}
|
||||||
validationSchema={getValidationSchema}
|
validationSchema={getValidationSchema}
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,10 @@ import { ModalEnum } from "../../enums/Model";
|
||||||
|
|
||||||
// import useSetPage_title from "../../Hooks/useSetPageTitle";
|
// import useSetPage_title from "../../Hooks/useSetPageTitle";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../../enums/abilities";
|
|
||||||
import { hasAbility } from "../../utils/hasAbility";
|
|
||||||
|
|
||||||
import { lazy, Suspense } from 'react';
|
import { lazy, Suspense } from 'react';
|
||||||
import { Spin } from "antd";
|
import { Spin } from "antd";
|
||||||
|
import { canAddTags } from "../../utils/hasAbilityFn";
|
||||||
|
import useSetPage_title from "../../Hooks/useSetPageTitle";
|
||||||
const Table = lazy(() => import('./Table'));
|
const Table = lazy(() => import('./Table'));
|
||||||
const AddModalForm = lazy(() => import('./Model/AddModel'));
|
const AddModalForm = lazy(() => import('./Model/AddModel'));
|
||||||
const EditModalForm = lazy(() => import('./Model/EditModel'));
|
const EditModalForm = lazy(() => import('./Model/EditModel'));
|
||||||
|
|
@ -20,9 +19,10 @@ const SearchField = lazy(() => import('../../Components/DataTable/SearchField'))
|
||||||
const TableHeader = () => {
|
const TableHeader = () => {
|
||||||
const { handel_open_model } = useModalHandler();
|
const { handel_open_model } = useModalHandler();
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
// useSetPage_title(`${t(ABILITIES_ENUM?.MAIN_PAGE)} / ${t(`models.${ABILITIES_ENUM.tags}`)}`);
|
useSetPage_title(
|
||||||
const can_add_tags = hasAbility(ABILITIES_ENUM.TAG, ABILITIES_VALUES_ENUM.STORE);
|
t(`page_header.tags`),
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="TableWithHeader">
|
<div className="TableWithHeader">
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@ const TableHeader = () => {
|
||||||
<header className="d-flex justify-content-between">
|
<header className="d-flex justify-content-between">
|
||||||
<SearchField searchBy="name" placeholder={t("practical.search_here")} />
|
<SearchField searchBy="name" placeholder={t("practical.search_here")} />
|
||||||
|
|
||||||
{can_add_tags && (
|
{canAddTags && (
|
||||||
<div className="Selects">
|
<div className="Selects">
|
||||||
<button
|
<button
|
||||||
onClick={() => handel_open_model(ModalEnum?.TAGS_ADD)}
|
onClick={() => handel_open_model(ModalEnum?.TAGS_ADD)}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { FaTrash } from 'react-icons/fa';
|
||||||
const Tag = ({ data, index }: { data: any, index: number }) => {
|
const Tag = ({ data, index }: { data: any, index: number }) => {
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const { set_Tags_search ,set_currentTag} = useObjectToEdit();
|
const { setTagsSearch ,setCurrentTag} = useObjectToEdit();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inputRef.current) {
|
if (inputRef.current) {
|
||||||
|
|
@ -20,13 +20,13 @@ const Tag = ({ data, index }: { data: any, index: number }) => {
|
||||||
const handleEditInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleEditInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
// console.log(e.target.value);
|
// console.log(e.target.value);
|
||||||
formik.setFieldValue(`synonyms[${index}]`, e.target.value);
|
formik.setFieldValue(`synonyms[${index}]`, e.target.value);
|
||||||
set_Tags_search(e.target.value)
|
setTagsSearch(e.target.value)
|
||||||
set_currentTag(index)
|
setCurrentTag(index)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInputBlur = () => {
|
const handleInputBlur = () => {
|
||||||
// set_Tags_search(null)
|
// setTagsSearch(null)
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteChoice = () => {
|
const handleDeleteChoice = () => {
|
||||||
|
|
@ -41,7 +41,7 @@ const Tag = ({ data, index }: { data: any, index: number }) => {
|
||||||
formik.setFieldValue('synonyms', currentTags);
|
formik.setFieldValue('synonyms', currentTags);
|
||||||
|
|
||||||
// Reset search state if needed
|
// Reset search state if needed
|
||||||
set_Tags_search(null);
|
setTagsSearch(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -7,27 +7,19 @@ import { RiDeleteBin6Fill } from "react-icons/ri";
|
||||||
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
||||||
import { useModalState } from "../../zustand/Modal";
|
import { useModalState } from "../../zustand/Modal";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../../enums/abilities";
|
import { canDeleteTags, canEditTags } from "../../utils/hasAbilityFn";
|
||||||
import { hasAbility } from "../../utils/hasAbility";
|
|
||||||
|
|
||||||
export const useColumns = () => {
|
export const useColumns = () => {
|
||||||
const { setIsOpen } = useModalState((state) => state);
|
const { setIsOpen } = useModalState((state) => state);
|
||||||
|
|
||||||
const { set_object_to_edit } = useObjectToEdit((state) => state);
|
const { setObjectToEdit } = useObjectToEdit((state) => state);
|
||||||
const handelDelete = (record: any) => {
|
const handelDelete = (record: any) => {
|
||||||
set_object_to_edit(record);
|
setObjectToEdit(record);
|
||||||
setIsOpen(ModalEnum?.TAGS_DELETE);
|
setIsOpen(ModalEnum?.TAGS_DELETE);
|
||||||
};
|
};
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
||||||
const can_edit_tags = hasAbility(
|
|
||||||
ABILITIES_ENUM.TAG,
|
|
||||||
ABILITIES_VALUES_ENUM.UPDATE,
|
|
||||||
);
|
|
||||||
const can_delete_tags = hasAbility(
|
|
||||||
ABILITIES_ENUM.TAG,
|
|
||||||
ABILITIES_VALUES_ENUM.DELETE,
|
|
||||||
);
|
|
||||||
|
|
||||||
const columns: TableColumnsType<tags> = [
|
const columns: TableColumnsType<tags> = [
|
||||||
{
|
{
|
||||||
|
|
@ -51,7 +43,7 @@ export const useColumns = () => {
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
const handleEdit = (record: any) => {
|
const handleEdit = (record: any) => {
|
||||||
// console.log(record,"record");
|
// console.log(record,"record");
|
||||||
set_object_to_edit(record);
|
setObjectToEdit(record);
|
||||||
setIsOpen(ModalEnum?.TAGS_EDIT);
|
setIsOpen(ModalEnum?.TAGS_EDIT);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -60,7 +52,7 @@ export const useColumns = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space size="middle" className={className}>
|
<Space size="middle" className={className}>
|
||||||
{can_edit_tags && (
|
{canEditTags && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
placement="top"
|
placement="top"
|
||||||
title={t("practical.edit")}
|
title={t("practical.edit")}
|
||||||
|
|
@ -78,7 +70,7 @@ export const useColumns = () => {
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{can_delete_tags && (
|
{canDeleteTags && (
|
||||||
<RiDeleteBin6Fill
|
<RiDeleteBin6Fill
|
||||||
onClick={() => handelDelete(record)}
|
onClick={() => handelDelete(record)}
|
||||||
size={22}
|
size={22}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
import { Col, Row } from "reactstrap";
|
|
||||||
import ValidationField from "../../../Components/ValidationField/ValidationField";
|
|
||||||
import { useFormikContext } from "formik";
|
|
||||||
import { useModalState } from "../../../zustand/Modal";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
|
|
||||||
const Form = () => {
|
|
||||||
const formik = useFormikContext();
|
|
||||||
const { isOpen } = useModalState((state) => state);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isOpen === "") {
|
|
||||||
formik.setErrors({});
|
|
||||||
}
|
|
||||||
if (isOpen === "isSuccess") {
|
|
||||||
formik.setErrors({});
|
|
||||||
formik.resetForm();
|
|
||||||
}
|
|
||||||
}, [isOpen]);
|
|
||||||
return (
|
|
||||||
<Row className="w-100">
|
|
||||||
<Col>
|
|
||||||
<ValidationField placeholder="name" label="name" name="name" />
|
|
||||||
<ValidationField placeholder="address" label="address" name="address" />
|
|
||||||
</Col>
|
|
||||||
<Col>
|
|
||||||
<ValidationField placeholder="number" label="number" name="number" />
|
|
||||||
|
|
||||||
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Form;
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
import React, { useEffect } from "react";
|
|
||||||
import { Modal, Spin } from "antd";
|
|
||||||
import { useModalState } from "../../../zustand/Modal";
|
|
||||||
import FormikForm from "../../../Layout/Dashboard/FormikFormModel";
|
|
||||||
import ModelBody from "./Add";
|
|
||||||
import { getInitialValues, getValidationSchema } from "./formUtil";
|
|
||||||
import { ModalEnum } from "../../../enums/Model";
|
|
||||||
|
|
||||||
import { useAddTeacher } from "../../../api/teacher";
|
|
||||||
import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import ModelButtons from "../../../Components/models/ModelButtons";
|
|
||||||
|
|
||||||
const ModalForm: React.FC = () => {
|
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
|
||||||
const { mutate, isSuccess, isLoading } = useAddTeacher();
|
|
||||||
const { set_object_to_edit } = useObjectToEdit();
|
|
||||||
useEffect(() => {
|
|
||||||
if (isSuccess) {
|
|
||||||
setIsOpen("isSuccess");
|
|
||||||
set_object_to_edit({});
|
|
||||||
}
|
|
||||||
}, [setIsOpen, isSuccess]);
|
|
||||||
|
|
||||||
const handleSubmit = (values: any) => {
|
|
||||||
mutate({
|
|
||||||
name: values?.name,
|
|
||||||
contact_information: values?.number,
|
|
||||||
address: values?.address,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
|
||||||
setIsOpen("");
|
|
||||||
set_object_to_edit({});
|
|
||||||
};
|
|
||||||
|
|
||||||
const [t] = useTranslation();
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Modal
|
|
||||||
className="ModalForm"
|
|
||||||
centered
|
|
||||||
width={"60vw"}
|
|
||||||
footer={null}
|
|
||||||
open={isOpen === ModalEnum?.TEACHER_ADD}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
>
|
|
||||||
<FormikForm
|
|
||||||
handleSubmit={handleSubmit}
|
|
||||||
initialValues={getInitialValues([])}
|
|
||||||
validationSchema={getValidationSchema}
|
|
||||||
>
|
|
||||||
<header>
|
|
||||||
{t("practical.add")} {t("models.teacher")}{" "}
|
|
||||||
</header>
|
|
||||||
<main className="main_modal w-100">
|
|
||||||
<ModelBody />
|
|
||||||
<ModelButtons isLoading={isLoading} />
|
|
||||||
</main>
|
|
||||||
</FormikForm>
|
|
||||||
</Modal>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ModalForm;
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
import React, { useEffect, useState } from "react";
|
|
||||||
import { Input, Modal, Spin } from "antd";
|
|
||||||
import { useModalState } from "../../../zustand/Modal";
|
|
||||||
import { ModalEnum } from "../../../enums/Model";
|
|
||||||
import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
|
||||||
import { useDeleteTeacher } from "../../../api/teacher";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
const ModalForm: React.FC = () => {
|
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
|
||||||
const [inputValue, setInputValue] = useState("");
|
|
||||||
|
|
||||||
const { mutate, isLoading, isSuccess } = useDeleteTeacher();
|
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isSuccess) {
|
|
||||||
setIsOpen("");
|
|
||||||
setInputValue("");
|
|
||||||
}
|
|
||||||
}, [isSuccess, setIsOpen]);
|
|
||||||
|
|
||||||
const handleSubmit = () => {
|
|
||||||
mutate({
|
|
||||||
id: Number(object_to_edit?.id),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
|
||||||
setInputValue("");
|
|
||||||
setIsOpen("");
|
|
||||||
set_object_to_edit({});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
// Step 2: Handle changes to the input field
|
|
||||||
setInputValue(e.target.value);
|
|
||||||
};
|
|
||||||
const [t] = useTranslation();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Modal
|
|
||||||
className="ModalForm"
|
|
||||||
centered
|
|
||||||
width={"40vw"}
|
|
||||||
footer={null}
|
|
||||||
open={isOpen === ModalEnum?.TEACHER_DELETE}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
>
|
|
||||||
<header>
|
|
||||||
{t("practical.delete")} ({object_to_edit?.name}){" "}
|
|
||||||
</header>
|
|
||||||
<main className="main_modal">
|
|
||||||
<div className="ValidationField w-100 mb-5">
|
|
||||||
<label className="text ">
|
|
||||||
{t("practical.to_confirm_deletion_please_re_enter")}{" "}
|
|
||||||
{t("input.name")} {t("models.teacher")}
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<Input
|
|
||||||
size="large"
|
|
||||||
type="text"
|
|
||||||
placeholder={`${t("practical.enter")} ${t("input.name")} ${t("models.teacher")} `}
|
|
||||||
value={inputValue}
|
|
||||||
onChange={handleChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="buttons">
|
|
||||||
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
|
||||||
<button
|
|
||||||
className={
|
|
||||||
object_to_edit?.name !== inputValue ? "disabled_button" : ""
|
|
||||||
}
|
|
||||||
disabled={object_to_edit?.name !== inputValue || isLoading}
|
|
||||||
onClick={handleSubmit}
|
|
||||||
>
|
|
||||||
{t("practical.delete")}
|
|
||||||
|
|
||||||
{isLoading && (
|
|
||||||
<span className="Spinier_Div">
|
|
||||||
<Spin />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
</Modal>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ModalForm;
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import { Col, Row } from "reactstrap";
|
|
||||||
import ValidationField from "../../../Components/ValidationField/ValidationField";
|
|
||||||
const Form = () => {
|
|
||||||
return (
|
|
||||||
<Row className="w-100">
|
|
||||||
<Col>
|
|
||||||
<ValidationField placeholder="name" label="name" name="name" />
|
|
||||||
<ValidationField placeholder="address" label="address" name="address" />
|
|
||||||
</Col>
|
|
||||||
<Col>
|
|
||||||
<ValidationField placeholder="number" label="number" name="number" />
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Form;
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
import React, { useEffect } from "react";
|
|
||||||
import { Modal, Spin } from "antd";
|
|
||||||
import { useModalState } from "../../../zustand/Modal";
|
|
||||||
import FormikForm from "../../../Layout/Dashboard/FormikFormModel";
|
|
||||||
import ModelBody from "./Edit";
|
|
||||||
import { getInitialValues, getValidationSchema } from "./formUtil";
|
|
||||||
import { ModalEnum } from "../../../enums/Model";
|
|
||||||
import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
|
||||||
import { useUpdateTeacher } from "../../../api/teacher";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import ModelButtons from "../../../Components/models/ModelButtons";
|
|
||||||
|
|
||||||
const ModalForm: React.FC = () => {
|
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit(
|
|
||||||
(state) => state,
|
|
||||||
);
|
|
||||||
const { mutate, isSuccess, isLoading } = useUpdateTeacher();
|
|
||||||
// console.log(object_to_edit,"object_to_edit");
|
|
||||||
const handleSubmit = (values: any) => {
|
|
||||||
// const contactInformationJson = JSON.stringify({
|
|
||||||
// phone_number: values?.number
|
|
||||||
// });
|
|
||||||
mutate({
|
|
||||||
id: values?.id,
|
|
||||||
name: values?.name,
|
|
||||||
contact_information: values?.number,
|
|
||||||
address: values?.address,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const handleCancel = () => {
|
|
||||||
setIsOpen("");
|
|
||||||
set_object_to_edit({});
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (isSuccess) {
|
|
||||||
setIsOpen("");
|
|
||||||
}
|
|
||||||
}, [setIsOpen, isSuccess]);
|
|
||||||
const [t] = useTranslation();
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
className="ModalForm"
|
|
||||||
centered
|
|
||||||
width={"60vw"}
|
|
||||||
footer={null}
|
|
||||||
open={isOpen === ModalEnum?.TEACHER_EDIT}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
>
|
|
||||||
{object_to_edit && (
|
|
||||||
<FormikForm
|
|
||||||
handleSubmit={handleSubmit}
|
|
||||||
initialValues={getInitialValues(object_to_edit)}
|
|
||||||
validationSchema={getValidationSchema}
|
|
||||||
>
|
|
||||||
<header>
|
|
||||||
{" "}
|
|
||||||
{t("practical.edit")} {t("practical.details")} {t("models.teacher")}{" "}
|
|
||||||
</header>
|
|
||||||
<main className="main_modal w-100">
|
|
||||||
<ModelBody />
|
|
||||||
<ModelButtons isLoading={isLoading} />
|
|
||||||
|
|
||||||
</main>
|
|
||||||
</FormikForm>
|
|
||||||
)}
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ModalForm;
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
import * as Yup from "yup";
|
|
||||||
export const getInitialValues = (objectToEdit: any): any => {
|
|
||||||
return {
|
|
||||||
id: objectToEdit?.id ?? null,
|
|
||||||
number: objectToEdit?.contact_information ?? null,
|
|
||||||
name: objectToEdit?.name ?? null,
|
|
||||||
address: objectToEdit?.address ?? null,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getValidationSchema = () => {
|
|
||||||
return Yup.object().shape({
|
|
||||||
number: Yup.string().required("validation.required"),
|
|
||||||
name: Yup.string().required("validation.required"),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
import { FaPlus } from "react-icons/fa";
|
|
||||||
|
|
||||||
import useModalHandler from "../../utils/useModalHandler";
|
|
||||||
import { ModalEnum } from "../../enums/Model";
|
|
||||||
|
|
||||||
// import useSetPage_title from "../../Hooks/useSetPageTitle";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../../enums/abilities";
|
|
||||||
import { hasAbility } from "../../utils/hasAbility";
|
|
||||||
|
|
||||||
import { lazy, Suspense } from 'react';
|
|
||||||
import { Spin } from "antd";
|
|
||||||
const Table = lazy(() => import('./Table'));
|
|
||||||
const AddModalForm = lazy(() => import('./Model/AddModel'));
|
|
||||||
const EditModalForm = lazy(() => import('./Model/EditModel'));
|
|
||||||
const DeleteModalForm = lazy(() => import('./Model/Delete'));
|
|
||||||
const SearchField = lazy(() => import('../../Components/DataTable/SearchField'));
|
|
||||||
|
|
||||||
|
|
||||||
const TableHeader = () => {
|
|
||||||
const { handel_open_model } = useModalHandler();
|
|
||||||
const [t] = useTranslation();
|
|
||||||
// useSetPage_title(`${t(ABILITIES_ENUM?.MAIN_PAGE)} / ${t(`models.${ABILITIES_ENUM.TEACHER}`)}`);
|
|
||||||
const can_add_TEACHER = hasAbility(ABILITIES_ENUM.TEACHER, ABILITIES_VALUES_ENUM.STORE);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="TableWithHeader">
|
|
||||||
|
|
||||||
<Suspense fallback={<Spin/>}>
|
|
||||||
<header className="d-flex justify-content-between">
|
|
||||||
<SearchField searchBy="name" placeholder={t("practical.search_here")} />
|
|
||||||
|
|
||||||
{can_add_TEACHER && (
|
|
||||||
<div className="Selects">
|
|
||||||
<button
|
|
||||||
onClick={() => handel_open_model(ModalEnum?.TEACHER_ADD)}
|
|
||||||
className="add_button"
|
|
||||||
>
|
|
||||||
{t("practical.add")} {t("models.teacher")} <FaPlus />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</header>
|
|
||||||
|
|
||||||
|
|
||||||
<Table />
|
|
||||||
<DeleteModalForm />
|
|
||||||
<AddModalForm />
|
|
||||||
<EditModalForm />
|
|
||||||
</Suspense>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default TableHeader;
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import React from "react";
|
|
||||||
import { useGetAllTeacher } from "../../api/teacher";
|
|
||||||
import DataTable from "../../Layout/Dashboard/Table/DataTable";
|
|
||||||
import { useColumns } from "./useTableColumns";
|
|
||||||
import useSearchQuery from "../../api/utils/useSearchQuery";
|
|
||||||
const App: React.FC = () => {
|
|
||||||
const [searchQuery] = useSearchQuery("name");
|
|
||||||
|
|
||||||
const response = useGetAllTeacher({
|
|
||||||
name: searchQuery,
|
|
||||||
pagination: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
return <DataTable response={response} useColumns={useColumns} />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
import { useColumns } from "./useTableColumns";
|
|
||||||
import Table from "./Table";
|
|
||||||
|
|
||||||
import { FaPlus } from "react-icons/fa";
|
|
||||||
|
|
||||||
import AddModalForm from "./Model/AddModel";
|
|
||||||
import EditModalForm from "./Model/EditModel";
|
|
||||||
import DeleteModalForm from "./Model/Delete";
|
|
||||||
|
|
||||||
export {
|
|
||||||
Table,
|
|
||||||
useColumns,
|
|
||||||
AddModalForm,
|
|
||||||
EditModalForm,
|
|
||||||
DeleteModalForm,
|
|
||||||
FaPlus
|
|
||||||
};
|
|
||||||
|
|
@ -1,109 +0,0 @@
|
||||||
import { Space, TableColumnsType, Tooltip } from "antd";
|
|
||||||
import { Teacher } from "../../types/Item";
|
|
||||||
|
|
||||||
import { ModalEnum } from "../../enums/Model";
|
|
||||||
import { MdOutlineEdit } from "react-icons/md";
|
|
||||||
import { RiDeleteBin6Fill } from "react-icons/ri";
|
|
||||||
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
|
||||||
import { useModalState } from "../../zustand/Modal";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../../enums/abilities";
|
|
||||||
import { hasAbility } from "../../utils/hasAbility";
|
|
||||||
|
|
||||||
export const useColumns = () => {
|
|
||||||
const { setIsOpen } = useModalState((state) => state);
|
|
||||||
|
|
||||||
const { set_object_to_edit } = useObjectToEdit((state) => state);
|
|
||||||
const handelDelete = (record: any) => {
|
|
||||||
set_object_to_edit(record);
|
|
||||||
setIsOpen(ModalEnum?.TEACHER_DELETE);
|
|
||||||
};
|
|
||||||
const [t] = useTranslation();
|
|
||||||
|
|
||||||
const can_edit_TEACHER = hasAbility(
|
|
||||||
ABILITIES_ENUM.TEACHER,
|
|
||||||
ABILITIES_VALUES_ENUM.UPDATE,
|
|
||||||
);
|
|
||||||
const can_delete_TEACHER = hasAbility(
|
|
||||||
ABILITIES_ENUM.TEACHER,
|
|
||||||
ABILITIES_VALUES_ENUM.DELETE,
|
|
||||||
);
|
|
||||||
|
|
||||||
const columns: TableColumnsType<Teacher> = [
|
|
||||||
{
|
|
||||||
title: t("columns.id"),
|
|
||||||
dataIndex: "id",
|
|
||||||
key: "id",
|
|
||||||
align: "center",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: t("columns.name"),
|
|
||||||
dataIndex: "name",
|
|
||||||
key: "name",
|
|
||||||
align: "center",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: t("columns.address"),
|
|
||||||
dataIndex: "address",
|
|
||||||
key: "address",
|
|
||||||
align: "center",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: t("columns.contact_information"),
|
|
||||||
dataIndex: "contact_information",
|
|
||||||
key: "contact_information",
|
|
||||||
align: "center",
|
|
||||||
render: (text, record, index) => {
|
|
||||||
return <>{record?.contact_information}</>;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: "",
|
|
||||||
key: "actions",
|
|
||||||
align: "end",
|
|
||||||
width: "25vw",
|
|
||||||
render: (text, record, index) => {
|
|
||||||
const handleEdit = (record: any) => {
|
|
||||||
// console.log(record,"record");
|
|
||||||
set_object_to_edit(record);
|
|
||||||
setIsOpen(ModalEnum?.TEACHER_EDIT);
|
|
||||||
};
|
|
||||||
|
|
||||||
const className =
|
|
||||||
index % 2 === 0 ? "even-row buttonAction" : "odd-row buttonAction";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Space size="middle" className={className}>
|
|
||||||
{can_edit_TEACHER && (
|
|
||||||
<Tooltip
|
|
||||||
placement="top"
|
|
||||||
title={t("practical.edit")}
|
|
||||||
color="#E0E0E0"
|
|
||||||
|
|
||||||
>
|
|
||||||
<span onClick={() => handleEdit(record)}>
|
|
||||||
<MdOutlineEdit
|
|
||||||
size={22}
|
|
||||||
style={{ color: "#A098AE" }}
|
|
||||||
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{can_delete_TEACHER && (
|
|
||||||
<RiDeleteBin6Fill
|
|
||||||
onClick={() => handelDelete(record)}
|
|
||||||
size={22}
|
|
||||||
style={{ color: "#C11313" }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Space>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return columns;
|
|
||||||
};
|
|
||||||
|
|
@ -12,11 +12,11 @@ const ModalForm: React.FC = () => {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useDeleteUnit();
|
const { mutate, isSuccess, isLoading } = useDeleteUnit();
|
||||||
const { object_to_edit } = useObjectToEdit((state) => state);
|
const { objectToEdit } = useObjectToEdit((state) => state);
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
mutate({
|
mutate({
|
||||||
id: Number(object_to_edit?.id),
|
id: Number(objectToEdit?.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
{" "}
|
{" "}
|
||||||
{t("practical.delete")} {object_to_edit?.name}{" "}
|
{t("practical.delete")} {objectToEdit?.name}{" "}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main className="main_modal">
|
<main className="main_modal">
|
||||||
|
|
@ -74,9 +74,9 @@ const ModalForm: React.FC = () => {
|
||||||
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
object_to_edit?.name !== inputValue ? "disabled_button" : ""
|
objectToEdit?.name !== inputValue ? "disabled_button" : ""
|
||||||
}
|
}
|
||||||
disabled={object_to_edit?.name !== inputValue || isLoading}
|
disabled={objectToEdit?.name !== inputValue || isLoading}
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@ const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useUpdateUnit();
|
const { mutate, isSuccess, isLoading } = useUpdateUnit();
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
// console.log(object_to_edit,"object_to_edit");
|
// console.log(objectToEdit,"objectToEdit");
|
||||||
const { subject_id } = useParams();
|
const { subject_id } = useParams();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -50,7 +50,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<FormikForm
|
<FormikForm
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
initialValues={getInitialValues(object_to_edit)}
|
initialValues={getInitialValues(objectToEdit)}
|
||||||
validationSchema={getValidationSchema}
|
validationSchema={getValidationSchema}
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ const TableHeader = () => {
|
||||||
|
|
||||||
const SubjectName = Subject?.data?.name ?? "";
|
const SubjectName = Subject?.data?.name ?? "";
|
||||||
|
|
||||||
console.log(SubjectName);
|
|
||||||
useSetPage_title(
|
useSetPage_title(
|
||||||
t(`page_header.subject`) +
|
t(`page_header.subject`) +
|
||||||
"/" +
|
"/" +
|
||||||
|
|
|
||||||
|
|
@ -1,54 +1,36 @@
|
||||||
import { Space, TableColumnsType, Tooltip } from "antd";
|
import { Space, TableColumnsType, Tooltip } from "antd";
|
||||||
import { Unit } from "../../types/Item";
|
import { Unit } from "../../types/Item";
|
||||||
import { FaPlus } from "react-icons/fa";
|
import { FaPlus } from "react-icons/fa";
|
||||||
|
|
||||||
import useModalHandler from "../../utils/useModalHandler";
|
import useModalHandler from "../../utils/useModalHandler";
|
||||||
import { ModalEnum } from "../../enums/Model";
|
import { ModalEnum } from "../../enums/Model";
|
||||||
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
||||||
import { RiDeleteBin6Fill } from "react-icons/ri";
|
import { RiDeleteBin6Fill } from "react-icons/ri";
|
||||||
import { MdOutlineEdit } from "react-icons/md";
|
import { MdOutlineEdit } from "react-icons/md";
|
||||||
import { findLabelByValue } from "../../utils/findLabelByValue";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { hasAbility } from "../../utils/hasAbility";
|
import { ABILITIES_ENUM } from "../../enums/abilities";
|
||||||
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../../enums/abilities";
|
|
||||||
import { formatNumber } from "../../utils/formatNumber";
|
|
||||||
import { BsEyeFill } from "react-icons/bs";
|
import { BsEyeFill } from "react-icons/bs";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { canAddUnit, canDeleteUnit, canEditUnit, canShowUnit } from "../../utils/hasAbilityFn";
|
||||||
|
|
||||||
export const useColumns = () => {
|
export const useColumns = () => {
|
||||||
const { handel_open_model } = useModalHandler();
|
const { handel_open_model } = useModalHandler();
|
||||||
|
|
||||||
const { set_object_to_edit } = useObjectToEdit((state) => state);
|
const { setObjectToEdit } = useObjectToEdit((state) => state);
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const handelShow = (record: any) => {
|
const handelShow = (record: any) => {
|
||||||
navigate(`${ABILITIES_ENUM?.UNIT}/${record?.id}`);
|
navigate(`${ABILITIES_ENUM?.UNIT}/${record?.id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const can_edit_Unit = hasAbility(
|
|
||||||
ABILITIES_ENUM.UNIT,
|
|
||||||
ABILITIES_VALUES_ENUM.UPDATE,
|
|
||||||
);
|
|
||||||
const can_delete_Unit = hasAbility(
|
|
||||||
ABILITIES_ENUM.UNIT,
|
|
||||||
ABILITIES_VALUES_ENUM.DELETE,
|
|
||||||
);
|
|
||||||
const can_add_Unit = hasAbility(
|
|
||||||
ABILITIES_ENUM.UNIT,
|
|
||||||
ABILITIES_VALUES_ENUM.STORE,
|
|
||||||
);
|
|
||||||
const can_show_Unit = hasAbility(
|
|
||||||
ABILITIES_ENUM.UNIT,
|
|
||||||
ABILITIES_VALUES_ENUM.SHOW,
|
|
||||||
);
|
|
||||||
|
|
||||||
const handelDelete = (data: any) => {
|
const handelDelete = (data: any) => {
|
||||||
set_object_to_edit(data);
|
setObjectToEdit(data);
|
||||||
handel_open_model(ModalEnum?.UNIT_DELETE);
|
handel_open_model(ModalEnum?.UNIT_DELETE);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEdit = (record: any) => {
|
const handleEdit = (record: any) => {
|
||||||
set_object_to_edit(record);
|
setObjectToEdit(record);
|
||||||
handel_open_model(ModalEnum?.UNIT_EDIT);
|
handel_open_model(ModalEnum?.UNIT_EDIT);
|
||||||
};
|
};
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
@ -78,7 +60,7 @@ export const useColumns = () => {
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
title: can_add_Unit ? (
|
title: canAddUnit ? (
|
||||||
<button
|
<button
|
||||||
onClick={() => handel_open_model(ModalEnum?.UNIT_ADD)}
|
onClick={() => handel_open_model(ModalEnum?.UNIT_ADD)}
|
||||||
className="add_button"
|
className="add_button"
|
||||||
|
|
@ -97,7 +79,7 @@ export const useColumns = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space size="middle" className={className}>
|
<Space size="middle" className={className}>
|
||||||
{can_edit_Unit && (
|
{canEditUnit && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
placement="top"
|
placement="top"
|
||||||
title={t("practical.edit")}
|
title={t("practical.edit")}
|
||||||
|
|
@ -112,14 +94,14 @@ export const useColumns = () => {
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{can_delete_Unit && (
|
{canDeleteUnit && (
|
||||||
<RiDeleteBin6Fill
|
<RiDeleteBin6Fill
|
||||||
onClick={() => handelDelete(record)}
|
onClick={() => handelDelete(record)}
|
||||||
size={22}
|
size={22}
|
||||||
style={{ color: "#C11313" }}
|
style={{ color: "#C11313" }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{can_show_Unit && (
|
{canShowUnit && (
|
||||||
|
|
||||||
<BsEyeFill
|
<BsEyeFill
|
||||||
onClick={() => handelShow(record)}
|
onClick={() => handelShow(record)}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import { ParamsEnum } from "../../../enums/params";
|
||||||
|
|
||||||
const ModalForm: React.FC = () => {
|
const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ const ModalForm: React.FC = () => {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useDeleteLesson();
|
const { mutate, isSuccess, isLoading } = useDeleteLesson();
|
||||||
const { object_to_edit,set_object_to_edit } = useObjectToEdit((state) => state);
|
const { objectToEdit,setObjectToEdit } = useObjectToEdit((state) => state);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
mutate({
|
mutate({
|
||||||
id: Number(object_to_edit?.id),
|
id: Number(objectToEdit?.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -32,7 +32,7 @@ const ModalForm: React.FC = () => {
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setInputValue("");
|
setInputValue("");
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
@ -51,7 +51,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
{" "}
|
{" "}
|
||||||
{t("practical.delete")} {object_to_edit?.name}{" "}
|
{t("practical.delete")} {objectToEdit?.name}{" "}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main className="main_modal">
|
<main className="main_modal">
|
||||||
|
|
@ -74,9 +74,9 @@ const ModalForm: React.FC = () => {
|
||||||
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
object_to_edit?.name !== inputValue ? "disabled_button" : ""
|
objectToEdit?.name !== inputValue ? "disabled_button" : ""
|
||||||
}
|
}
|
||||||
disabled={object_to_edit?.name !== inputValue || isLoading}
|
disabled={objectToEdit?.name !== inputValue || isLoading}
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
>
|
>
|
||||||
{t("practical.delete")}
|
{t("practical.delete")}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useUpdateLesson();
|
const { mutate, isSuccess, isLoading } = useUpdateLesson();
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
// console.log(object_to_edit,"object_to_edit");
|
// console.log(objectToEdit,"objectToEdit");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
|
|
@ -53,7 +53,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<FormikForm
|
<FormikForm
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
initialValues={getInitialValues(object_to_edit)}
|
initialValues={getInitialValues(objectToEdit)}
|
||||||
validationSchema={getValidationSchema}
|
validationSchema={getValidationSchema}
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -14,41 +14,27 @@ import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../../enums/abilities";
|
||||||
import { formatNumber } from "../../utils/formatNumber";
|
import { formatNumber } from "../../utils/formatNumber";
|
||||||
import { BsEyeFill } from "react-icons/bs";
|
import { BsEyeFill } from "react-icons/bs";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { canAddLesson, canDeleteLesson, canEditLesson, canShowLesson } from "../../utils/hasAbilityFn";
|
||||||
|
|
||||||
export const useColumns = () => {
|
export const useColumns = () => {
|
||||||
const { handel_open_model } = useModalHandler();
|
const { handel_open_model } = useModalHandler();
|
||||||
|
|
||||||
const { set_object_to_edit } = useObjectToEdit((state) => state);
|
const { setObjectToEdit } = useObjectToEdit((state) => state);
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const handelShow = (record: any) => {
|
const handelShow = (record: any) => {
|
||||||
navigate(`${ABILITIES_ENUM.LESSON}/${record?.id}`);
|
navigate(`${ABILITIES_ENUM.LESSON}/${record?.id}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const can_edit_Lesson = hasAbility(
|
|
||||||
ABILITIES_ENUM.LESSON,
|
|
||||||
ABILITIES_VALUES_ENUM.UPDATE,
|
|
||||||
);
|
|
||||||
const can_delete_Lesson = hasAbility(
|
|
||||||
ABILITIES_ENUM.LESSON,
|
|
||||||
ABILITIES_VALUES_ENUM.DELETE,
|
|
||||||
);
|
|
||||||
const can_add_Lesson = hasAbility(
|
|
||||||
ABILITIES_ENUM.LESSON,
|
|
||||||
ABILITIES_VALUES_ENUM.STORE,
|
|
||||||
);
|
|
||||||
const can_show_Lesson = hasAbility(
|
|
||||||
ABILITIES_ENUM.LESSON,
|
|
||||||
ABILITIES_VALUES_ENUM.SHOW,
|
|
||||||
);
|
|
||||||
|
|
||||||
const handelDelete = (data: any) => {
|
const handelDelete = (data: any) => {
|
||||||
set_object_to_edit(data);
|
setObjectToEdit(data);
|
||||||
handel_open_model(ModalEnum?.LESSON_DELETE);
|
handel_open_model(ModalEnum?.LESSON_DELETE);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEdit = (record: any) => {
|
const handleEdit = (record: any) => {
|
||||||
set_object_to_edit(record);
|
setObjectToEdit(record);
|
||||||
handel_open_model(ModalEnum?.LESSON_EDIT);
|
handel_open_model(ModalEnum?.LESSON_EDIT);
|
||||||
};
|
};
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
@ -69,7 +55,7 @@ export const useColumns = () => {
|
||||||
render: (text, record) => record?.name,
|
render: (text, record) => record?.name,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: can_add_Lesson ? (
|
title: canAddLesson ? (
|
||||||
<button
|
<button
|
||||||
onClick={() => handel_open_model(ModalEnum?.LESSON_ADD)}
|
onClick={() => handel_open_model(ModalEnum?.LESSON_ADD)}
|
||||||
className="add_button"
|
className="add_button"
|
||||||
|
|
@ -88,7 +74,7 @@ export const useColumns = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space size="middle" className={className}>
|
<Space size="middle" className={className}>
|
||||||
{can_edit_Lesson && (
|
{canEditLesson && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
placement="top"
|
placement="top"
|
||||||
title={t("practical.edit")}
|
title={t("practical.edit")}
|
||||||
|
|
@ -103,14 +89,14 @@ export const useColumns = () => {
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{can_delete_Lesson && (
|
{canDeleteLesson && (
|
||||||
<RiDeleteBin6Fill
|
<RiDeleteBin6Fill
|
||||||
onClick={() => handelDelete(record)}
|
onClick={() => handelDelete(record)}
|
||||||
size={22}
|
size={22}
|
||||||
style={{ color: "#C11313" }}
|
style={{ color: "#C11313" }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{can_show_Lesson && (
|
{canShowLesson && (
|
||||||
|
|
||||||
<BsEyeFill
|
<BsEyeFill
|
||||||
onClick={() => handelShow(record)}
|
onClick={() => handelShow(record)}
|
||||||
|
|
|
||||||
|
|
@ -22,21 +22,47 @@ import { QUESTION_OBJECT_KEY } from "../../config/AppKey";
|
||||||
import useSaveOnDisconnect from "../../Hooks/useSaveOnDisconnect";
|
import useSaveOnDisconnect from "../../Hooks/useSaveOnDisconnect";
|
||||||
import { getLocalStorageQuestions } from "../../utils/setLocalStorageQuestions";
|
import { getLocalStorageQuestions } from "../../utils/setLocalStorageQuestions";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
import useSetPage_title from "../../Hooks/useSetPageTitle";
|
||||||
|
import { useGetAllUnit } from "../../api/unit";
|
||||||
|
import { useGetAllLesson } from "../../api/lesson";
|
||||||
|
|
||||||
const AddPage: React.FC = () => {
|
const AddPage: React.FC = () => {
|
||||||
|
|
||||||
const {isSuccess:isSuccessAsync,mutateAsync} = useAddQuestionAsync()
|
const {isSuccess:isSuccessAsync,mutateAsync} = useAddQuestionAsync()
|
||||||
const { mutate,isSuccess, isLoading} = useAddQuestion();
|
const { mutate,isSuccess, isLoading} = useAddQuestion();
|
||||||
const {isBseQuestion,set_Tags_search,set_object_to_edit,set_Success,SavedQuestionData} = useObjectToEdit()
|
const {isBseQuestion,setTagsSearch,setObjectToEdit,setSuccess,SavedQuestionData} = useObjectToEdit()
|
||||||
|
|
||||||
const {subject_id,lesson_id} = useParams<ParamsEnum>()
|
const {subject_id,lesson_id,unit_id} = useParams<ParamsEnum>()
|
||||||
const { setIsOpen } = useModalState((state) => state);
|
const { setIsOpen } = useModalState((state) => state);
|
||||||
|
|
||||||
|
|
||||||
|
const { data: unit } = useGetAllUnit({ show: unit_id });
|
||||||
|
const { data: lesson } = useGetAllLesson({ show: lesson_id });
|
||||||
|
|
||||||
|
const [t] = useTranslation()
|
||||||
|
const unitName = unit?.data?.name ?? "";
|
||||||
|
const SubjectName = unit?.data?.subject?.name ?? "";
|
||||||
|
const lessonName = lesson?.data?.name ?? "";
|
||||||
|
|
||||||
|
useSetPage_title(
|
||||||
|
t(`page_header.subject`) +
|
||||||
|
"/" +
|
||||||
|
`${SubjectName}` +
|
||||||
|
"/" +
|
||||||
|
t(`page_title.unit`) +
|
||||||
|
"/" +
|
||||||
|
`${unitName}`+"/"
|
||||||
|
+
|
||||||
|
t(`page_title.lesson`) +
|
||||||
|
"/" +
|
||||||
|
`${lessonName}`+ "/" +
|
||||||
|
t(`page_title.questions`)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
const handleSubmit = (values: any, { resetForm }: { resetForm: () => void }) => {
|
const handleSubmit = (values: any, { resetForm }: { resetForm: () => void }) => {
|
||||||
const DataToSend = structuredClone(values);
|
const DataToSend = structuredClone(values);
|
||||||
set_Tags_search(null);
|
setTagsSearch(null);
|
||||||
console.log(isBseQuestion);
|
console.log(isBseQuestion);
|
||||||
|
|
||||||
if (isBseQuestion || DataToSend?.isBase === 1) {
|
if (isBseQuestion || DataToSend?.isBase === 1) {
|
||||||
|
|
@ -84,15 +110,15 @@ const AddPage: React.FC = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
if (isSuccessAsync && ( SavedQuestionData?.Questions?.length > 0 ? isSuccess: true )) {
|
if (isSuccessAsync && ( SavedQuestionData?.Questions?.length > 0 ? isSuccess: true )) {
|
||||||
set_object_to_edit(null)
|
setObjectToEdit(null)
|
||||||
set_Success(true)
|
setSuccess(true)
|
||||||
localStorage.removeItem(QUESTION_OBJECT_KEY)
|
localStorage.removeItem(QUESTION_OBJECT_KEY)
|
||||||
|
|
||||||
}
|
}
|
||||||
if(isSuccess && !(SavedQuestionData?.Questions?.length)){
|
if(isSuccess && !(SavedQuestionData?.Questions?.length)){
|
||||||
toast.success(t("validation.the_possess_done_successful"))
|
toast.success(t("validation.the_possess_done_successful"))
|
||||||
set_object_to_edit(null)
|
setObjectToEdit(null)
|
||||||
set_Success(true)
|
setSuccess(true)
|
||||||
localStorage.removeItem(QUESTION_OBJECT_KEY)
|
localStorage.removeItem(QUESTION_OBJECT_KEY)
|
||||||
}
|
}
|
||||||
}, [isSuccess,isSuccessAsync])
|
}, [isSuccess,isSuccessAsync])
|
||||||
|
|
@ -117,7 +143,6 @@ const AddPage: React.FC = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [t] = useTranslation();
|
|
||||||
|
|
||||||
|
|
||||||
if(isBseQuestion || SavedData?.isBase === 1){
|
if(isBseQuestion || SavedData?.isBase === 1){
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,18 @@ import { ParamsEnum } from "../../enums/params";
|
||||||
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
||||||
import { removeStringKeys } from "../../utils/removeStringKeys";
|
import { removeStringKeys } from "../../utils/removeStringKeys";
|
||||||
import SpinContainer from "../../Components/Layout/SpinContainer";
|
import SpinContainer from "../../Components/Layout/SpinContainer";
|
||||||
import Header from "../../Components/exercise/Header";
|
|
||||||
import Form from './Model/Edit'
|
import Form from './Model/Edit'
|
||||||
import BaseForm from './Model/Malty/Edit'
|
import BaseForm from './Model/Malty/Edit'
|
||||||
import { Question } from "../../types/Item";
|
import { Question } from "../../types/Item";
|
||||||
import { toast } from "react-toastify";
|
import { toast } from "react-toastify";
|
||||||
|
import useSetPage_title from "../../Hooks/useSetPageTitle";
|
||||||
|
import { useGetAllUnit } from "../../api/unit";
|
||||||
|
import { useGetAllLesson } from "../../api/lesson";
|
||||||
|
|
||||||
const EditPage: React.FC = () => {
|
const EditPage: React.FC = () => {
|
||||||
|
|
||||||
const {question_id,subject_id} = useParams<ParamsEnum>()
|
const {question_id,subject_id,unit_id} = useParams<ParamsEnum>()
|
||||||
const {isBseQuestion,set_isBseQuestion,set_Tags_search,DeletedQuestions} = useObjectToEdit()
|
const {isBseQuestion,setIsBseQuestion,setTagsSearch,DeletedQuestions} = useObjectToEdit()
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useUpdateQuestion();
|
const { mutate, isSuccess, isLoading } = useUpdateQuestion();
|
||||||
const { mutate:DeleteQuestion} = useDeleteQuestion();
|
const { mutate:DeleteQuestion} = useDeleteQuestion();
|
||||||
|
|
@ -29,20 +31,45 @@ const EditPage: React.FC = () => {
|
||||||
|
|
||||||
const {data:Questions,isLoading:QuestionsDataLoading}= useGetAllQuestion({questionParentId:question_id ,onlyWithNoParents:false})
|
const {data:Questions,isLoading:QuestionsDataLoading}= useGetAllQuestion({questionParentId:question_id ,onlyWithNoParents:false})
|
||||||
|
|
||||||
const object_to_edit = {...data?.data,Questions:Questions?.data } ;
|
const objectToEdit = {...data?.data,Questions:Questions?.data } ;
|
||||||
|
|
||||||
const {lesson_id} = useParams()
|
const {lesson_id} = useParams()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(object_to_edit?.isBase && isBseQuestion !== true){
|
if(objectToEdit?.isBase && isBseQuestion !== true){
|
||||||
set_isBseQuestion(true)
|
setIsBseQuestion(true)
|
||||||
|
|
||||||
}
|
}
|
||||||
}, [object_to_edit?.isBase])
|
}, [objectToEdit?.isBase])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const { data: unit } = useGetAllUnit({ show: unit_id });
|
||||||
|
const { data: lesson } = useGetAllLesson({ show: lesson_id });
|
||||||
|
|
||||||
|
const [t] = useTranslation()
|
||||||
|
const unitName = unit?.data?.name ?? "";
|
||||||
|
const SubjectName = unit?.data?.subject?.name ?? "";
|
||||||
|
const lessonName = lesson?.data?.name ?? "";
|
||||||
|
|
||||||
|
useSetPage_title(
|
||||||
|
t(`page_header.subject`) +
|
||||||
|
"/" +
|
||||||
|
`${SubjectName}` +
|
||||||
|
"/" +
|
||||||
|
t(`page_title.unit`) +
|
||||||
|
"/" +
|
||||||
|
`${unitName}`+"/"
|
||||||
|
+
|
||||||
|
t(`page_title.lesson`) +
|
||||||
|
"/" +
|
||||||
|
`${lessonName}`+ "/" +
|
||||||
|
t(`page_title.questions`)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
const handleSubmit = (values: any) => {
|
const handleSubmit = (values: any) => {
|
||||||
const DataToSend = structuredClone(values);
|
const DataToSend = structuredClone(values);
|
||||||
set_Tags_search(null)
|
setTagsSearch(null)
|
||||||
console.log(DataToSend);
|
console.log(DataToSend);
|
||||||
|
|
||||||
if(isBseQuestion){
|
if(isBseQuestion){
|
||||||
|
|
@ -52,11 +79,12 @@ const EditPage: React.FC = () => {
|
||||||
"content" : DataToSend?.content,
|
"content" : DataToSend?.content,
|
||||||
"image": DataToSend?.image ?? "",
|
"image": DataToSend?.image ?? "",
|
||||||
}
|
}
|
||||||
if( typeof UpdateBseQuestion?.image === "string"){
|
if( typeof UpdateBseQuestion?.image === "string" && UpdateBseQuestion?.image !== ""){
|
||||||
delete UpdateBseQuestion["image"]
|
delete UpdateBseQuestion["image"]
|
||||||
}
|
}
|
||||||
console.log(DeletedQuestions,"DeletedQuestions");
|
console.log(DeletedQuestions,"DeletedQuestions");
|
||||||
|
console.log(UpdateBseQuestion);
|
||||||
|
|
||||||
mutate(UpdateBseQuestion)
|
mutate(UpdateBseQuestion)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -118,11 +146,21 @@ const EditPage: React.FC = () => {
|
||||||
delete updatedObject["parent_id"];
|
delete updatedObject["parent_id"];
|
||||||
const tags = processTags(updatedObject)
|
const tags = processTags(updatedObject)
|
||||||
console.log(updatedObject,"updatedObject");
|
console.log(updatedObject,"updatedObject");
|
||||||
|
if(!(updatedObject?.image)){
|
||||||
|
updatedObject["image"] = "" ;
|
||||||
|
}
|
||||||
|
console.log(updatedObject);
|
||||||
|
|
||||||
const oldQuestionOptions = [] as any;
|
const oldQuestionOptions = [] as any;
|
||||||
const newQuestionOptions = [] as any;
|
const newQuestionOptions = [] as any;
|
||||||
|
|
||||||
updatedObject?.QuestionOptions?.forEach((item:any) => {
|
updatedObject?.QuestionOptions?.forEach((item:any) => {
|
||||||
if (item?.id) {
|
if (item?.id) {
|
||||||
|
// if(!item?.answer_image){
|
||||||
|
// item["answer_image"] = ""
|
||||||
|
// }
|
||||||
|
console.log(item);
|
||||||
|
|
||||||
oldQuestionOptions.push(item);
|
oldQuestionOptions.push(item);
|
||||||
} else {
|
} else {
|
||||||
newQuestionOptions.push(item);
|
newQuestionOptions.push(item);
|
||||||
|
|
@ -145,7 +183,6 @@ const EditPage: React.FC = () => {
|
||||||
navigate(-1)
|
navigate(-1)
|
||||||
};
|
};
|
||||||
|
|
||||||
const [t] = useTranslation();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(isSuccess){
|
if(isSuccess){
|
||||||
|
|
@ -156,10 +193,10 @@ const EditPage: React.FC = () => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(dataLoading && !!(object_to_edit?.isBase) && QuestionsDataLoading){
|
if(dataLoading || QuestionsDataLoading){
|
||||||
return <SpinContainer/>
|
return <SpinContainer/>
|
||||||
}
|
}
|
||||||
if(object_to_edit?.isBase){
|
if(objectToEdit?.isBase){
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -167,7 +204,7 @@ const EditPage: React.FC = () => {
|
||||||
|
|
||||||
<FormikForm
|
<FormikForm
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
initialValues={getInitialValuesBase(object_to_edit)}
|
initialValues={getInitialValuesBase(objectToEdit)}
|
||||||
validationSchema={getValidationSchemaBase}
|
validationSchema={getValidationSchemaBase}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|
@ -207,7 +244,7 @@ const EditPage: React.FC = () => {
|
||||||
|
|
||||||
<FormikForm
|
<FormikForm
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
initialValues={getInitialValues(object_to_edit)}
|
initialValues={getInitialValues(objectToEdit)}
|
||||||
validationSchema={getValidationSchema}
|
validationSchema={getValidationSchema}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,18 +11,18 @@ import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
|
||||||
import MathInput from "./MathInput";
|
import MathInput from "./MathInput";
|
||||||
const Form = () => {
|
const Form = () => {
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const{set_Success,Success,set_SavedQuestionData} = useObjectToEdit()
|
const{setSuccess,Success,setSavedQuestionData} = useObjectToEdit()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (Success) {
|
if (Success) {
|
||||||
formik.setErrors({});
|
formik.setErrors({});
|
||||||
formik.resetForm({ values: {} });
|
formik.resetForm({ values: {} });
|
||||||
set_Success(false)
|
setSuccess(false)
|
||||||
}
|
}
|
||||||
}, [Success]);
|
}, [Success]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
set_SavedQuestionData(formik.values)
|
setSavedQuestionData(formik.values)
|
||||||
}, [formik?.values])
|
}, [formik?.values])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const ModalForm: React.FC = () => {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
||||||
const { mutate, isLoading, isSuccess } = useDeleteQuestion();
|
const { mutate, isLoading, isSuccess } = useDeleteQuestion();
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
|
|
@ -22,14 +22,14 @@ const ModalForm: React.FC = () => {
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
mutate({
|
mutate({
|
||||||
id: Number(object_to_edit?.id),
|
id: Number(objectToEdit?.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setInputValue("");
|
setInputValue("");
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
@ -37,7 +37,7 @@ const ModalForm: React.FC = () => {
|
||||||
setInputValue(e.target.value);
|
setInputValue(e.target.value);
|
||||||
};
|
};
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
console.log(object_to_edit?.id);
|
console.log(objectToEdit?.id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -50,7 +50,7 @@ const ModalForm: React.FC = () => {
|
||||||
onCancel={handleCancel}
|
onCancel={handleCancel}
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
{t("practical.delete")} {t("input.id")} ({object_to_edit?.id}){" "}
|
{t("practical.delete")} {t("input.id")} ({objectToEdit?.id}){" "}
|
||||||
</header>
|
</header>
|
||||||
<main className="main_modal">
|
<main className="main_modal">
|
||||||
<div className="ValidationField w-100 mb-5">
|
<div className="ValidationField w-100 mb-5">
|
||||||
|
|
@ -72,9 +72,9 @@ const ModalForm: React.FC = () => {
|
||||||
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
object_to_edit?.id !== inputValue ? "disabled_button" : ""
|
objectToEdit?.id !== inputValue ? "disabled_button" : ""
|
||||||
}
|
}
|
||||||
disabled={Number(object_to_edit?.id) !== Number(inputValue) || isLoading}
|
disabled={Number(objectToEdit?.id) !== Number(inputValue) || isLoading}
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
>
|
>
|
||||||
{t("practical.delete")}
|
{t("practical.delete")}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ const Form = () => {
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const { isOpen } = useModalState((state) => state);
|
const { isOpen } = useModalState((state) => state);
|
||||||
// const {data} = useGetAllQuestion();
|
// const {data} = useGetAllQuestion();
|
||||||
const{set_Success,Success,set_SavedQuestionData} = useObjectToEdit()
|
const{setSuccess,Success,setSavedQuestionData} = useObjectToEdit()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (Success) {
|
if (Success) {
|
||||||
|
|
@ -23,12 +23,12 @@ const Form = () => {
|
||||||
|
|
||||||
formik.setErrors({});
|
formik.setErrors({});
|
||||||
formik.resetForm({ values: {} });
|
formik.resetForm({ values: {} });
|
||||||
set_Success(false)
|
setSuccess(false)
|
||||||
}
|
}
|
||||||
}, [Success]);
|
}, [Success]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
set_SavedQuestionData(formik.values)
|
setSavedQuestionData(formik.values)
|
||||||
}, [formik?.values])
|
}, [formik?.values])
|
||||||
|
|
||||||
// console.log(formik?.errors);
|
// console.log(formik?.errors);
|
||||||
|
|
|
||||||
|
|
@ -13,18 +13,18 @@ import { toast } from 'react-toastify';
|
||||||
const QuestionFIeld = ({index,data}:{index:number , data :Choice }) => {
|
const QuestionFIeld = ({index,data}:{index:number , data :Choice }) => {
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
console.log(index);
|
console.log(index);
|
||||||
const {set_DeletedQuestions,DeletedQuestions} = useObjectToEdit()
|
const {setDeletedQuestions,DeletedQuestions} = useObjectToEdit()
|
||||||
|
|
||||||
const [t] = useTranslation()
|
const [t] = useTranslation()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
set_DeletedQuestions([])
|
setDeletedQuestions([])
|
||||||
}, [window?.location.pathname])
|
}, [window?.location.pathname])
|
||||||
|
|
||||||
const handleDeleteQuestion = () => {
|
const handleDeleteQuestion = () => {
|
||||||
|
|
||||||
const DeleteQuestionId = formik.values.Questions?.[index];
|
const DeleteQuestionId = formik.values.Questions?.[index];
|
||||||
if(DeleteQuestionId?.id){
|
if(DeleteQuestionId?.id){
|
||||||
set_DeletedQuestions([...DeletedQuestions,DeleteQuestionId])
|
setDeletedQuestions([...DeletedQuestions,DeleteQuestionId])
|
||||||
|
|
||||||
}
|
}
|
||||||
const updatedQuestionOptions = formik.values.Questions.filter((_:any, i:any) => i !== index);
|
const updatedQuestionOptions = formik.values.Questions.filter((_:any, i:any) => i !== index);
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ const DynamicTags = ({parent_index}:{parent_index:number}) => {
|
||||||
|
|
||||||
const formik = useFormikContext<any>()
|
const formik = useFormikContext<any>()
|
||||||
const [t] = useTranslation()
|
const [t] = useTranslation()
|
||||||
const { Tags_search ,set_Tags_search,currentTag,current_parent_index} = useObjectToEdit();
|
const { TagsSearch ,setTagsSearch,currentTag,currentParentIndex} = useObjectToEdit();
|
||||||
const {data} = useGetAllTag({
|
const {data} = useGetAllTag({
|
||||||
name : Tags_search
|
name : TagsSearch
|
||||||
})
|
})
|
||||||
const suggests = data?.data
|
const suggests = data?.data
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ const DynamicTags = ({parent_index}:{parent_index:number}) => {
|
||||||
const handleAddChoice = () => {
|
const handleAddChoice = () => {
|
||||||
const length = formik?.values?.Questions?.[parent_index]?.tags.length;
|
const length = formik?.values?.Questions?.[parent_index]?.tags.length;
|
||||||
const lastElement = formik?.values?.Questions?.[parent_index]?.tags[length - 1]?.name;
|
const lastElement = formik?.values?.Questions?.[parent_index]?.tags[length - 1]?.name;
|
||||||
set_Tags_search(null)
|
setTagsSearch(null)
|
||||||
|
|
||||||
if(lastElement !== ""){
|
if(lastElement !== ""){
|
||||||
formik.setFieldValue(`Questions.[${parent_index}].tags`, [...(formik?.values as any)?.Questions?.[parent_index]?.tags as any[],
|
formik.setFieldValue(`Questions.[${parent_index}].tags`, [...(formik?.values as any)?.Questions?.[parent_index]?.tags as any[],
|
||||||
|
|
@ -45,7 +45,7 @@ const handleChoice = (item: any) => {
|
||||||
console.log(currentTag);
|
console.log(currentTag);
|
||||||
|
|
||||||
formik.setFieldValue(`Questions.[${parent_index}].tags[${currentTag}]`, {...item,key:length});
|
formik.setFieldValue(`Questions.[${parent_index}].tags[${currentTag}]`, {...item,key:length});
|
||||||
set_Tags_search(null);
|
setTagsSearch(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -87,10 +87,10 @@ return (
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{Tags_search && current_parent_index === parent_index &&
|
{TagsSearch && currentParentIndex === parent_index &&
|
||||||
<div className="suggests">
|
<div className="suggests">
|
||||||
{suggests?.map((item:any,index:number)=>{
|
{suggests?.map((item:any,index:number)=>{
|
||||||
console.log(current_parent_index === parent_index);
|
console.log(currentParentIndex === parent_index);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='suggested' key={index} onClick={()=> handleChoice(item)}>
|
<div className='suggested' key={index} onClick={()=> handleChoice(item)}>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ const Tag = ({ data, index,parent_index }: { data: any, index: number,parent_ind
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
const DEBOUNCE_DELAY = 500;
|
const DEBOUNCE_DELAY = 500;
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const { set_Tags_search ,set_currentTag,set_current_parent_index} = useObjectToEdit();
|
const { setTagsSearch ,setCurrentTag,setCurrentParentIndex} = useObjectToEdit();
|
||||||
console.log(formik?.values?.Questions);
|
console.log(formik?.values?.Questions);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -22,14 +22,14 @@ const Tag = ({ data, index,parent_index }: { data: any, index: number,parent_ind
|
||||||
|
|
||||||
|
|
||||||
formik.setFieldValue(`Questions.[${parent_index}].tags[${index}]`, {key:parent_index, name :e.target.value , id:`${parent_index}_key`});
|
formik.setFieldValue(`Questions.[${parent_index}].tags[${index}]`, {key:parent_index, name :e.target.value , id:`${parent_index}_key`});
|
||||||
set_currentTag(index)
|
setCurrentTag(index)
|
||||||
set_current_parent_index(parent_index)
|
setCurrentParentIndex(parent_index)
|
||||||
if (timeoutRef.current) {
|
if (timeoutRef.current) {
|
||||||
clearTimeout(timeoutRef.current);
|
clearTimeout(timeoutRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeoutRef.current = setTimeout(() => {
|
timeoutRef.current = setTimeout(() => {
|
||||||
set_Tags_search(e.target.value)
|
setTagsSearch(e.target.value)
|
||||||
}, DEBOUNCE_DELAY);
|
}, DEBOUNCE_DELAY);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ const Tag = ({ data, index,parent_index }: { data: any, index: number,parent_ind
|
||||||
formik.setFieldValue(`Questions.[${parent_index}].tags`, currentTags);
|
formik.setFieldValue(`Questions.[${parent_index}].tags`, currentTags);
|
||||||
|
|
||||||
// Reset search state if needed
|
// Reset search state if needed
|
||||||
set_Tags_search(null);
|
setTagsSearch(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,18 @@ const DynamicTags = () => {
|
||||||
|
|
||||||
const formik = useFormikContext<any>()
|
const formik = useFormikContext<any>()
|
||||||
const [t] = useTranslation()
|
const [t] = useTranslation()
|
||||||
const { Tags_search ,set_Tags_search,currentTag} = useObjectToEdit();
|
const { TagsSearch ,setTagsSearch,currentTag} = useObjectToEdit();
|
||||||
const {data} = useGetAllTag({
|
const {data} = useGetAllTag({
|
||||||
name : Tags_search
|
name : TagsSearch
|
||||||
})
|
})
|
||||||
const suggests = data?.data
|
const suggests = data?.data
|
||||||
console.log(Tags_search);
|
console.log(TagsSearch);
|
||||||
|
|
||||||
|
|
||||||
const handleAddChoice = () => {
|
const handleAddChoice = () => {
|
||||||
const length = formik?.values?.tags.length;
|
const length = formik?.values?.tags.length;
|
||||||
const lastElement = formik?.values?.tags[length - 1]?.name;
|
const lastElement = formik?.values?.tags[length - 1]?.name;
|
||||||
set_Tags_search
|
setTagsSearch
|
||||||
if(lastElement !== ""){
|
if(lastElement !== ""){
|
||||||
formik.setFieldValue('tags', [...(formik?.values as any)?.tags as any[],
|
formik.setFieldValue('tags', [...(formik?.values as any)?.tags as any[],
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ const handleChoice = (item: any) => {
|
||||||
console.log(currentTag);
|
console.log(currentTag);
|
||||||
|
|
||||||
formik.setFieldValue(`tags[${currentTag}]`, {...item,key:length});
|
formik.setFieldValue(`tags[${currentTag}]`, {...item,key:length});
|
||||||
set_Tags_search(null);
|
setTagsSearch(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -86,7 +86,7 @@ return (
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
{Tags_search &&
|
{TagsSearch &&
|
||||||
<div className="suggests">
|
<div className="suggests">
|
||||||
{suggests?.map((item:any,index:number)=>{
|
{suggests?.map((item:any,index:number)=>{
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { FaTrash } from 'react-icons/fa';
|
||||||
const Tag = ({ data, index }: { data: any, index: number }) => {
|
const Tag = ({ data, index }: { data: any, index: number }) => {
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const { set_Tags_search ,set_currentTag} = useObjectToEdit();
|
const { setTagsSearch ,setCurrentTag} = useObjectToEdit();
|
||||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
const DEBOUNCE_DELAY = 500;
|
const DEBOUNCE_DELAY = 500;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -18,21 +18,21 @@ const Tag = ({ data, index }: { data: any, index: number }) => {
|
||||||
const handleEditInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleEditInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
// console.log(e.target.value);
|
// console.log(e.target.value);
|
||||||
formik.setFieldValue(`tags[${index}].name`, e.target.value);
|
formik.setFieldValue(`tags[${index}].name`, e.target.value);
|
||||||
// set_Tags_search(e.target.value)
|
// setTagsSearch(e.target.value)
|
||||||
formik.setFieldValue(`tags.[${index}]`, {key:index, name :e.target.value , id:`${index}_key`});
|
formik.setFieldValue(`tags.[${index}]`, {key:index, name :e.target.value , id:`${index}_key`});
|
||||||
|
|
||||||
set_currentTag(index)
|
setCurrentTag(index)
|
||||||
if (timeoutRef.current) {
|
if (timeoutRef.current) {
|
||||||
clearTimeout(timeoutRef.current);
|
clearTimeout(timeoutRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
timeoutRef.current = setTimeout(() => {
|
timeoutRef.current = setTimeout(() => {
|
||||||
set_Tags_search(e.target.value)
|
setTagsSearch(e.target.value)
|
||||||
}, DEBOUNCE_DELAY);
|
}, DEBOUNCE_DELAY);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleInputBlur = () => {
|
const handleInputBlur = () => {
|
||||||
// set_Tags_search(null)
|
// setTagsSearch(null)
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteChoice = () => {
|
const handleDeleteChoice = () => {
|
||||||
|
|
@ -50,7 +50,7 @@ const Tag = ({ data, index }: { data: any, index: number }) => {
|
||||||
formik.setFieldValue('tags', currentTags);
|
formik.setFieldValue('tags', currentTags);
|
||||||
|
|
||||||
// Reset search state if needed
|
// Reset search state if needed
|
||||||
set_Tags_search(null);
|
setTagsSearch(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,57 +1,35 @@
|
||||||
import { Space, TableColumnsType, Tooltip } from "antd";
|
import { Space, TableColumnsType, Tooltip } from "antd";
|
||||||
import { Question } from "../../types/Item";
|
import { Question } from "../../types/Item";
|
||||||
import { FaPlus } from "react-icons/fa";
|
import { FaPlus } from "react-icons/fa";
|
||||||
|
|
||||||
import useModalHandler from "../../utils/useModalHandler";
|
|
||||||
import { ModalEnum } from "../../enums/Model";
|
import { ModalEnum } from "../../enums/Model";
|
||||||
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
import { useObjectToEdit } from "../../zustand/ObjectToEditState";
|
||||||
import { RiDeleteBin6Fill } from "react-icons/ri";
|
import { RiDeleteBin6Fill } from "react-icons/ri";
|
||||||
import { MdOutlineEdit } from "react-icons/md";
|
import { MdOutlineEdit } from "react-icons/md";
|
||||||
import { findLabelByValue } from "../../utils/findLabelByValue";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { hasAbility } from "../../utils/hasAbility";
|
import { ABILITIES_ENUM } from "../../enums/abilities";
|
||||||
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../../enums/abilities";
|
|
||||||
import { formatNumber } from "../../utils/formatNumber";
|
|
||||||
import { BsEyeFill } from "react-icons/bs";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useModalState } from "../../zustand/Modal";
|
import { useModalState } from "../../zustand/Modal";
|
||||||
|
import { canAddQuestion, canDeleteQuestion, canEditQuestion } from "../../utils/hasAbilityFn";
|
||||||
|
|
||||||
export const useColumns = () => {
|
export const useColumns = () => {
|
||||||
const { handel_open_model } = useModalHandler();
|
const { setObjectToEdit } = useObjectToEdit((state) => state);
|
||||||
|
|
||||||
const { set_object_to_edit } = useObjectToEdit((state) => state);
|
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { setIsOpen } = useModalState((state) => state);
|
const { setIsOpen } = useModalState((state) => state);
|
||||||
|
|
||||||
const handelAdd = () => {
|
const handelAdd = () => {
|
||||||
set_object_to_edit({})
|
setObjectToEdit({})
|
||||||
navigate(`${ABILITIES_ENUM?.QUESTION}/add`)
|
navigate(`${ABILITIES_ENUM?.QUESTION}/add`)
|
||||||
};
|
};
|
||||||
|
|
||||||
const can_edit_Question = hasAbility(
|
|
||||||
ABILITIES_ENUM.QUESTION,
|
|
||||||
ABILITIES_VALUES_ENUM.UPDATE,
|
|
||||||
);
|
|
||||||
const can_delete_Question = hasAbility(
|
|
||||||
ABILITIES_ENUM.QUESTION,
|
|
||||||
ABILITIES_VALUES_ENUM.DELETE,
|
|
||||||
);
|
|
||||||
const can_add_Question = hasAbility(
|
|
||||||
ABILITIES_ENUM.QUESTION,
|
|
||||||
ABILITIES_VALUES_ENUM.STORE,
|
|
||||||
);
|
|
||||||
const can_show_Question = hasAbility(
|
|
||||||
ABILITIES_ENUM.QUESTION,
|
|
||||||
ABILITIES_VALUES_ENUM.SHOW,
|
|
||||||
);
|
|
||||||
const handelDelete = (data: any) => {
|
const handelDelete = (data: any) => {
|
||||||
set_object_to_edit(data);
|
setObjectToEdit(data);
|
||||||
setIsOpen(ModalEnum?.QUESTION_DELETE);
|
setIsOpen(ModalEnum?.QUESTION_DELETE);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEdit = (record: any) => {
|
const handleEdit = (record: any) => {
|
||||||
set_object_to_edit(record);
|
setObjectToEdit(record);
|
||||||
navigate(`${ABILITIES_ENUM?.QUESTION}/${record?.id}`)
|
navigate(`${ABILITIES_ENUM?.QUESTION}/${record?.id}`)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -71,6 +49,7 @@ export const useColumns = () => {
|
||||||
key: "name",
|
key: "name",
|
||||||
align: "center",
|
align: "center",
|
||||||
render: (text, record) => record?.content,
|
render: (text, record) => record?.content,
|
||||||
|
ellipsis:true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: t("columns.isBase"),
|
title: t("columns.isBase"),
|
||||||
|
|
@ -87,7 +66,7 @@ export const useColumns = () => {
|
||||||
render: (text, record) => record?.question_options_count,
|
render: (text, record) => record?.question_options_count,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: can_add_Question ? (
|
title: canAddQuestion ? (
|
||||||
<button
|
<button
|
||||||
onClick={() => handelAdd() }
|
onClick={() => handelAdd() }
|
||||||
className="add_button"
|
className="add_button"
|
||||||
|
|
@ -106,7 +85,7 @@ export const useColumns = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space size="middle" className={className}>
|
<Space size="middle" className={className}>
|
||||||
{can_edit_Question && (
|
{canEditQuestion && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
placement="top"
|
placement="top"
|
||||||
title={t("practical.edit")}
|
title={t("practical.edit")}
|
||||||
|
|
@ -121,7 +100,7 @@ export const useColumns = () => {
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{can_delete_Question && (
|
{canDeleteQuestion && (
|
||||||
<RiDeleteBin6Fill
|
<RiDeleteBin6Fill
|
||||||
onClick={() => handelDelete(record)}
|
onClick={() => handelDelete(record)}
|
||||||
size={22}
|
size={22}
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,12 @@ import { useTranslation } from "react-i18next";
|
||||||
const ModalForm: React.FC = () => {
|
const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
const { mutate, isSuccess, isLoading } = useAddSubject();
|
const { mutate, isSuccess, isLoading } = useAddSubject();
|
||||||
const { set_object_to_edit } = useObjectToEdit();
|
const { setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
}
|
}
|
||||||
}, [setIsOpen, isSuccess]);
|
}, [setIsOpen, isSuccess]);
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ const ModalForm: React.FC = () => {
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ const ModalForm: React.FC = () => {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useDeleteSubject();
|
const { mutate, isSuccess, isLoading } = useDeleteSubject();
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
const full_name = object_to_edit?.name;
|
const full_name = objectToEdit?.name;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
|
|
@ -24,14 +24,14 @@ const ModalForm: React.FC = () => {
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
mutate({
|
mutate({
|
||||||
id: Number(object_to_edit?.id),
|
id: Number(objectToEdit?.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setInputValue("");
|
setInputValue("");
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import { handelImageState } from "../../../utils/DataToSendImageState";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const ModalForm: React.FC = () => {
|
const ModalForm: React.FC = () => {
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit(
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit(
|
||||||
(state) => state,
|
(state) => state,
|
||||||
);
|
);
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
|
|
@ -21,7 +21,7 @@ const ModalForm: React.FC = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
}
|
}
|
||||||
}, [isSuccess]);
|
}, [isSuccess]);
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ const ModalForm: React.FC = () => {
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit(null);
|
setObjectToEdit(null);
|
||||||
};
|
};
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<Formik
|
<Formik
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
initialValues={getInitialValues(object_to_edit)}
|
initialValues={getInitialValues(objectToEdit)}
|
||||||
validationSchema={getValidationSchema}
|
validationSchema={getValidationSchema}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import React from 'react'
|
|
||||||
import { hasAbility } from '../../../utils/hasAbility';
|
|
||||||
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from '../../../enums/abilities';
|
|
||||||
import { ModalEnum } from '../../../enums/Model';
|
import { ModalEnum } from '../../../enums/Model';
|
||||||
import useModalHandler from '../../../utils/useModalHandler';
|
import useModalHandler from '../../../utils/useModalHandler';
|
||||||
import { FaPlus } from 'react-icons/fa';
|
import { FaPlus } from 'react-icons/fa';
|
||||||
|
|
@ -12,13 +10,11 @@ import AddSubjectModalForm from "../Model/AddModel";
|
||||||
import EditSubjectModalForm from "../Model/EditModel";
|
import EditSubjectModalForm from "../Model/EditModel";
|
||||||
import DeleteSubjectModalForm from "../Model/Delete";
|
import DeleteSubjectModalForm from "../Model/Delete";
|
||||||
import useSetPage_title from '../../../Hooks/useSetPageTitle';
|
import useSetPage_title from '../../../Hooks/useSetPageTitle';
|
||||||
|
import { canAddSubject } from '../../../utils/hasAbilityFn';
|
||||||
|
|
||||||
|
|
||||||
const TableWithHeader = () => {
|
const TableWithHeader = () => {
|
||||||
const store_subject_ability = hasAbility(
|
|
||||||
ABILITIES_ENUM?.SUBJECT,
|
|
||||||
ABILITIES_VALUES_ENUM?.STORE,
|
|
||||||
);
|
|
||||||
const { handel_open_model } = useModalHandler();
|
const { handel_open_model } = useModalHandler();
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
||||||
|
|
@ -30,7 +26,7 @@ const TableWithHeader = () => {
|
||||||
<div className="TableWithHeader">
|
<div className="TableWithHeader">
|
||||||
<header>
|
<header>
|
||||||
<h4 className="Bold Primary ">{t("models.subject")}</h4>
|
<h4 className="Bold Primary ">{t("models.subject")}</h4>
|
||||||
{store_subject_ability && (
|
{canAddSubject && (
|
||||||
<button
|
<button
|
||||||
onClick={() => handel_open_model(ModalEnum?.SUBJECT_ADD)}
|
onClick={() => handel_open_model(ModalEnum?.SUBJECT_ADD)}
|
||||||
className="add_button"
|
className="add_button"
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,20 @@ import {
|
||||||
ABILITIES_VALUES_ENUM,
|
ABILITIES_VALUES_ENUM,
|
||||||
} from "../../../enums/abilities";
|
} from "../../../enums/abilities";
|
||||||
import { hasAbility } from "../../../utils/hasAbility";
|
import { hasAbility } from "../../../utils/hasAbility";
|
||||||
|
import { canDeleteSubject, canEditSubject } from "../../../utils/hasAbilityFn";
|
||||||
|
|
||||||
export const useColumns = () => {
|
export const useColumns = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { set_object_to_edit } = useObjectToEdit((state) => state);
|
const { setObjectToEdit } = useObjectToEdit((state) => state);
|
||||||
const { handel_open_model } = useModalHandler();
|
const { handel_open_model } = useModalHandler();
|
||||||
|
|
||||||
const handelDeleteSubject = (data: any) => {
|
const handelDeleteSubject = (data: any) => {
|
||||||
set_object_to_edit(data);
|
setObjectToEdit(data);
|
||||||
handel_open_model(ModalEnum?.SUBJECT_DELETE);
|
handel_open_model(ModalEnum?.SUBJECT_DELETE);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEdit = (record: any) => {
|
const handleEdit = (record: any) => {
|
||||||
set_object_to_edit(record);
|
setObjectToEdit(record);
|
||||||
handel_open_model(ModalEnum?.SUBJECT_EDIT);
|
handel_open_model(ModalEnum?.SUBJECT_EDIT);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -83,18 +84,11 @@ export const useColumns = () => {
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
const className =
|
const className =
|
||||||
index % 2 === 0 ? "even-row buttonAction" : "odd-row buttonAction";
|
index % 2 === 0 ? "even-row buttonAction" : "odd-row buttonAction";
|
||||||
const edit_subject_ability = hasAbility(
|
|
||||||
ABILITIES_ENUM?.SUBJECT,
|
|
||||||
ABILITIES_VALUES_ENUM?.UPDATE,
|
|
||||||
);
|
|
||||||
const delete_subject_ability = hasAbility(
|
|
||||||
ABILITIES_ENUM?.SUBJECT,
|
|
||||||
ABILITIES_VALUES_ENUM?.DELETE,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space size="middle" className={className}>
|
<Space size="middle" className={className}>
|
||||||
{edit_subject_ability && (
|
{canEditSubject && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
placement="top"
|
placement="top"
|
||||||
title={t("practical.edit")}
|
title={t("practical.edit")}
|
||||||
|
|
@ -109,7 +103,7 @@ export const useColumns = () => {
|
||||||
</span>
|
</span>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
{delete_subject_ability && (
|
{canDeleteSubject && (
|
||||||
<RiDeleteBin6Fill
|
<RiDeleteBin6Fill
|
||||||
onClick={() => handelDeleteSubject(record)}
|
onClick={() => handelDeleteSubject(record)}
|
||||||
size={22}
|
size={22}
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ const ModalForm: React.FC = () => {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useDeleteUnit();
|
const { mutate, isSuccess, isLoading } = useDeleteUnit();
|
||||||
const { object_to_edit } = useObjectToEdit((state) => state);
|
const { objectToEdit } = useObjectToEdit((state) => state);
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
mutate({
|
mutate({
|
||||||
id: Number(object_to_edit?.id),
|
id: Number(objectToEdit?.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
{" "}
|
{" "}
|
||||||
{t("practical.delete")} {object_to_edit?.name}{" "}
|
{t("practical.delete")} {objectToEdit?.name}{" "}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main className="main_modal">
|
<main className="main_modal">
|
||||||
|
|
@ -74,9 +74,9 @@ const ModalForm: React.FC = () => {
|
||||||
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
object_to_edit?.name !== inputValue ? "disabled_button" : ""
|
objectToEdit?.name !== inputValue ? "disabled_button" : ""
|
||||||
}
|
}
|
||||||
disabled={object_to_edit?.name !== inputValue || isLoading}
|
disabled={objectToEdit?.name !== inputValue || isLoading}
|
||||||
// onClick={handleSubmit}
|
// onClick={handleSubmit}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@ const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useUpdateUnit();
|
const { mutate, isSuccess, isLoading } = useUpdateUnit();
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
// console.log(object_to_edit,"object_to_edit");
|
// console.log(objectToEdit,"objectToEdit");
|
||||||
const { subject_id } = useParams();
|
const { subject_id } = useParams();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -50,7 +50,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<FormikForm
|
<FormikForm
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
initialValues={getInitialValues(object_to_edit)}
|
initialValues={getInitialValues(objectToEdit)}
|
||||||
validationSchema={getValidationSchema}
|
validationSchema={getValidationSchema}
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,17 @@ import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const genExtra = (
|
const genExtra = (
|
||||||
item: Unit,
|
item: Unit,
|
||||||
set_object_to_edit: any,
|
setObjectToEdit: any,
|
||||||
handel_open_model: any,
|
handel_open_model: any,
|
||||||
t: any,
|
t: any,
|
||||||
) => {
|
) => {
|
||||||
const handelDelete = (event: any, item: Unit) => {
|
const handelDelete = (event: any, item: Unit) => {
|
||||||
handel_open_model(ModalEnum?.UNIT_DELETE);
|
handel_open_model(ModalEnum?.UNIT_DELETE);
|
||||||
set_object_to_edit(item);
|
setObjectToEdit(item);
|
||||||
};
|
};
|
||||||
const handleEdit = (event: any, item: Unit) => {
|
const handleEdit = (event: any, item: Unit) => {
|
||||||
// console.log(item,"event");
|
// console.log(item,"event");
|
||||||
set_object_to_edit(item);
|
setObjectToEdit(item);
|
||||||
handel_open_model(ModalEnum?.UNIT_EDIT);
|
handel_open_model(ModalEnum?.UNIT_EDIT);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ const genExtra = (
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
const { handel_open_model } = useModalHandler();
|
const { handel_open_model } = useModalHandler();
|
||||||
const { set_object_to_edit } = useObjectToEdit();
|
const { setObjectToEdit } = useObjectToEdit();
|
||||||
const { subject_id } = useParams();
|
const { subject_id } = useParams();
|
||||||
|
|
||||||
const panelStyle: React.CSSProperties = {
|
const panelStyle: React.CSSProperties = {
|
||||||
|
|
@ -78,7 +78,7 @@ const App: React.FC = () => {
|
||||||
label: item?.name,
|
label: item?.name,
|
||||||
children: <Lessons unit_id={item?.id} data={item?.lessons} />,
|
children: <Lessons unit_id={item?.id} data={item?.lessons} />,
|
||||||
style: panelStyle,
|
style: panelStyle,
|
||||||
extra: genExtra(item, set_object_to_edit, handel_open_model, t),
|
extra: genExtra(item, setObjectToEdit, handel_open_model, t),
|
||||||
})) || [];
|
})) || [];
|
||||||
|
|
||||||
// console.log(units,"units");
|
// console.log(units,"units");
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,19 @@ import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const Lessons = ({ data, unit_id }: { data: Lesson[]; unit_id: number }) => {
|
const Lessons = ({ data, unit_id }: { data: Lesson[]; unit_id: number }) => {
|
||||||
const { handel_open_model } = useModalHandler();
|
const { handel_open_model } = useModalHandler();
|
||||||
const { set_object_to_edit } = useObjectToEdit();
|
const { setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
const handelDelete = (item: Lesson) => {
|
const handelDelete = (item: Lesson) => {
|
||||||
handel_open_model(ModalEnum?.LESSON_DELETE);
|
handel_open_model(ModalEnum?.LESSON_DELETE);
|
||||||
set_object_to_edit(item);
|
setObjectToEdit(item);
|
||||||
};
|
};
|
||||||
const handleEdit = (item: Lesson) => {
|
const handleEdit = (item: Lesson) => {
|
||||||
// console.log(item,"event");
|
// console.log(item,"event");
|
||||||
set_object_to_edit(item);
|
setObjectToEdit(item);
|
||||||
handel_open_model(ModalEnum?.LESSON_EDIT);
|
handel_open_model(ModalEnum?.LESSON_EDIT);
|
||||||
};
|
};
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
set_object_to_edit({ unit_id: unit_id });
|
setObjectToEdit({ unit_id: unit_id });
|
||||||
handel_open_model(ModalEnum?.LESSON_ADD);
|
handel_open_model(ModalEnum?.LESSON_ADD);
|
||||||
};
|
};
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
const ModalForm: React.FC = () => {
|
const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ const ModalForm: React.FC = () => {
|
||||||
}, [setIsOpen, isSuccess, queryClient]);
|
}, [setIsOpen, isSuccess, queryClient]);
|
||||||
|
|
||||||
const handleSubmit = (values: any) => {
|
const handleSubmit = (values: any) => {
|
||||||
mutate({ ...values, unit_id: object_to_edit?.unit_id });
|
mutate({ ...values, unit_id: objectToEdit?.unit_id });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ const ModalForm: React.FC = () => {
|
||||||
const [inputValue, setInputValue] = useState("");
|
const [inputValue, setInputValue] = useState("");
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useDeleteLesson();
|
const { mutate, isSuccess, isLoading } = useDeleteLesson();
|
||||||
const { object_to_edit } = useObjectToEdit((state) => state);
|
const { objectToEdit } = useObjectToEdit((state) => state);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
mutate({
|
mutate({
|
||||||
id: Number(object_to_edit?.id),
|
id: Number(objectToEdit?.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -32,7 +32,7 @@ const ModalForm: React.FC = () => {
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setInputValue("");
|
setInputValue("");
|
||||||
setIsOpen("");
|
setIsOpen("");
|
||||||
set_object_to_edit({});
|
setObjectToEdit({});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
@ -51,7 +51,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
{" "}
|
{" "}
|
||||||
{t("practical.delete")} {object_to_edit?.name}{" "}
|
{t("practical.delete")} {objectToEdit?.name}{" "}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main className="main_modal">
|
<main className="main_modal">
|
||||||
|
|
@ -74,9 +74,9 @@ const ModalForm: React.FC = () => {
|
||||||
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
<div onClick={handleCancel}>{t("practical.cancel")}</div>
|
||||||
<button
|
<button
|
||||||
className={
|
className={
|
||||||
object_to_edit?.name !== inputValue ? "disabled_button" : ""
|
objectToEdit?.name !== inputValue ? "disabled_button" : ""
|
||||||
}
|
}
|
||||||
disabled={object_to_edit?.name !== inputValue || isLoading}
|
disabled={objectToEdit?.name !== inputValue || isLoading}
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
>
|
>
|
||||||
{t("practical.delete")}
|
{t("practical.delete")}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ const ModalForm: React.FC = () => {
|
||||||
const { isOpen, setIsOpen } = useModalState((state) => state);
|
const { isOpen, setIsOpen } = useModalState((state) => state);
|
||||||
|
|
||||||
const { mutate, isSuccess, isLoading } = useUpdateLesson();
|
const { mutate, isSuccess, isLoading } = useUpdateLesson();
|
||||||
const { object_to_edit, set_object_to_edit } = useObjectToEdit();
|
const { objectToEdit, setObjectToEdit } = useObjectToEdit();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
// console.log(object_to_edit,"object_to_edit");
|
// console.log(objectToEdit,"objectToEdit");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
|
|
@ -53,7 +53,7 @@ const ModalForm: React.FC = () => {
|
||||||
>
|
>
|
||||||
<FormikForm
|
<FormikForm
|
||||||
handleSubmit={handleSubmit}
|
handleSubmit={handleSubmit}
|
||||||
initialValues={getInitialValues(object_to_edit)}
|
initialValues={getInitialValues(objectToEdit)}
|
||||||
validationSchema={getValidationSchema}
|
validationSchema={getValidationSchema}
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ export const CrudRoute: TCrudRoute[] = [
|
||||||
path: `/${ABILITIES_ENUM?.SUBJECT}/:${ParamsEnum?.SUBJECT_ID}/${ABILITIES_ENUM?.UNIT}/:${ParamsEnum?.UNIT_ID}/${ABILITIES_ENUM?.LESSON}/:${ParamsEnum?.LESSON_ID}/${ABILITIES_ENUM?.QUESTION}/add`,
|
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: ABILITIES_ENUM?.QUESTION,
|
||||||
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
||||||
prevPath: 0,
|
prevPath: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "page_header.edit_Question",
|
header: "page_header.edit_Question",
|
||||||
|
|
@ -108,7 +108,7 @@ export const CrudRoute: TCrudRoute[] = [
|
||||||
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}`,
|
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: ABILITIES_ENUM?.QUESTION,
|
||||||
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
abilities_value: ABILITIES_VALUES_ENUM.INDEX,
|
||||||
prevPath: 0,
|
prevPath: 2,
|
||||||
},
|
},
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
margin-inline: auto;
|
margin-inline: auto;
|
||||||
height: 60%;
|
height: 60%;
|
||||||
content: "";
|
content: "";
|
||||||
background: url("../../../public/Layout/auth_bg.png");
|
background: url("../../../public/Layout/BackgroundHeader.webp");
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
|
|
||||||
background-image: url("../../../public/Layout/Background_Header.svg");
|
background-image: url("../../../public/Layout/BackgroundHeader.webp");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
export const BaseURL = "https://exercise-automation.point-dev.net/api/";
|
export const BaseURL = "https://exercise-automation.point-dev.net/api/";
|
||||||
|
|
||||||
export const ImageBaseURL = "http://192.168.1.9:8000/";
|
// export const ImageBaseURL = "http://192.168.1.9:8000/";
|
||||||
|
|
||||||
// export const ImageBaseURL = "https://school-back-dev.point-dev.net/";
|
export const ImageBaseURL = "https://exercise-automation.point-dev.net/";
|
||||||
export const HEADER_KEY = "X-Custom-Query-Key";
|
export const HEADER_KEY = "X-Custom-Query-Key";
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@ function useGetQuery(
|
||||||
|
|
||||||
const { page, per_page } = PaginationParams(location);
|
const { page, per_page } = PaginationParams(location);
|
||||||
|
|
||||||
const param_to_send = pagination
|
const paramToSend = pagination
|
||||||
? { ...remainingParams, page: page, per_page: per_page }
|
? { ...remainingParams, page: page, per_page: per_page }
|
||||||
: { ...remainingParams };
|
: { ...remainingParams };
|
||||||
|
|
||||||
const filteredParams = filterParams(param_to_send);
|
const filteredParams = filterParams(paramToSend);
|
||||||
|
|
||||||
return useQuery(
|
return useQuery(
|
||||||
[KEY, filteredParams, show],
|
[KEY, filteredParams, show],
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
import React from "react";
|
|
||||||
|
|
||||||
const Course = () => {
|
|
||||||
return <div></div>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Course;
|
|
||||||
521
src/utils/hasAbilityFn.ts
Normal file
|
|
@ -0,0 +1,521 @@
|
||||||
|
import { ABILITIES_ENUM, ABILITIES_VALUES_ENUM } from "../enums/abilities";
|
||||||
|
import { hasAbility } from "./hasAbility";
|
||||||
|
|
||||||
|
///// EduClass
|
||||||
|
|
||||||
|
export const canAddEduClass = hasAbility(
|
||||||
|
ABILITIES_ENUM.EDUCATION_CLASS,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
export const canEditEduClass = hasAbility(
|
||||||
|
ABILITIES_ENUM.EDUCATION_CLASS,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteEduClass = hasAbility(
|
||||||
|
ABILITIES_ENUM.EDUCATION_CLASS,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowEduClass = hasAbility(
|
||||||
|
ABILITIES_ENUM.EDUCATION_CLASS,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
export const canIndexEduClass = hasAbility(
|
||||||
|
ABILITIES_ENUM.EDUCATION_CLASS,
|
||||||
|
ABILITIES_VALUES_ENUM.INDEX,
|
||||||
|
);
|
||||||
|
|
||||||
|
///// Course
|
||||||
|
|
||||||
|
export const canAddCourse = hasAbility(
|
||||||
|
ABILITIES_ENUM.COURSE,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
export const canEditCourse = hasAbility(
|
||||||
|
ABILITIES_ENUM.COURSE,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteCourse = hasAbility(
|
||||||
|
ABILITIES_ENUM.COURSE,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowCourse = hasAbility(
|
||||||
|
ABILITIES_ENUM.COURSE,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
export const canIndexCourse = hasAbility(
|
||||||
|
ABILITIES_ENUM.COURSE,
|
||||||
|
ABILITIES_VALUES_ENUM.INDEX,
|
||||||
|
);
|
||||||
|
|
||||||
|
///// session
|
||||||
|
|
||||||
|
export const canAddSession = hasAbility(
|
||||||
|
ABILITIES_ENUM.SESSION,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
export const canEditSession = hasAbility(
|
||||||
|
ABILITIES_ENUM.SESSION,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteSession = hasAbility(
|
||||||
|
ABILITIES_ENUM.SESSION,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
|
||||||
|
//// teacher
|
||||||
|
|
||||||
|
export const canEditTeacher = hasAbility(
|
||||||
|
ABILITIES_ENUM.TEACHER,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteTeacher = hasAbility(
|
||||||
|
ABILITIES_ENUM.TEACHER,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canAddTeacher = hasAbility(
|
||||||
|
ABILITIES_ENUM.TEACHER,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
//// unit
|
||||||
|
export const canAddUnit = hasAbility(
|
||||||
|
ABILITIES_ENUM.UNIT,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditUnit = hasAbility(
|
||||||
|
ABILITIES_ENUM.UNIT,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteUnit = hasAbility(
|
||||||
|
ABILITIES_ENUM.UNIT,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowUnit = hasAbility(
|
||||||
|
ABILITIES_ENUM.UNIT,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// subject
|
||||||
|
|
||||||
|
export const canAddSubject = hasAbility(
|
||||||
|
ABILITIES_ENUM.SUBJECT,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditSubject = hasAbility(
|
||||||
|
ABILITIES_ENUM.SUBJECT,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteSubject = hasAbility(
|
||||||
|
ABILITIES_ENUM.SUBJECT,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Role
|
||||||
|
|
||||||
|
export const canAddRole = hasAbility(
|
||||||
|
ABILITIES_ENUM.ROLE,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditRole = hasAbility(
|
||||||
|
ABILITIES_ENUM.ROLE,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteRole = hasAbility(
|
||||||
|
ABILITIES_ENUM.ROLE,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Payment
|
||||||
|
|
||||||
|
export const canIndexPayment = hasAbility(
|
||||||
|
ABILITIES_ENUM.PAYMENT,
|
||||||
|
ABILITIES_VALUES_ENUM.INDEX,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canAddPayment = hasAbility(
|
||||||
|
ABILITIES_ENUM.PAYMENT,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditPayment = hasAbility(
|
||||||
|
ABILITIES_ENUM.PAYMENT,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeletePayment = hasAbility(
|
||||||
|
ABILITIES_ENUM.PAYMENT,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Lesson
|
||||||
|
|
||||||
|
export const canAddLesson = hasAbility(
|
||||||
|
ABILITIES_ENUM.LESSON,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditLesson = hasAbility(
|
||||||
|
ABILITIES_ENUM.LESSON,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteLesson = hasAbility(
|
||||||
|
ABILITIES_ENUM.LESSON,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowLesson = hasAbility(
|
||||||
|
ABILITIES_ENUM.LESSON,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Exercise
|
||||||
|
|
||||||
|
export const canAddExercise = hasAbility(
|
||||||
|
ABILITIES_ENUM.EXERCISE,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditExercise = hasAbility(
|
||||||
|
ABILITIES_ENUM.EXERCISE,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteExercise = hasAbility(
|
||||||
|
ABILITIES_ENUM.EXERCISE,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Cycle
|
||||||
|
|
||||||
|
export const canAddCycle = hasAbility(
|
||||||
|
ABILITIES_ENUM.CYCLE,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditCycle = hasAbility(
|
||||||
|
ABILITIES_ENUM.CYCLE,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteCycle = hasAbility(
|
||||||
|
ABILITIES_ENUM.CYCLE,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowCycle = hasAbility(
|
||||||
|
ABILITIES_ENUM.CYCLE,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Admin
|
||||||
|
|
||||||
|
export const canAddAdmin = hasAbility(
|
||||||
|
ABILITIES_ENUM.ADMIN,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditAdmin = hasAbility(
|
||||||
|
ABILITIES_ENUM.ADMIN,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteAdmin = hasAbility(
|
||||||
|
ABILITIES_ENUM.ADMIN,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowAdmin = hasAbility(
|
||||||
|
ABILITIES_ENUM.ADMIN,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Term
|
||||||
|
|
||||||
|
export const canAddTerm = hasAbility(
|
||||||
|
ABILITIES_ENUM.TERM,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditTerm = hasAbility(
|
||||||
|
ABILITIES_ENUM.TERM,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteTerm = hasAbility(
|
||||||
|
ABILITIES_ENUM.TERM,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowTerm = hasAbility(
|
||||||
|
ABILITIES_ENUM.TERM,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Student
|
||||||
|
|
||||||
|
export const canAddStudent = hasAbility(
|
||||||
|
ABILITIES_ENUM.STUDENT,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditStudent = hasAbility(
|
||||||
|
ABILITIES_ENUM.STUDENT,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteStudent = hasAbility(
|
||||||
|
ABILITIES_ENUM.STUDENT,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowStudent = hasAbility(
|
||||||
|
ABILITIES_ENUM.STUDENT,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canImportStudent = hasAbility(
|
||||||
|
ABILITIES_ENUM.STUDENT,
|
||||||
|
ABILITIES_VALUES_ENUM.IMPORT_STUDENTS,
|
||||||
|
);
|
||||||
|
export const canMoveStudent = hasAbility(
|
||||||
|
ABILITIES_ENUM.STUDENT,
|
||||||
|
ABILITIES_VALUES_ENUM.MOVE_STUDENTS,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// EarlyDeparture
|
||||||
|
|
||||||
|
export const canAddEarlyDeparture = hasAbility(
|
||||||
|
ABILITIES_ENUM.EARLY_DEPARTURE,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditEarlyDeparture = hasAbility(
|
||||||
|
ABILITIES_ENUM.EARLY_DEPARTURE,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteEarlyDeparture = hasAbility(
|
||||||
|
ABILITIES_ENUM.EARLY_DEPARTURE,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowEarlyDeparture = hasAbility(
|
||||||
|
ABILITIES_ENUM.EARLY_DEPARTURE,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Exam
|
||||||
|
|
||||||
|
export const canAddExam = hasAbility(
|
||||||
|
ABILITIES_ENUM.EXAM,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditExam = hasAbility(
|
||||||
|
ABILITIES_ENUM.EXAM,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteExam = hasAbility(
|
||||||
|
ABILITIES_ENUM.EXAM,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowExam = hasAbility(
|
||||||
|
ABILITIES_ENUM.EXAM,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// HomeWork
|
||||||
|
|
||||||
|
export const canAddHomeWork = hasAbility(
|
||||||
|
ABILITIES_ENUM.HOMEWORK,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditHomeWork = hasAbility(
|
||||||
|
ABILITIES_ENUM.HOMEWORK,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteHomeWork = hasAbility(
|
||||||
|
ABILITIES_ENUM.HOMEWORK,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowHomeWork = hasAbility(
|
||||||
|
ABILITIES_ENUM.HOMEWORK,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Mark
|
||||||
|
|
||||||
|
export const canAddMark = hasAbility(
|
||||||
|
ABILITIES_ENUM.MARK,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditMark = hasAbility(
|
||||||
|
ABILITIES_ENUM.MARK,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteMark = hasAbility(
|
||||||
|
ABILITIES_ENUM.MARK,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowMark = hasAbility(
|
||||||
|
ABILITIES_ENUM.MARK,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Note
|
||||||
|
|
||||||
|
export const canAddNote = hasAbility(
|
||||||
|
ABILITIES_ENUM.NOTE,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditNote = hasAbility(
|
||||||
|
ABILITIES_ENUM.NOTE,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteNote = hasAbility(
|
||||||
|
ABILITIES_ENUM.NOTE,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowNote = hasAbility(
|
||||||
|
ABILITIES_ENUM.NOTE,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Absence
|
||||||
|
|
||||||
|
export const canAddAbsence = hasAbility(
|
||||||
|
ABILITIES_ENUM.ABSENCE,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditAbsence = hasAbility(
|
||||||
|
ABILITIES_ENUM.ABSENCE,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteAbsence = hasAbility(
|
||||||
|
ABILITIES_ENUM.ABSENCE,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowAbsence = hasAbility(
|
||||||
|
ABILITIES_ENUM.ABSENCE,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// SessionContent
|
||||||
|
|
||||||
|
export const canAddSessionContent = hasAbility(
|
||||||
|
ABILITIES_ENUM.SESSION_CONTENT,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditSessionContent = hasAbility(
|
||||||
|
ABILITIES_ENUM.SESSION_CONTENT,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteSessionContent = hasAbility(
|
||||||
|
ABILITIES_ENUM.SESSION_CONTENT,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowSessionContent = hasAbility(
|
||||||
|
ABILITIES_ENUM.SESSION_CONTENT,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// Branch
|
||||||
|
|
||||||
|
export const canAddBranch = hasAbility(
|
||||||
|
ABILITIES_ENUM.BRANCH,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditBranch = hasAbility(
|
||||||
|
ABILITIES_ENUM.BRANCH,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteBranch = hasAbility(
|
||||||
|
ABILITIES_ENUM.BRANCH,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowBranch = hasAbility(
|
||||||
|
ABILITIES_ENUM.BRANCH,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// status
|
||||||
|
|
||||||
|
export const canIndexStatus =
|
||||||
|
hasAbility(ABILITIES_ENUM.EARLY_DEPARTURE, ABILITIES_VALUES_ENUM.INDEX) &&
|
||||||
|
hasAbility(ABILITIES_ENUM.ABSENCE, ABILITIES_VALUES_ENUM.INDEX) &&
|
||||||
|
hasAbility(ABILITIES_ENUM.LATE_ARRIVAL, ABILITIES_VALUES_ENUM.INDEX) &&
|
||||||
|
hasAbility(ABILITIES_ENUM.PRESENCE, ABILITIES_VALUES_ENUM.INDEX);
|
||||||
|
|
||||||
|
export const canUpdateStatus =
|
||||||
|
hasAbility(ABILITIES_ENUM.EARLY_DEPARTURE, ABILITIES_VALUES_ENUM.UPDATE) &&
|
||||||
|
hasAbility(ABILITIES_ENUM.ABSENCE, ABILITIES_VALUES_ENUM.UPDATE) &&
|
||||||
|
hasAbility(ABILITIES_ENUM.LATE_ARRIVAL, ABILITIES_VALUES_ENUM.UPDATE);
|
||||||
|
|
||||||
|
export const canAddStatus =
|
||||||
|
hasAbility(ABILITIES_ENUM.EARLY_DEPARTURE, ABILITIES_VALUES_ENUM.STORE) &&
|
||||||
|
hasAbility(ABILITIES_ENUM.ABSENCE, ABILITIES_VALUES_ENUM.STORE) &&
|
||||||
|
hasAbility(ABILITIES_ENUM.LATE_ARRIVAL, ABILITIES_VALUES_ENUM.STORE);
|
||||||
|
|
||||||
|
/// notification
|
||||||
|
|
||||||
|
export const canAddNotification = hasAbility(
|
||||||
|
ABILITIES_ENUM.NOTE,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
/// MarksReport
|
||||||
|
|
||||||
|
export const canAddMarksReport = hasAbility(
|
||||||
|
ABILITIES_ENUM.MARK,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditMarksReport = hasAbility(
|
||||||
|
ABILITIES_ENUM.MARK,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteMarksReport = hasAbility(
|
||||||
|
ABILITIES_ENUM.MARK,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowMarksReport = hasAbility(
|
||||||
|
ABILITIES_ENUM.MARK,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
/// Tags
|
||||||
|
|
||||||
|
|
||||||
|
export const canAddTags = hasAbility(
|
||||||
|
ABILITIES_ENUM.TAG,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditTags = hasAbility(
|
||||||
|
ABILITIES_ENUM.TAG,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteTags = hasAbility(
|
||||||
|
ABILITIES_ENUM.TAG,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowTags = hasAbility(
|
||||||
|
ABILITIES_ENUM.TAG,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/// Question
|
||||||
|
|
||||||
|
export const canAddQuestion = hasAbility(
|
||||||
|
ABILITIES_ENUM.QUESTION,
|
||||||
|
ABILITIES_VALUES_ENUM.STORE,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const canEditQuestion = hasAbility(
|
||||||
|
ABILITIES_ENUM.QUESTION,
|
||||||
|
ABILITIES_VALUES_ENUM.UPDATE,
|
||||||
|
);
|
||||||
|
export const canDeleteQuestion = hasAbility(
|
||||||
|
ABILITIES_ENUM.QUESTION,
|
||||||
|
ABILITIES_VALUES_ENUM.DELETE,
|
||||||
|
);
|
||||||
|
export const canShowQuestion = hasAbility(
|
||||||
|
ABILITIES_ENUM.QUESTION,
|
||||||
|
ABILITIES_VALUES_ENUM.SHOW,
|
||||||
|
);
|
||||||
|
|
@ -1,56 +1,48 @@
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
interface ModelState {
|
interface ModelState {
|
||||||
object_to_edit: any;
|
objectToEdit: any;
|
||||||
set_object_to_edit: (data: any) => void;
|
setObjectToEdit: (data: any) => void;
|
||||||
old_object_to_edit: any;
|
paramToSend: any;
|
||||||
set_old_object_to_edit: (data: any) => void;
|
setParamToSend: (data: any) => void;
|
||||||
object_ids: any;
|
TagsSearch: any;
|
||||||
set_object_ids: (data: any) => void;
|
setTagsSearch: (data: any) => void;
|
||||||
param_to_send: any;
|
TagsQuery: any;
|
||||||
set_param_to_send: (data: any) => void;
|
setTagsQuery: (data: any) => void;
|
||||||
Tags_search: any;
|
|
||||||
set_Tags_search: (data: any) => void;
|
|
||||||
Tags_query: any;
|
|
||||||
set_Tags_query: (data: any) => void;
|
|
||||||
currentTag: any;
|
currentTag: any;
|
||||||
set_currentTag: (data: any) => void;
|
setCurrentTag: (data: any) => void;
|
||||||
current_parent_index: any;
|
currentParentIndex: any;
|
||||||
set_current_parent_index: (data: any) => void;
|
setCurrentParentIndex: (data: any) => void;
|
||||||
isBseQuestion: boolean;
|
isBseQuestion: boolean;
|
||||||
set_isBseQuestion: (data: any) => void;
|
setIsBseQuestion: (data: any) => void;
|
||||||
Success: boolean;
|
Success: boolean;
|
||||||
set_Success: (data: any) => void;
|
setSuccess: (data: any) => void;
|
||||||
DeletedQuestions: any;
|
DeletedQuestions: any;
|
||||||
set_DeletedQuestions: (data: any) => void;
|
setDeletedQuestions: (data: any) => void;
|
||||||
|
|
||||||
SavedQuestionData: any;
|
SavedQuestionData: any;
|
||||||
set_SavedQuestionData: (data: any) => void;
|
setSavedQuestionData: (data: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useObjectToEdit = create<ModelState>((set) => ({
|
export const useObjectToEdit = create<ModelState>((set) => ({
|
||||||
object_to_edit: null,
|
objectToEdit: null,
|
||||||
set_object_to_edit: (data) => set(() => ({ object_to_edit: data })),
|
setObjectToEdit: (data) => set(() => ({ objectToEdit: data })),
|
||||||
old_object_to_edit: null,
|
paramToSend: {},
|
||||||
set_old_object_to_edit: (data) => set(() => ({ old_object_to_edit: data })),
|
setParamToSend: (data) => set(() => ({ paramToSend: data })),
|
||||||
object_ids: [],
|
TagsSearch: null,
|
||||||
set_object_ids: (data) => set(() => ({ object_ids: data })),
|
setTagsSearch: (data) => set(() => ({ TagsSearch: data })),
|
||||||
param_to_send: {},
|
TagsQuery: null,
|
||||||
set_param_to_send: (data) => set(() => ({ param_to_send: data })),
|
setTagsQuery: (data) => set(() => ({ TagsQuery: data })),
|
||||||
Tags_search: null,
|
|
||||||
set_Tags_search: (data) => set(() => ({ Tags_search: data })),
|
|
||||||
Tags_query: null,
|
|
||||||
set_Tags_query: (data) => set(() => ({ Tags_query: data })),
|
|
||||||
currentTag: null,
|
currentTag: null,
|
||||||
set_currentTag: (data) => set(() => ({ currentTag: data })),
|
setCurrentTag: (data) => set(() => ({ currentTag: data })),
|
||||||
current_parent_index: null,
|
currentParentIndex: null,
|
||||||
set_current_parent_index: (data) => set(() => ({ current_parent_index: data })),
|
setCurrentParentIndex: (data) => set(() => ({ currentParentIndex: data })),
|
||||||
isBseQuestion: false,
|
isBseQuestion: false,
|
||||||
set_isBseQuestion: (data) => set(() => ({ isBseQuestion: data })),
|
setIsBseQuestion: (data) => set(() => ({ isBseQuestion: data })),
|
||||||
Success: false,
|
Success: false,
|
||||||
set_Success: (data) => set(() => ({ Success: data })),
|
setSuccess: (data) => set(() => ({ Success: data })),
|
||||||
DeletedQuestions: [],
|
DeletedQuestions: [],
|
||||||
set_DeletedQuestions: (data) => set(() => ({ DeletedQuestions: data })),
|
setDeletedQuestions: (data) => set(() => ({ DeletedQuestions: data })),
|
||||||
SavedQuestionData: [],
|
SavedQuestionData: [],
|
||||||
set_SavedQuestionData: (data) => set(() => ({ SavedQuestionData: data })),
|
setSavedQuestionData: (data) => set(() => ({ SavedQuestionData: data })),
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||