Compare commits
4 Commits
edd50bafad
...
c858803cb0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c858803cb0 | ||
|
|
de71606e88 | ||
|
|
05d0a12527 | ||
|
|
32f87910ea |
|
|
@ -27,6 +27,7 @@ const ImageBoxField = ({ name }: any) => {
|
||||||
|
|
||||||
const handleFileChange = (event: any) => {
|
const handleFileChange = (event: any) => {
|
||||||
const file = event.target.files[0];
|
const file = event.target.files[0];
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
const maxSize = 2 * 1024 * 1024;
|
const maxSize = 2 * 1024 * 1024;
|
||||||
|
|
||||||
|
|
@ -42,6 +43,8 @@ const ImageBoxField = ({ name }: any) => {
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
generateImagePreview(file, setImagePreview);
|
generateImagePreview(file, setImagePreview);
|
||||||
|
console.log(file,"file");
|
||||||
|
|
||||||
formik.setFieldValue(name, file);
|
formik.setFieldValue(name, file);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -55,7 +58,7 @@ const ImageBoxField = ({ name }: any) => {
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setImagePreview("");
|
setImagePreview("");
|
||||||
formik.setFieldValue(name, "");
|
formik.setFieldValue(name, null);
|
||||||
|
|
||||||
if (fileInputRef.current) {
|
if (fileInputRef.current) {
|
||||||
fileInputRef.current.value = "";
|
fileInputRef.current.value = "";
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,27 @@ const SelectTag: React.FC = () => {
|
||||||
const [searchValue, setSearchValue] = useState<string>("");
|
const [searchValue, setSearchValue] = useState<string>("");
|
||||||
|
|
||||||
const [fieldValue, setFieldValue] = useState<string>("");
|
const [fieldValue, setFieldValue] = useState<string>("");
|
||||||
|
const [NewAdditionalData, setNewAdditionalData] = useState({})
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const handleChange = (value: string[]) => {
|
const handleChange = (value: any,option:any) => {
|
||||||
console.log(value);
|
const newSelectedOption = option?.pop()
|
||||||
|
const newObject = {
|
||||||
|
id:newSelectedOption?.id,
|
||||||
|
name:newSelectedOption?.name
|
||||||
|
}
|
||||||
|
setNewAdditionalData(newObject)
|
||||||
formik.setFieldValue("tags", value);
|
formik.setFieldValue("tags", value);
|
||||||
setSearchValue("");
|
setSearchValue("");
|
||||||
setFieldValue("");
|
setFieldValue("");
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSearch = useDebounce((value: string) => {
|
const handleSearch = useDebounce((value: string) => {
|
||||||
|
|
||||||
setSearchValue(value);
|
setSearchValue(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleFieldChange = (value: string) => {
|
const handleFieldChange = (value: string) => {
|
||||||
|
|
||||||
setFieldValue(value);
|
setFieldValue(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -42,11 +49,23 @@ const SelectTag: React.FC = () => {
|
||||||
options.length < 1 && searchValue.length > 1 && !isLoading
|
options.length < 1 && searchValue.length > 1 && !isLoading
|
||||||
? [{ id: searchValue, name: searchValue }]
|
? [{ id: searchValue, name: searchValue }]
|
||||||
: [];
|
: [];
|
||||||
|
console.log(formik?.values?.tags,"formik?.values?.tags");
|
||||||
|
|
||||||
const value =
|
const value =
|
||||||
formik?.values?.tags?.map((item: any) => item?.id ?? item) ?? [];
|
formik?.values?.tags?.map((item: any) => item?.id ?? item) ?? [];
|
||||||
|
|
||||||
const AllOptions = [...options, ...additionalData];
|
const AllOptions = [...options, ...additionalData,NewAdditionalData,...(formik?.values?.tags ?? {})];
|
||||||
|
console.log(AllOptions,"AllOptions");
|
||||||
|
|
||||||
|
const uniqueOptions = Array.from(
|
||||||
|
new Map(
|
||||||
|
AllOptions
|
||||||
|
.filter(item => Object.keys(item).length > 0) // Filter out empty objects
|
||||||
|
.map(item => [item.id, item]) // Create [id, item] pairs to ensure uniqueness
|
||||||
|
).values()
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(uniqueOptions,"uniqueOptions");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="SelectTag">
|
<div className="SelectTag">
|
||||||
|
|
@ -58,7 +77,7 @@ const SelectTag: React.FC = () => {
|
||||||
placeholder=""
|
placeholder=""
|
||||||
fieldNames={{ label: "name", value: "id" }}
|
fieldNames={{ label: "name", value: "id" }}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
options={AllOptions}
|
options={uniqueOptions}
|
||||||
filterOption={false}
|
filterOption={false}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
notFoundContent={isLoading ? <Spin /> : t("practical.not_found")}
|
notFoundContent={isLoading ? <Spin /> : t("practical.not_found")}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,34 @@ const Header = () => {
|
||||||
const { values, setFieldValue, setValues } = useFormikContext<any>();
|
const { values, setFieldValue, setValues } = useFormikContext<any>();
|
||||||
const { isBseQuestion, setIsBseQuestion } = useObjectToEdit();
|
const { isBseQuestion, setIsBseQuestion } = useObjectToEdit();
|
||||||
const { setSavedQuestionData } = useObjectToEdit();
|
const { setSavedQuestionData } = useObjectToEdit();
|
||||||
|
console.log(values,"values");
|
||||||
|
|
||||||
|
|
||||||
|
const isEdited = ()=>{
|
||||||
|
|
||||||
|
if(isBseQuestion || values?.isBase === 1){
|
||||||
|
|
||||||
|
const content = !values?.content ;
|
||||||
|
const content_image = !values?.content_image ;
|
||||||
|
const hint = !values?.hint ;
|
||||||
|
const Questions = values?.Questions?.length <= 1 && values?.Questions?.[0]?.answers?.length === 0 ;
|
||||||
|
|
||||||
|
if(content && content_image && hint && Questions) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
const content = !values?.content ;
|
||||||
|
const content_image = !values?.content_image ;
|
||||||
|
const hint = !values?.hint ;
|
||||||
|
const answers = !values?.answers ;
|
||||||
|
const tags = !(values?.tags?.length > 0) ;
|
||||||
|
if(content && content_image && hint && answers && tags) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
console.log(isEdited(),"isEdited");
|
||||||
|
|
||||||
const handleChange = () => {
|
const handleChange = () => {
|
||||||
setSavedQuestionData(null);
|
setSavedQuestionData(null);
|
||||||
|
|
@ -62,6 +90,8 @@ const Header = () => {
|
||||||
</div>
|
</div>
|
||||||
</article>
|
</article>
|
||||||
<div>
|
<div>
|
||||||
|
{
|
||||||
|
isEdited() ?
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={t("header.this_will_un_do_all_your_changes")}
|
title={t("header.this_will_un_do_all_your_changes")}
|
||||||
okText={t("practical.yes")}
|
okText={t("practical.yes")}
|
||||||
|
|
@ -77,6 +107,23 @@ const Header = () => {
|
||||||
: t("header.exercise")}
|
: t("header.exercise")}
|
||||||
|
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
|
|
||||||
|
|
||||||
|
:
|
||||||
|
|
||||||
|
<>
|
||||||
|
|
||||||
|
|
||||||
|
<GoArrowSwitch onClick={()=>confirm()} className="m-2" />
|
||||||
|
{isBseQuestion || values?.isBase === 1
|
||||||
|
? t("header.malty_exercise")
|
||||||
|
: t("header.exercise")}
|
||||||
|
</>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ const FormikFormModel: React.FC<FormikFormProps> = ({
|
||||||
>
|
>
|
||||||
{(formik) => {
|
{(formik) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpen === "") {
|
if (isOpen === "" || isOpen === "isSuccess") {
|
||||||
formik.setErrors({});
|
formik.setErrors({});
|
||||||
formik.resetForm();
|
formik.resetForm();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ const DataTable: React.FC<DataTableProps> = ({
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
const data: any[] = response?.data?.data || [];
|
const data: any[] = response?.data?.data || [];
|
||||||
const dataSource = useAddKeyToData(data);
|
|
||||||
const columns = useColumns();
|
const columns = useColumns();
|
||||||
const { pagination, handlePageChange } = usePagination(response?.data);
|
const { pagination, handlePageChange } = usePagination(response?.data);
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
@ -28,7 +27,8 @@ const DataTable: React.FC<DataTableProps> = ({
|
||||||
<Table
|
<Table
|
||||||
style={{ minHeight: "300px" }}
|
style={{ minHeight: "300px" }}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={dataSource}
|
dataSource={data}
|
||||||
|
rowKey={"id"}
|
||||||
rowClassName={(record, index) => getRowClassName(record, index)}
|
rowClassName={(record, index) => getRowClassName(record, index)}
|
||||||
className="DataTable"
|
className="DataTable"
|
||||||
loading={{
|
loading={{
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
import { TableColumnsType } from "antd";
|
import { TableColumnsType } from "antd";
|
||||||
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 { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ABILITIES_ENUM } from "../../../enums/abilities";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
canAddGrade,
|
|
||||||
canDeleteGrade,
|
canDeleteGrade,
|
||||||
canEditGrade,
|
canEditGrade,
|
||||||
canShowGrade,
|
canShowGrade,
|
||||||
|
|
@ -15,7 +12,6 @@ import {
|
||||||
import ActionButtons from "../../../Components/Table/ActionButtons";
|
import ActionButtons from "../../../Components/Table/ActionButtons";
|
||||||
import ColumnsImage from "../../../Components/Columns/ColumnsImage";
|
import ColumnsImage from "../../../Components/Columns/ColumnsImage";
|
||||||
import { Grade } from "../../../types/Grade";
|
import { Grade } from "../../../types/Grade";
|
||||||
import { useFilterState } from "../../../Components/Utils/Filter/FilterState";
|
|
||||||
import { useFilterStateState } from "../../../zustand/Filter";
|
import { useFilterStateState } from "../../../zustand/Filter";
|
||||||
|
|
||||||
export const useColumns = () => {
|
export const useColumns = () => {
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ const AddPage: React.FC = () => {
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
if(haveImageOrContent){
|
if(haveImageOrContent){
|
||||||
toast.error("validation.one_of_image_and_content_should_be_enter")
|
toast.error(t("validation.one_of_image_and_content_should_be_enter"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +127,8 @@ const AddPage: React.FC = () => {
|
||||||
const haveAnswers = answers?.length > 0;
|
const haveAnswers = answers?.length > 0;
|
||||||
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
|
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
|
||||||
const haveOneAnswerRight = haveMoreThanOneAnswer && answers?.some((item: any) => item?.isCorrect === 1 || item.isCorrect === true);
|
const haveOneAnswerRight = haveMoreThanOneAnswer && answers?.some((item: any) => item?.isCorrect === 1 || item.isCorrect === true);
|
||||||
const haveImageOrContent = haveOneAnswerRight && values?.answers?.some((item:any)=> !(item?.content) && !(item.content_image) )
|
const haveImageOrContent = haveOneAnswerRight && answers?.some((item:any)=> !(item?.content) && !(item.content_image) )
|
||||||
|
console.log(haveImageOrContent,"haveImageOrContent");
|
||||||
|
|
||||||
if (!haveAnswers) {
|
if (!haveAnswers) {
|
||||||
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
||||||
|
|
@ -145,7 +146,7 @@ const AddPage: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(haveImageOrContent){
|
if(haveImageOrContent){
|
||||||
toast.error("validation.one_of_image_and_content_should_be_enter")
|
toast.error(t("validation.one_of_image_and_content_should_be_enter"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ const EditPage: React.FC = () => {
|
||||||
if (item?.id) {
|
if (item?.id) {
|
||||||
const itemToSend = structuredClone(item);
|
const itemToSend = structuredClone(item);
|
||||||
const keysToRemove = ["content_image"];
|
const keysToRemove = ["content_image"];
|
||||||
|
console.log(itemToSend,"itemToSend");
|
||||||
|
|
||||||
const updatedObject = removeStringKeys(itemToSend, keysToRemove);
|
const updatedObject = removeStringKeys(itemToSend, keysToRemove);
|
||||||
console.log(updatedObject, "updatedObject");
|
console.log(updatedObject, "updatedObject");
|
||||||
|
|
||||||
|
|
@ -96,16 +98,6 @@ const EditPage: React.FC = () => {
|
||||||
const oldAnswers = [] as any;
|
const oldAnswers = [] as any;
|
||||||
const newAnswers = [] as any;
|
const newAnswers = [] as any;
|
||||||
|
|
||||||
if (updatedObject?.answers?.length > 0) {
|
|
||||||
const isValidAnswers = updatedObject?.answers?.some(
|
|
||||||
(answer: any) => answer?.isCorrect === 1,
|
|
||||||
);
|
|
||||||
|
|
||||||
// if(!isValidAnswers){
|
|
||||||
// toast.error(t("validation.at_least_one_answer_should_be_correct"));
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
updatedObject?.answers?.forEach((item: any) => {
|
updatedObject?.answers?.forEach((item: any) => {
|
||||||
if (item?.id) {
|
if (item?.id) {
|
||||||
oldAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
|
oldAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
|
||||||
|
|
@ -118,7 +110,6 @@ const EditPage: React.FC = () => {
|
||||||
new: newAnswers,
|
new: newAnswers,
|
||||||
};
|
};
|
||||||
console.log(answers);
|
console.log(answers);
|
||||||
|
|
||||||
mutate({
|
mutate({
|
||||||
...updatedObject,
|
...updatedObject,
|
||||||
answers,
|
answers,
|
||||||
|
|
@ -127,7 +118,10 @@ const EditPage: React.FC = () => {
|
||||||
} else {
|
} else {
|
||||||
console.log(values?.id);
|
console.log(values?.id);
|
||||||
|
|
||||||
const tags = processTags(DataToSend);
|
const tags = processTags(item);
|
||||||
|
console.log(item,"DataToSend");
|
||||||
|
|
||||||
|
console.log(tags,"tags");
|
||||||
mutateAdd({
|
mutateAdd({
|
||||||
...item,
|
...item,
|
||||||
subject_id: subject_id,
|
subject_id: subject_id,
|
||||||
|
|
@ -149,19 +143,17 @@ const EditPage: React.FC = () => {
|
||||||
|
|
||||||
const oldAnswers = [] as any;
|
const oldAnswers = [] as any;
|
||||||
const newAnswers = [] as any;
|
const newAnswers = [] as any;
|
||||||
if (updatedObject?.answers?.length > 0) {
|
|
||||||
// const isValidAnswers = updatedObject?.answers?.some((answer:any) => answer?.isCorrect === 1 || answer?.isCorrect === true)
|
|
||||||
// const isValidAnswers2 = updatedObject?.answers?.filter((answer: any) => answer?.isCorrect === 1 || answer?.isCorrect === true ).length > 1;
|
|
||||||
// console.log(isValidAnswers2);
|
|
||||||
// console.log(isValidAnswers,"isValidAnswers");
|
|
||||||
// if(!isValidAnswers || isValidAnswers2){
|
|
||||||
// toast.error(t("validation.at_least_one_answer_should_be_correct"));
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
updatedObject?.answers?.forEach((item: any) => {
|
updatedObject?.answers?.forEach((item: any) => {
|
||||||
if (item?.id) {
|
if (item?.id) {
|
||||||
|
console.log(item,"item");
|
||||||
|
const deletedImage = item?.content_image === null
|
||||||
|
if(deletedImage){
|
||||||
|
oldAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0, content_image:"" });
|
||||||
|
|
||||||
|
}else{
|
||||||
oldAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
|
oldAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
|
||||||
|
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
newAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
|
newAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
|
||||||
}
|
}
|
||||||
|
|
@ -181,7 +173,6 @@ const EditPage: React.FC = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
navigate(-1);
|
navigate(-1);
|
||||||
|
|
@ -191,6 +182,7 @@ const EditPage: React.FC = () => {
|
||||||
const handleValidateSingleQuestion = (values:any)=>{
|
const handleValidateSingleQuestion = (values:any)=>{
|
||||||
const haveMoreThanOneAnswer = values?.answers?.length > 1;
|
const haveMoreThanOneAnswer = values?.answers?.length > 1;
|
||||||
const haveOneAnswerRight = haveMoreThanOneAnswer && values?.answers?.some((item:any)=> item?.isCorrect === 1 || item.isCorrect === true )
|
const haveOneAnswerRight = haveMoreThanOneAnswer && values?.answers?.some((item:any)=> item?.isCorrect === 1 || item.isCorrect === true )
|
||||||
|
const haveImageOrContent = haveOneAnswerRight && values?.answers?.some((item:any)=> !(item?.content) && !(item.content_image) )
|
||||||
|
|
||||||
if(!haveMoreThanOneAnswer){
|
if(!haveMoreThanOneAnswer){
|
||||||
toast.error(t("validation.it_should_have_more_than_one_answers")) ;
|
toast.error(t("validation.it_should_have_more_than_one_answers")) ;
|
||||||
|
|
@ -200,6 +192,10 @@ const EditPage: React.FC = () => {
|
||||||
toast.error(t("validation.it_should_have_more_than_one_correct_answers")) ;
|
toast.error(t("validation.it_should_have_more_than_one_correct_answers")) ;
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
if(haveImageOrContent){
|
||||||
|
toast.error(t("validation.one_of_image_and_content_should_be_enter"))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,6 +206,7 @@ const handleValidateBaseQuestion = (values: any) => {
|
||||||
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
|
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
|
||||||
const haveOneAnswerRight =
|
const haveOneAnswerRight =
|
||||||
haveMoreThanOneAnswer && answers?.some((item: any) => item?.isCorrect === 1 || item.isCorrect === true);
|
haveMoreThanOneAnswer && answers?.some((item: any) => item?.isCorrect === 1 || item.isCorrect === true);
|
||||||
|
const haveImageOrContent = haveOneAnswerRight && answers?.some((item:any)=> !(item?.content) && !(item.content_image) )
|
||||||
|
|
||||||
if (!haveAnswers) {
|
if (!haveAnswers) {
|
||||||
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
toast.error(t("validation.it_should_have_more_than_one_answers"));
|
||||||
|
|
@ -226,6 +223,12 @@ const handleValidateBaseQuestion = (values: any) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(haveImageOrContent){
|
||||||
|
toast.error(t("validation.one_of_image_and_content_should_be_enter"))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,16 @@ const ChoiceFields = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
formik.setFieldValue("answers", updatedAnswers);
|
formik.setFieldValue("answers", updatedAnswers);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const values = formik?.values?.answers?.[index] ;
|
||||||
|
const handelCanDeleteAnswers = ()=>{
|
||||||
|
const content = values?.content ;
|
||||||
|
const content_image = values?.content_image ;
|
||||||
|
if(!content && !content_image ){
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="ChoiceFields">
|
<div className="ChoiceFields">
|
||||||
|
|
@ -52,7 +62,17 @@ const ChoiceFields = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
name={index}
|
name={index}
|
||||||
type="Checkbox"
|
type="Checkbox"
|
||||||
/>
|
/>
|
||||||
|
{handelCanDeleteAnswers() ?
|
||||||
|
<p className="delete_question_options" onClick={()=>{handleDeleteChoice()}}>
|
||||||
|
{t("header.delete_choice")}
|
||||||
|
<GoTrash
|
||||||
|
className="trash_icon"
|
||||||
|
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
:
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={t("header.this_will_un_do_all_your_changes")}
|
title={t("header.this_will_un_do_all_your_changes")}
|
||||||
okText={t("practical.yes")}
|
okText={t("practical.yes")}
|
||||||
|
|
@ -72,6 +92,8 @@ const ChoiceFields = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
|
|
||||||
|
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,19 @@ const ChoiceFields = ({
|
||||||
formik.setFieldValue(`Questions[${parent_index}].answers`, updatedAnswers);
|
formik.setFieldValue(`Questions[${parent_index}].answers`, updatedAnswers);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const values = formik.values.Questions?.[parent_index]?.answers?.[index] ;
|
||||||
|
console.log(values,"values");
|
||||||
|
|
||||||
|
const handelCanDeleteAnswers = ()=>{
|
||||||
|
const content = values?.content ;
|
||||||
|
const content_image = values?.content_image ;
|
||||||
|
if(!content && !content_image ){
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="ChoiceFields">
|
<div className="ChoiceFields">
|
||||||
|
|
@ -71,6 +84,18 @@ const ChoiceFields = ({
|
||||||
parent_index={parent_index}
|
parent_index={parent_index}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
{handelCanDeleteAnswers() ?
|
||||||
|
<p className="delete_question_options" onClick={()=>{handleDeleteChoice()}} >
|
||||||
|
{t("header.delete_choice")}
|
||||||
|
<GoTrash
|
||||||
|
className="trash_icon"
|
||||||
|
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
:
|
||||||
|
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={t("header.this_will_un_do_all_your_changes")}
|
title={t("header.this_will_un_do_all_your_changes")}
|
||||||
okText={t("practical.yes")}
|
okText={t("practical.yes")}
|
||||||
|
|
@ -89,6 +114,10 @@ const ChoiceFields = ({
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,11 @@ const Form = () => {
|
||||||
}
|
}
|
||||||
}, [Success]);
|
}, [Success]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row className="w-100 exercise_form_container">
|
<Row className="w-100 exercise_form_container">
|
||||||
<div className="exercise_form">
|
<div className="exercise_form">
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,22 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
formik.setFieldValue(`Questions`, updatedAnswers);
|
formik.setFieldValue(`Questions`, updatedAnswers);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const values = formik.values.Questions?.[index] ;
|
||||||
|
console.log(values,"values");
|
||||||
|
|
||||||
|
const handelCanDeleteAnswers = ()=>{
|
||||||
|
const content = values?.content ;
|
||||||
|
const content_image = values?.content_image ;
|
||||||
|
if(!content && !content_image ){
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="exercise_forms">
|
<div className="exercise_forms">
|
||||||
|
|
@ -48,7 +64,22 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
|
|
||||||
<ImageBoxField name={`Questions.${index}.content_image`} />
|
<ImageBoxField name={`Questions.${index}.content_image`} />
|
||||||
|
|
||||||
|
{handelCanDeleteAnswers() ?
|
||||||
<div className="answer_status" >
|
<div className="answer_status" >
|
||||||
|
<p className="delete_question_options" onClick={()=>{handleDeleteQuestion()}}>
|
||||||
|
{t("header.delete_question")}
|
||||||
|
<GoTrash
|
||||||
|
className="trash_icon"
|
||||||
|
|
||||||
|
size={17}
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
:
|
||||||
|
|
||||||
|
<div className="answer_status" >
|
||||||
|
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={t("header.this_will_un_do_all_your_changes")}
|
title={t("header.this_will_un_do_all_your_changes")}
|
||||||
okText={t("practical.yes")}
|
okText={t("practical.yes")}
|
||||||
|
|
@ -68,6 +99,9 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,16 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => {
|
||||||
const [fieldValue, setFieldValue] = useState<string>("");
|
const [fieldValue, setFieldValue] = useState<string>("");
|
||||||
const formik = useFormikContext<any>();
|
const formik = useFormikContext<any>();
|
||||||
const values = formik?.values?.Questions?.[parent_index]?.tags;
|
const values = formik?.values?.Questions?.[parent_index]?.tags;
|
||||||
const handleChange = (value: string[]) => {
|
const [NewAdditionalData, setNewAdditionalData] = useState({})
|
||||||
|
|
||||||
|
const handleChange = (value: string[],option:any) => {
|
||||||
|
const newSelectedOption = option?.pop()
|
||||||
|
const newObject = {
|
||||||
|
id:newSelectedOption?.id,
|
||||||
|
name:newSelectedOption?.name
|
||||||
|
}
|
||||||
|
setNewAdditionalData(newObject)
|
||||||
|
|
||||||
formik.setFieldValue(`Questions.[${parent_index}].tags`, value);
|
formik.setFieldValue(`Questions.[${parent_index}].tags`, value);
|
||||||
setSearchValue("");
|
setSearchValue("");
|
||||||
setFieldValue("");
|
setFieldValue("");
|
||||||
|
|
@ -40,13 +49,22 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => {
|
||||||
options.length < 1 && searchValue.length > 1 && !isLoading
|
options.length < 1 && searchValue.length > 1 && !isLoading
|
||||||
? [{ id: searchValue, name: searchValue }]
|
? [{ id: searchValue, name: searchValue }]
|
||||||
: [];
|
: [];
|
||||||
|
console.log(formik?.values?.Questions[parent_index]?.tags,"formik?.values?.Questions[parent_index]?.tags");
|
||||||
|
|
||||||
const value =
|
const value =
|
||||||
formik?.values?.Questions[parent_index]?.tags?.map(
|
formik?.values?.Questions[parent_index]?.tags?.map(
|
||||||
(item: any) => item?.id ?? item,
|
(item: any) => item?.id ?? item,
|
||||||
) ?? [];
|
) ?? [];
|
||||||
|
|
||||||
const AllOptions = [...options, ...additionalData];
|
const AllOptions = [...options, ...additionalData,NewAdditionalData , ...(formik?.values?.Questions[parent_index]?.tags ?? [])];
|
||||||
|
|
||||||
|
const uniqueOptions = Array.from(
|
||||||
|
new Map(
|
||||||
|
AllOptions
|
||||||
|
.filter(item => Object.keys(item).length > 0) // Filter out empty objects
|
||||||
|
.map(item => [item.id, item]) // Create [id, item] pairs to ensure uniqueness
|
||||||
|
).values()
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="SelectTag">
|
<div className="SelectTag">
|
||||||
|
|
@ -58,7 +76,7 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => {
|
||||||
placeholder=""
|
placeholder=""
|
||||||
fieldNames={{ label: "name", value: "id" }}
|
fieldNames={{ label: "name", value: "id" }}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
options={AllOptions}
|
options={uniqueOptions}
|
||||||
filterOption={false}
|
filterOption={false}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
notFoundContent={isLoading ? <Spin /> : t("practical.not_found")}
|
notFoundContent={isLoading ? <Spin /> : t("practical.not_found")}
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ export const getValidationSchemaBase = () => {
|
||||||
|
|
||||||
export function processTags(DataToSend: any) {
|
export function processTags(DataToSend: any) {
|
||||||
console.log(DataToSend?.tags);
|
console.log(DataToSend?.tags);
|
||||||
|
console.log(DataToSend);
|
||||||
|
|
||||||
const oldTags = DataToSend?.tags
|
const oldTags = DataToSend?.tags
|
||||||
?.map((item: any, index: number) => {
|
?.map((item: any, index: number) => {
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,16 @@ import { handelImageState } from "../../../../utils/DataToSendImageState";
|
||||||
import LayoutModel from "../../../../Layout/Dashboard/LayoutModel";
|
import LayoutModel from "../../../../Layout/Dashboard/LayoutModel";
|
||||||
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
|
||||||
import ModelForm from "./ModelForm";
|
import ModelForm from "./ModelForm";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { ParamsEnum } from "../../../../enums/params";
|
||||||
|
|
||||||
const ModalForm: React.FC = () => {
|
const ModalForm: React.FC = () => {
|
||||||
const { objectToEdit } = useObjectToEdit((state) => state);
|
const { objectToEdit } = useObjectToEdit((state) => state);
|
||||||
|
|
||||||
const { mutate, status } = useUpdateSubject();
|
const { mutate, status } = useUpdateSubject();
|
||||||
|
const {subject_id} = useParams<ParamsEnum>()
|
||||||
const handleSubmit = (values: any) => {
|
const handleSubmit = (values: any) => {
|
||||||
const Data_to_send = { ...values };
|
const Data_to_send = { ...values,subject_id };
|
||||||
const handelImage = handelImageState(Data_to_send, "icon");
|
const handelImage = handelImageState(Data_to_send, "icon");
|
||||||
mutate(handelImage);
|
mutate(handelImage);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useFilter from "../../Components/FilterField/components/useFilter";
|
import useFilter from "../../Components/FilterField/components/useFilter";
|
||||||
|
import { Select } from "antd";
|
||||||
|
|
||||||
const Dummy = () => {
|
const Dummy = () => {
|
||||||
const [t] = useTranslation();
|
const [t] = useTranslation();
|
||||||
|
|
@ -8,12 +9,15 @@ const Dummy = () => {
|
||||||
return (
|
return (
|
||||||
<div className="DummyHomePage">
|
<div className="DummyHomePage">
|
||||||
|
|
||||||
<FilterButton/>
|
{/* <FilterButton/>
|
||||||
<FilterBody>
|
<FilterBody>
|
||||||
karim
|
karim
|
||||||
</FilterBody>
|
</FilterBody>
|
||||||
|
<Select
|
||||||
|
style={{width:"200px"}}
|
||||||
|
showSearch
|
||||||
|
/> */}
|
||||||
|
|
||||||
karim2
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -96,15 +96,3 @@
|
||||||
.model_sub_children{
|
.model_sub_children{
|
||||||
padding-bottom: 30px;
|
padding-bottom: 30px;
|
||||||
}
|
}
|
||||||
.ant-select-selection-search{
|
|
||||||
// color: #6A7287 !important;
|
|
||||||
// display: none !important;
|
|
||||||
|
|
||||||
}
|
|
||||||
:where(.css-dev-only-do-not-override-oad6qy).ant-select-single.ant-select-lg .ant-select-selector .ant-select-selection-search{
|
|
||||||
input{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
:where(.css-dev-only-do-not-override-oad6qy).ant-select-single.ant-select-lg:not(.ant-select-customize-input) .ant-select-selector .ant-select-selection-search-input{
|
|
||||||
}
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
@import "./Layout.scss";
|
@import "./Layout.scss";
|
||||||
@import "./SideBar.scss";
|
@import "./SideBar.scss";
|
||||||
@import "./DataTable.scss";
|
@import "./DataTable.scss";
|
||||||
|
|
||||||
@import "./DataState.scss";
|
@import "./DataState.scss";
|
||||||
@import "./PageHeader.scss";
|
@import "./PageHeader.scss";
|
||||||
@import "./FilterLayout.scss";
|
@import "./FilterLayout.scss";
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ function useAxios() {
|
||||||
|
|
||||||
build_Axios.interceptors.response.use(
|
build_Axios.interceptors.response.use(
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
|
console.log(response?.data);
|
||||||
|
|
||||||
const responseMsg = response?.data?.message;
|
const responseMsg = response?.data?.message;
|
||||||
const method = response.config.method;
|
const method = response.config.method;
|
||||||
|
|
||||||
|
|
@ -53,7 +55,7 @@ function useAxios() {
|
||||||
console.log(error?.response);
|
console.log(error?.response);
|
||||||
|
|
||||||
const status = error?.request?.status;
|
const status = error?.request?.status;
|
||||||
const errorMsg = error?.response?.data?.message;
|
const errorMsg = error?.response?.data?.error;
|
||||||
const errorField = error?.response?.data;
|
const errorField = error?.response?.data;
|
||||||
const method = error.config.method;
|
const method = error.config.method;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
import useAxios from "./useAxios";
|
import useAxios from "./useAxios";
|
||||||
import { useLocation } from "react-router-dom";
|
|
||||||
import { PaginationParams } from "../utils/PaginationParams";
|
|
||||||
import { filterParams } from "../utils/filterParams";
|
import { filterParams } from "../utils/filterParams";
|
||||||
import { useFilterStateState } from "../../zustand/Filter";
|
import { useFilterStateState } from "../../zustand/Filter";
|
||||||
function useGetQuery(
|
function useGetQuery(
|
||||||
|
|
@ -13,11 +11,9 @@ function useGetQuery(
|
||||||
const axios = useAxios();
|
const axios = useAxios();
|
||||||
const { show, pagination, ...remainingParams } = params;
|
const { show, pagination, ...remainingParams } = params;
|
||||||
|
|
||||||
const location = useLocation();
|
const { Filter } = useFilterStateState();
|
||||||
const { Filter ,setFilter } = useFilterStateState();
|
|
||||||
const page = Filter?.page ;
|
const page = Filter?.page ;
|
||||||
const per_page = Filter?.per_page ;
|
const per_page = Filter?.per_page ;
|
||||||
// const { per_page } = PaginationParams(location);
|
|
||||||
|
|
||||||
const paramToSend = pagination
|
const paramToSend = pagination
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@
|
||||||
"at_least_one_answer_should_be_correct": "يجب أن تكون إجابة واحدة صحيحة",
|
"at_least_one_answer_should_be_correct": "يجب أن تكون إجابة واحدة صحيحة",
|
||||||
"it_should_have_more_than_one_answers": "يجب أن يحتوي على أكثر من إجابة",
|
"it_should_have_more_than_one_answers": "يجب أن يحتوي على أكثر من إجابة",
|
||||||
"it_should_have_more_than_one_correct_answers": "يجب أن يحتوي على إجابة صحيحة",
|
"it_should_have_more_than_one_correct_answers": "يجب أن يحتوي على إجابة صحيحة",
|
||||||
"File_size_exceeds_2_MB_limit.":"حجم الملف يتجاوز الحد الأقصى البالغ 2 ميجابايت"
|
"File_size_exceeds_2_MB_limit.":"حجم الملف يتجاوز الحد الأقصى البالغ 2 ميجابايت",
|
||||||
|
"one_of_image_and_content_should_be_enter":"يجب إدخال صورة أو محتوى واحد على الأقل"
|
||||||
},
|
},
|
||||||
"header": {
|
"header": {
|
||||||
"register_students": "تسجيل الطلاب",
|
"register_students": "تسجيل الطلاب",
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ export function removeStringKeys(obj: any, keysToRemove: string[]): any {
|
||||||
// Check if the value is a string or "null" and the key is in keysToRemove
|
// Check if the value is a string or "null" and the key is in keysToRemove
|
||||||
if (
|
if (
|
||||||
keysToRemove.includes(key) &&
|
keysToRemove.includes(key) &&
|
||||||
(typeof value === "string" || value === "null")
|
(typeof value === "string")
|
||||||
) {
|
) {
|
||||||
delete obj[key];
|
delete obj[key];
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user