Compare commits

...

4 Commits

Author SHA1 Message Date
karimaldeen
c858803cb0 Merge branch 'dev' of https://git.point-dev.net/Karimaldeen/Quiz_dashboard into dev 2024-09-16 20:22:58 +03:00
karimaldeen
de71606e88 fix 2024-09-16 20:22:07 +03:00
karimaldeen
05d0a12527 fix tags 2024-09-16 15:48:33 +03:00
karimaldeen
32f87910ea fix tag 2024-09-16 15:29:53 +03:00
22 changed files with 265 additions and 93 deletions

View File

@ -27,6 +27,7 @@ const ImageBoxField = ({ name }: any) => {
const handleFileChange = (event: any) => {
const file = event.target.files[0];
if (file) {
const maxSize = 2 * 1024 * 1024;
@ -42,6 +43,8 @@ const ImageBoxField = ({ name }: any) => {
if (file) {
generateImagePreview(file, setImagePreview);
console.log(file,"file");
formik.setFieldValue(name, file);
}
};
@ -55,7 +58,7 @@ const ImageBoxField = ({ name }: any) => {
const handleCancel = () => {
setImagePreview("");
formik.setFieldValue(name, "");
formik.setFieldValue(name, null);
if (fileInputRef.current) {
fileInputRef.current.value = "";

View File

@ -9,20 +9,27 @@ const SelectTag: React.FC = () => {
const [searchValue, setSearchValue] = useState<string>("");
const [fieldValue, setFieldValue] = useState<string>("");
const [NewAdditionalData, setNewAdditionalData] = useState({})
const formik = useFormikContext<any>();
const handleChange = (value: string[]) => {
console.log(value);
const handleChange = (value: any,option:any) => {
const newSelectedOption = option?.pop()
const newObject = {
id:newSelectedOption?.id,
name:newSelectedOption?.name
}
setNewAdditionalData(newObject)
formik.setFieldValue("tags", value);
setSearchValue("");
setFieldValue("");
};
const handleSearch = useDebounce((value: string) => {
setSearchValue(value);
});
const handleFieldChange = (value: string) => {
setFieldValue(value);
};
@ -42,11 +49,23 @@ const SelectTag: React.FC = () => {
options.length < 1 && searchValue.length > 1 && !isLoading
? [{ id: searchValue, name: searchValue }]
: [];
console.log(formik?.values?.tags,"formik?.values?.tags");
const value =
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 (
<div className="SelectTag">
@ -58,7 +77,7 @@ const SelectTag: React.FC = () => {
placeholder=""
fieldNames={{ label: "name", value: "id" }}
onChange={handleChange}
options={AllOptions}
options={uniqueOptions}
filterOption={false}
loading={isLoading}
notFoundContent={isLoading ? <Spin /> : t("practical.not_found")}

View File

@ -13,6 +13,34 @@ const Header = () => {
const { values, setFieldValue, setValues } = useFormikContext<any>();
const { isBseQuestion, setIsBseQuestion } = 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 = () => {
setSavedQuestionData(null);
@ -62,7 +90,9 @@ const Header = () => {
</div>
</article>
<div>
<Popconfirm
{
isEdited() ?
<Popconfirm
title={t("header.this_will_un_do_all_your_changes")}
okText={t("practical.yes")}
cancelText={t("practical.no")}
@ -77,6 +107,23 @@ const Header = () => {
: t("header.exercise")}
</Popconfirm>
:
<>
<GoArrowSwitch onClick={()=>confirm()} className="m-2" />
{isBseQuestion || values?.isBase === 1
? t("header.malty_exercise")
: t("header.exercise")}
</>
}
</div>
</header>
);

View File

@ -33,7 +33,7 @@ const FormikFormModel: React.FC<FormikFormProps> = ({
>
{(formik) => {
useEffect(() => {
if (isOpen === "") {
if (isOpen === "" || isOpen === "isSuccess") {
formik.setErrors({});
formik.resetForm();
}

View File

@ -14,7 +14,6 @@ const DataTable: React.FC<DataTableProps> = ({
...props
}) => {
const data: any[] = response?.data?.data || [];
const dataSource = useAddKeyToData(data);
const columns = useColumns();
const { pagination, handlePageChange } = usePagination(response?.data);
const [t] = useTranslation();
@ -28,7 +27,8 @@ const DataTable: React.FC<DataTableProps> = ({
<Table
style={{ minHeight: "300px" }}
columns={columns}
dataSource={dataSource}
dataSource={data}
rowKey={"id"}
rowClassName={(record, index) => getRowClassName(record, index)}
className="DataTable"
loading={{

View File

@ -1,13 +1,10 @@
import { TableColumnsType } from "antd";
import { FaPlus } from "react-icons/fa";
import useModalHandler from "../../../utils/useModalHandler";
import { ModalEnum } from "../../../enums/Model";
import { useObjectToEdit } from "../../../zustand/ObjectToEditState";
import { useTranslation } from "react-i18next";
import { ABILITIES_ENUM } from "../../../enums/abilities";
import { useNavigate } from "react-router-dom";
import {
canAddGrade,
canDeleteGrade,
canEditGrade,
canShowGrade,
@ -15,7 +12,6 @@ import {
import ActionButtons from "../../../Components/Table/ActionButtons";
import ColumnsImage from "../../../Components/Columns/ColumnsImage";
import { Grade } from "../../../types/Grade";
import { useFilterState } from "../../../Components/Utils/Filter/FilterState";
import { useFilterStateState } from "../../../zustand/Filter";
export const useColumns = () => {

View File

@ -115,7 +115,7 @@ const AddPage: React.FC = () => {
return false ;
}
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
}
@ -127,7 +127,8 @@ const AddPage: React.FC = () => {
const haveAnswers = answers?.length > 0;
const haveMoreThanOneAnswer = haveAnswers && answers?.length > 1;
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) {
toast.error(t("validation.it_should_have_more_than_one_answers"));
@ -145,7 +146,7 @@ const AddPage: React.FC = () => {
}
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
}

View File

@ -89,6 +89,8 @@ const EditPage: React.FC = () => {
if (item?.id) {
const itemToSend = structuredClone(item);
const keysToRemove = ["content_image"];
console.log(itemToSend,"itemToSend");
const updatedObject = removeStringKeys(itemToSend, keysToRemove);
console.log(updatedObject, "updatedObject");
@ -96,16 +98,6 @@ const EditPage: React.FC = () => {
const oldAnswers = [] 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) => {
if (item?.id) {
oldAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
@ -118,7 +110,6 @@ const EditPage: React.FC = () => {
new: newAnswers,
};
console.log(answers);
mutate({
...updatedObject,
answers,
@ -127,7 +118,10 @@ const EditPage: React.FC = () => {
} else {
console.log(values?.id);
const tags = processTags(DataToSend);
const tags = processTags(item);
console.log(item,"DataToSend");
console.log(tags,"tags");
mutateAdd({
...item,
subject_id: subject_id,
@ -149,19 +143,17 @@ const EditPage: React.FC = () => {
const oldAnswers = [] 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) => {
if (item?.id) {
oldAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
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 });
}
} else {
newAnswers.push({ ...item, isCorrect: item?.isCorrect ? 1 : 0 });
}
@ -181,7 +173,6 @@ const EditPage: React.FC = () => {
};
const location = useLocation();
const navigate = useNavigate();
const handleCancel = () => {
navigate(-1);
@ -191,6 +182,7 @@ const EditPage: React.FC = () => {
const handleValidateSingleQuestion = (values:any)=>{
const haveMoreThanOneAnswer = values?.answers?.length > 1;
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){
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")) ;
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 haveOneAnswerRight =
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) {
toast.error(t("validation.it_should_have_more_than_one_answers"));
@ -226,6 +223,12 @@ const handleValidateBaseQuestion = (values: any) => {
return false;
}
if(haveImageOrContent){
toast.error(t("validation.one_of_image_and_content_should_be_enter"))
return false
}
return true;
});

View File

@ -26,6 +26,16 @@ const ChoiceFields = ({ index, data }: { index: number; data: Choice }) => {
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 (
<>
<div className="ChoiceFields">
@ -52,26 +62,38 @@ const ChoiceFields = ({ index, data }: { index: number; data: Choice }) => {
name={index}
type="Checkbox"
/>
{handelCanDeleteAnswers() ?
<p className="delete_question_options" onClick={()=>{handleDeleteChoice()}}>
{t("header.delete_choice")}
<GoTrash
className="trash_icon"
size={17}
/>
</p>
:
<Popconfirm
title={t("header.this_will_un_do_all_your_changes")}
okText={t("practical.yes")}
cancelText={t("practical.no")}
onConfirm={()=>{handleDeleteChoice()}}
defaultOpen={false}
title={t("header.this_will_un_do_all_your_changes")}
okText={t("practical.yes")}
cancelText={t("practical.no")}
onConfirm={()=>{handleDeleteChoice()}}
defaultOpen={false}
>
<p className="delete_question_options">
{t("header.delete_choice")}
<GoTrash
className="trash_icon"
>
<p className="delete_question_options">
{t("header.delete_choice")}
<GoTrash
className="trash_icon"
size={17}
/>
</p>
size={17}
/>
</p>
</Popconfirm>
</Popconfirm>
}
</div>
</div>

View File

@ -42,6 +42,19 @@ const ChoiceFields = ({
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 (
<>
<div className="ChoiceFields">
@ -71,7 +84,19 @@ const ChoiceFields = ({
parent_index={parent_index}
/>
<Popconfirm
{handelCanDeleteAnswers() ?
<p className="delete_question_options" onClick={()=>{handleDeleteChoice()}} >
{t("header.delete_choice")}
<GoTrash
className="trash_icon"
size={17}
/>
</p>
:
<Popconfirm
title={t("header.this_will_un_do_all_your_changes")}
okText={t("practical.yes")}
cancelText={t("practical.no")}
@ -89,6 +114,10 @@ const ChoiceFields = ({
</p>
</Popconfirm>
}
</div>
</div>

View File

@ -94,6 +94,11 @@ const Form = () => {
}
}, [Success]);
return (
<Row className="w-100 exercise_form_container">
<div className="exercise_form">

View File

@ -29,6 +29,22 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
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 (
<>
<div className="exercise_forms">
@ -48,7 +64,22 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
<ImageBoxField name={`Questions.${index}.content_image`} />
<div className="answer_status" >
{handelCanDeleteAnswers() ?
<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
title={t("header.this_will_un_do_all_your_changes")}
okText={t("practical.yes")}
@ -68,6 +99,9 @@ const QuestionFIeld = ({ index, data }: { index: number; data: Choice }) => {
</Popconfirm>
</div>
}
</div>
</div>

View File

@ -10,7 +10,16 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => {
const [fieldValue, setFieldValue] = useState<string>("");
const formik = useFormikContext<any>();
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);
setSearchValue("");
setFieldValue("");
@ -40,13 +49,22 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => {
options.length < 1 && searchValue.length > 1 && !isLoading
? [{ id: searchValue, name: searchValue }]
: [];
console.log(formik?.values?.Questions[parent_index]?.tags,"formik?.values?.Questions[parent_index]?.tags");
const value =
formik?.values?.Questions[parent_index]?.tags?.map(
(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 (
<div className="SelectTag">
@ -58,7 +76,7 @@ const MaltySelectTag = ({ parent_index }: { parent_index: number }) => {
placeholder=""
fieldNames={{ label: "name", value: "id" }}
onChange={handleChange}
options={AllOptions}
options={uniqueOptions}
filterOption={false}
loading={isLoading}
notFoundContent={isLoading ? <Spin /> : t("practical.not_found")}

View File

@ -123,6 +123,7 @@ export const getValidationSchemaBase = () => {
export function processTags(DataToSend: any) {
console.log(DataToSend?.tags);
console.log(DataToSend);
const oldTags = DataToSend?.tags
?.map((item: any, index: number) => {

View File

@ -7,14 +7,16 @@ import { handelImageState } from "../../../../utils/DataToSendImageState";
import LayoutModel from "../../../../Layout/Dashboard/LayoutModel";
import { QueryStatusEnum } from "../../../../enums/QueryStatus";
import ModelForm from "./ModelForm";
import { useParams } from "react-router-dom";
import { ParamsEnum } from "../../../../enums/params";
const ModalForm: React.FC = () => {
const { objectToEdit } = useObjectToEdit((state) => state);
const { mutate, status } = useUpdateSubject();
const {subject_id} = useParams<ParamsEnum>()
const handleSubmit = (values: any) => {
const Data_to_send = { ...values };
const Data_to_send = { ...values,subject_id };
const handelImage = handelImageState(Data_to_send, "icon");
mutate(handelImage);
};

View File

@ -1,6 +1,7 @@
import React from "react";
import { useTranslation } from "react-i18next";
import useFilter from "../../Components/FilterField/components/useFilter";
import { Select } from "antd";
const Dummy = () => {
const [t] = useTranslation();
@ -8,12 +9,15 @@ const Dummy = () => {
return (
<div className="DummyHomePage">
<FilterButton/>
{/* <FilterButton/>
<FilterBody>
karim
</FilterBody>
<Select
style={{width:"200px"}}
showSearch
/> */}
karim2
</div>
);
};

View File

@ -96,15 +96,3 @@
.model_sub_children{
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{
}

View File

@ -3,6 +3,7 @@
@import "./Layout.scss";
@import "./SideBar.scss";
@import "./DataTable.scss";
@import "./DataState.scss";
@import "./PageHeader.scss";
@import "./FilterLayout.scss";

View File

@ -32,6 +32,8 @@ function useAxios() {
build_Axios.interceptors.response.use(
function (response: any) {
console.log(response?.data);
const responseMsg = response?.data?.message;
const method = response.config.method;
@ -53,7 +55,7 @@ function useAxios() {
console.log(error?.response);
const status = error?.request?.status;
const errorMsg = error?.response?.data?.message;
const errorMsg = error?.response?.data?.error;
const errorField = error?.response?.data;
const method = error.config.method;

View File

@ -1,7 +1,5 @@
import { useQuery } from "react-query";
import useAxios from "./useAxios";
import { useLocation } from "react-router-dom";
import { PaginationParams } from "../utils/PaginationParams";
import { filterParams } from "../utils/filterParams";
import { useFilterStateState } from "../../zustand/Filter";
function useGetQuery(
@ -13,11 +11,9 @@ function useGetQuery(
const axios = useAxios();
const { show, pagination, ...remainingParams } = params;
const location = useLocation();
const { Filter ,setFilter } = useFilterStateState();
const { Filter } = useFilterStateState();
const page = Filter?.page ;
const per_page = Filter?.per_page ;
// const { per_page } = PaginationParams(location);
const paramToSend = pagination

View File

@ -49,7 +49,8 @@
"at_least_one_answer_should_be_correct": "يجب أن تكون إجابة واحدة صحيحة",
"it_should_have_more_than_one_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": {
"register_students": "تسجيل الطلاب",

View File

@ -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
if (
keysToRemove.includes(key) &&
(typeof value === "string" || value === "null")
(typeof value === "string")
) {
delete obj[key];
} else {