fix tag
This commit is contained in:
parent
1d39a4cd4f
commit
32f87910ea
|
|
@ -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 = "";
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
@ -46,7 +53,7 @@ const SelectTag: React.FC = () => {
|
|||
const value =
|
||||
formik?.values?.tags?.map((item: any) => item?.id ?? item) ?? [];
|
||||
|
||||
const AllOptions = [...options, ...additionalData];
|
||||
const AllOptions = [...options, ...additionalData,NewAdditionalData];
|
||||
|
||||
return (
|
||||
<div className="SelectTag">
|
||||
|
|
|
|||
|
|
@ -13,6 +13,21 @@ 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){
|
||||
|
||||
}else{
|
||||
const content = !!values?.content ;
|
||||
const content_image = !!values?.content_image ;
|
||||
const hint = !values?.hint ;
|
||||
const answers = !values?.answers ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const handleChange = () => {
|
||||
setSavedQuestionData(null);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
|
|
@ -149,19 +141,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) {
|
||||
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 +171,6 @@ const EditPage: React.FC = () => {
|
|||
};
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
const navigate = useNavigate();
|
||||
const handleCancel = () => {
|
||||
navigate(-1);
|
||||
|
|
@ -191,6 +180,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 +190,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 +204,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 +221,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;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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,7 +62,17 @@ 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")}
|
||||
|
|
@ -72,6 +92,8 @@ const ChoiceFields = ({ index, data }: { index: number; data: Choice }) => {
|
|||
|
||||
|
||||
</Popconfirm>
|
||||
}
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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,6 +84,18 @@ const ChoiceFields = ({
|
|||
parent_index={parent_index}
|
||||
/>
|
||||
|
||||
|
||||
{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")}
|
||||
|
|
@ -89,6 +114,10 @@ const ChoiceFields = ({
|
|||
</p>
|
||||
|
||||
</Popconfirm>
|
||||
|
||||
}
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -94,6 +94,11 @@ const Form = () => {
|
|||
}
|
||||
}, [Success]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Row className="w-100 exercise_form_container">
|
||||
<div className="exercise_form">
|
||||
|
|
|
|||
|
|
@ -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`} />
|
||||
|
||||
{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>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
@ -12,8 +13,11 @@ const Dummy = () => {
|
|||
<FilterBody>
|
||||
karim
|
||||
</FilterBody>
|
||||
<Select
|
||||
style={{width:"200px"}}
|
||||
showSearch
|
||||
/>
|
||||
|
||||
karim2
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
@import "./Layout.scss";
|
||||
@import "./SideBar.scss";
|
||||
@import "./DataTable.scss";
|
||||
|
||||
@import "./DataState.scss";
|
||||
@import "./PageHeader.scss";
|
||||
@import "./FilterLayout.scss";
|
||||
|
|
|
|||
|
|
@ -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": "تسجيل الطلاب",
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user