From 693c1cdb069253e20edb91d5f71377cd69ad3c76 Mon Sep 17 00:00:00 2001 From: karimaldeen Date: Sat, 14 Sep 2024 16:00:20 +0300 Subject: [PATCH] remove un used code --- .../ImageBoxField/ImageBoxField.tsx | 2 +- src/Components/exercise/Header.tsx | 4 +- src/Pages/Admin/question/AddPage.tsx | 14 +-- src/Pages/Admin/question/EditPage.tsx | 3 +- .../Admin/question/Model/AcceptModal.tsx | 57 ---------- .../Model/Malty/ChoiceField/CheckboxField.tsx | 5 +- .../Model/Malty/ChoiceField/ChoiceFields.tsx | 3 - .../question/Model/Malty/ChoiceField/File.tsx | 88 -------------- .../Model/Malty/ChoiceField/HintField.tsx | 54 --------- src/Pages/Admin/question/Model/Malty/Form.tsx | 6 + .../Model/Malty/QuestionFIeld/File.tsx | 85 -------------- .../Model/Malty/QuestionFIeld/HintField.tsx | 52 --------- .../Malty/QuestionFIeld/QuestionFIeld.tsx | 6 - .../question/Model/Malty/Tags/DynamicTags.tsx | 107 ------------------ .../Admin/question/Model/Malty/Tags/Tag.tsx | 80 ------------- .../Admin/question/{Model => }/formUtil.ts | 2 +- 16 files changed, 17 insertions(+), 551 deletions(-) delete mode 100644 src/Pages/Admin/question/Model/AcceptModal.tsx delete mode 100644 src/Pages/Admin/question/Model/Malty/ChoiceField/File.tsx delete mode 100644 src/Pages/Admin/question/Model/Malty/ChoiceField/HintField.tsx delete mode 100644 src/Pages/Admin/question/Model/Malty/QuestionFIeld/File.tsx delete mode 100644 src/Pages/Admin/question/Model/Malty/QuestionFIeld/HintField.tsx delete mode 100644 src/Pages/Admin/question/Model/Malty/Tags/DynamicTags.tsx delete mode 100644 src/Pages/Admin/question/Model/Malty/Tags/Tag.tsx rename src/Pages/Admin/question/{Model => }/formUtil.ts (98%) diff --git a/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx b/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx index e19dd62..230058e 100644 --- a/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx +++ b/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx @@ -63,7 +63,7 @@ const ImageBoxField = ({ name }: any) => {
hidden
)} -
+
{imagePreview ? ( Preview ) : ( diff --git a/src/Components/exercise/Header.tsx b/src/Components/exercise/Header.tsx index ffa1aec..a524b5f 100644 --- a/src/Components/exercise/Header.tsx +++ b/src/Components/exercise/Header.tsx @@ -72,11 +72,11 @@ const Header = () => { > - - {isBseQuestion || values?.isBase === 1 ? t("header.malty_exercise") : t("header.exercise")} + +
); diff --git a/src/Pages/Admin/question/AddPage.tsx b/src/Pages/Admin/question/AddPage.tsx index 5d35fe7..1f4b5dd 100644 --- a/src/Pages/Admin/question/AddPage.tsx +++ b/src/Pages/Admin/question/AddPage.tsx @@ -1,13 +1,12 @@ import React, { Suspense, lazy, useEffect } from "react"; import { Spin } from "antd"; -import FormikForm from "../../../Layout/Dashboard/FormikFormModel"; import { getInitialValues, getValidationSchema, getInitialValuesBase, getValidationSchemaBase, processTags, -} from "./Model/formUtil"; +} from "./formUtil"; import { useAddQuestion, useAddQuestionAsync } from "../../../api/Question"; import { useTranslation } from "react-i18next"; import { useLocation, useNavigate, useParams } from "react-router-dom"; @@ -21,7 +20,6 @@ import ModelForm from "./Model/ModelForm"; import { toast } from "react-toastify"; import { Form, Formik } from "formik"; import { MdOutlineArrowForwardIos } from "react-icons/md"; -const AcceptModal = lazy(() => import("./Model/AcceptModal")); const AddPage: React.FC = () => { const location = useLocation(); @@ -163,7 +161,8 @@ const AddPage: React.FC = () => { const handleCancel = () => { navigate(-1); }; - const Loading = LoadingAsync || isLoading + const Loading = LoadingAsync || isLoading; + useEffect(() => { if (isSuccess) { setSuccess(true); @@ -211,9 +210,7 @@ const AddPage: React.FC = () => { )} - }> - - +
@@ -264,9 +261,6 @@ const AddPage: React.FC = () => { )} - }> - - ); diff --git a/src/Pages/Admin/question/EditPage.tsx b/src/Pages/Admin/question/EditPage.tsx index c82a6af..7c6427c 100644 --- a/src/Pages/Admin/question/EditPage.tsx +++ b/src/Pages/Admin/question/EditPage.tsx @@ -1,13 +1,12 @@ import React, { useEffect } from "react"; import { Modal, Spin } from "antd"; -import FormikForm from "../../../Layout/Dashboard/FormikFormModel"; import { getInitialValues, getValidationSchema, getInitialValuesBase, getValidationSchemaBase, processTags, -} from "./Model/formUtil"; +} from "./formUtil"; import { useAddQuestion, useDeleteQuestion, diff --git a/src/Pages/Admin/question/Model/AcceptModal.tsx b/src/Pages/Admin/question/Model/AcceptModal.tsx deleted file mode 100644 index 43531b9..0000000 --- a/src/Pages/Admin/question/Model/AcceptModal.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import React from "react"; -import { Modal } from "antd"; -import { useModalState } from "../../../../zustand/Modal"; -import { ModalEnum } from "../../../../enums/Model"; -import { useTranslation } from "react-i18next"; -import { useNavigate } from "react-router-dom"; -import { QUESTION_OBJECT_KEY } from "../../../../config/AppKey"; - -const AcceptModal: React.FC = () => { - const { isOpen, setIsOpen } = useModalState((state) => state); - const navigate = useNavigate(); - - const handleSubmit = () => { - localStorage.removeItem(QUESTION_OBJECT_KEY); - console.log("Handle submit clicked"); - setIsOpen(""); - - navigate(-1); - }; - - const handleCancel = () => { - setIsOpen(""); - }; - - const [t] = useTranslation(); - return ( - <> - -
{t("practical.accept_back")}
- -
-
- -
- -
-
{t("practical.cancel")}
-
{t("practical.accept")}
-
-
-
- - ); -}; - -export default AcceptModal; diff --git a/src/Pages/Admin/question/Model/Malty/ChoiceField/CheckboxField.tsx b/src/Pages/Admin/question/Model/Malty/ChoiceField/CheckboxField.tsx index 990bcdc..139fc2c 100644 --- a/src/Pages/Admin/question/Model/Malty/ChoiceField/CheckboxField.tsx +++ b/src/Pages/Admin/question/Model/Malty/ChoiceField/CheckboxField.tsx @@ -1,7 +1,6 @@ import React from "react"; -import useFormField from "../../../../../../Hooks/useFormField"; -import { Checkbox, Form } from "antd"; -import { useFormik, useFormikContext } from "formik"; +import { Checkbox } from "antd"; +import { useFormikContext } from "formik"; import { useTranslation } from "react-i18next"; const CheckboxField = ({ name, diff --git a/src/Pages/Admin/question/Model/Malty/ChoiceField/ChoiceFields.tsx b/src/Pages/Admin/question/Model/Malty/ChoiceField/ChoiceFields.tsx index 0640d42..4586fbb 100644 --- a/src/Pages/Admin/question/Model/Malty/ChoiceField/ChoiceFields.tsx +++ b/src/Pages/Admin/question/Model/Malty/ChoiceField/ChoiceFields.tsx @@ -6,10 +6,7 @@ import { useTranslation } from "react-i18next"; import { getCharFromNumber } from "../../../../../../utils/getCharFromNumber"; import CheckboxField from "./CheckboxField"; import TextField from "./TextField"; -import File from "./File"; -import { FaTrash } from "react-icons/fa"; import { toast } from "react-toastify"; -import HintField from "./HintField"; import ImageBoxField from "../../../../../../Components/CustomFields/ImageBoxField/ImageBoxField"; import { GoTrash } from "react-icons/go"; diff --git a/src/Pages/Admin/question/Model/Malty/ChoiceField/File.tsx b/src/Pages/Admin/question/Model/Malty/ChoiceField/File.tsx deleted file mode 100644 index b3d2e37..0000000 --- a/src/Pages/Admin/question/Model/Malty/ChoiceField/File.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import { Button, Upload, UploadFile } from "antd"; -import useFormField from "../../../../../../Hooks/useFormField"; -import { UploadOutlined } from "@ant-design/icons"; -import { useMemo } from "react"; - -const File = ({ - name, - label, - onChange, - isDisabled, - placholder, - className, - parent_index, - props, -}: any) => { - const newName = `Questions[${parent_index}].answers[${name}].answer_image`; - - const { formik, t, isError, errorMsg } = useFormField(newName, props); - let imageUrl = - formik?.values?.Questions?.[parent_index]?.answers[name]?.answer_image ?? - null; - // console.log(imageUrl); - - const fileList: UploadFile[] = useMemo(() => { - if (!imageUrl) return []; - - return [ - typeof imageUrl === "string" - ? { - uid: "-1", - name: "uploaded-image", - status: "done", - url: imageUrl, - thumbUrl: imageUrl, - } - : { - uid: imageUrl.uid || "-1", - name: imageUrl.name || "uploaded-image", - status: "done", - originFileObj: imageUrl, - }, - ]; - }, [imageUrl]); - // console.log(1); - - const FilehandleChange = (value: any) => { - // console.log(value,"filevalue"); - if (value.fileList.length === 0) { - formik.setFieldValue(newName, null); - } else { - formik.setFieldValue( - `Questions[${parent_index}].answers[${name}].answer_image`, - value?.file?.originFileObj, - ); - } - }; - const customRequest = async ({ onSuccess, no_label, label_icon }: any) => { - onSuccess(); - }; - return ( -
- - - - -
{isError ? "required" : ""}
- {errorMsg} -
-
- ); -}; - -export default File; diff --git a/src/Pages/Admin/question/Model/Malty/ChoiceField/HintField.tsx b/src/Pages/Admin/question/Model/Malty/ChoiceField/HintField.tsx deleted file mode 100644 index dcdf284..0000000 --- a/src/Pages/Admin/question/Model/Malty/ChoiceField/HintField.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { Form, Input } from "antd"; -import React from "react"; -import useFormField from "../../../../../../Hooks/useFormField"; -import { MdOutlineEdit } from "react-icons/md"; -import { Field } from "formik"; - -const HintField = ({ - name, - label, - label2, - placeholder, - isDisabled, - onChange, - props, - parent_index, - id, - className, -}: any) => { - const newName = `Questions[${parent_index}].answers[${name}].hint`; - - const { formik, isError, errorMsg, t } = useFormField(newName, props); - const TextFilehandleChange = ( - e: React.ChangeEvent, - ) => { - // console.log('Change:', e.target.value); - formik.setFieldValue(newName, e.target.value); - }; - - return ( -
- - - - -
- ); -}; - -export default React.memo(HintField); diff --git a/src/Pages/Admin/question/Model/Malty/Form.tsx b/src/Pages/Admin/question/Model/Malty/Form.tsx index 62a0839..fbb81f3 100644 --- a/src/Pages/Admin/question/Model/Malty/Form.tsx +++ b/src/Pages/Admin/question/Model/Malty/Form.tsx @@ -87,6 +87,12 @@ const Form = () => { ); + useEffect(() => { + if (Success) { + formik.resetForm() + setSuccess(false); + } + }, [Success]); return ( diff --git a/src/Pages/Admin/question/Model/Malty/QuestionFIeld/File.tsx b/src/Pages/Admin/question/Model/Malty/QuestionFIeld/File.tsx deleted file mode 100644 index fdc5bab..0000000 --- a/src/Pages/Admin/question/Model/Malty/QuestionFIeld/File.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import { Button, Upload, UploadFile } from "antd"; -import useFormField from "../../../../../../Hooks/useFormField"; -import { UploadOutlined } from "@ant-design/icons"; -import { useMemo } from "react"; - -const File = ({ - name, - label, - onChange, - isDisabled, - placholder, - className, - props, -}: any) => { - const newName = `Questions[${name}].image`; - - const { formik, t, isError, errorMsg } = useFormField(newName, props); - let imageUrl = formik?.values?.Questions?.[name]?.image ?? null; - // console.log(imageUrl); - - const fileList: UploadFile[] = useMemo(() => { - if (!imageUrl) return []; - - return [ - typeof imageUrl === "string" - ? { - uid: "-1", - name: "uploaded-image", - status: "done", - url: imageUrl, - thumbUrl: imageUrl, - } - : { - uid: imageUrl.uid || "-1", - name: imageUrl.name || "uploaded-image", - status: "done", - originFileObj: imageUrl, - }, - ]; - }, [imageUrl]); - // console.log(1); - - const FilehandleChange = (value: any) => { - // console.log(value,"filevalue"); - if (value.fileList.length === 0) { - formik.setFieldValue(newName, null); - } else { - formik.setFieldValue( - `Questions[${name}].image`, - value?.file?.originFileObj, - ); - } - }; - const customRequest = async ({ onSuccess, no_label, label_icon }: any) => { - onSuccess(); - }; - return ( -
- - - - -
{isError ? "required" : ""}
- {errorMsg} -
-
- ); -}; - -export default File; diff --git a/src/Pages/Admin/question/Model/Malty/QuestionFIeld/HintField.tsx b/src/Pages/Admin/question/Model/Malty/QuestionFIeld/HintField.tsx deleted file mode 100644 index 753a8b3..0000000 --- a/src/Pages/Admin/question/Model/Malty/QuestionFIeld/HintField.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { Form, Input } from "antd"; -import React from "react"; -import useFormField from "../../../../../../Hooks/useFormField"; -import { MdOutlineEdit } from "react-icons/md"; -import { Field } from "formik"; - -const HintField = ({ - name, - label, - label2, - placeholder, - isDisabled, - onChange, - props, - id, - className, -}: any) => { - const newName = `Questions[${name}].hint`; - const { formik, isError, errorMsg, t } = useFormField(newName, props); - const TextFilehandleChange = ( - e: React.ChangeEvent, - ) => { - // console.log('Change:', e.target.value); - formik.setFieldValue(newName, e.target.value); - }; - - return ( -
- - - - -
- ); -}; - -export default React.memo(HintField); diff --git a/src/Pages/Admin/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx b/src/Pages/Admin/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx index 5bb1b33..907b975 100644 --- a/src/Pages/Admin/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx +++ b/src/Pages/Admin/question/Model/Malty/QuestionFIeld/QuestionFIeld.tsx @@ -1,16 +1,10 @@ import React, { useEffect } from "react"; import { Choice } from "../../../../../../types/Item"; -import ValidationField from "../../../../../../Components/ValidationField/ValidationField"; import { useFormikContext } from "formik"; import { useTranslation } from "react-i18next"; import { getCharFromNumber } from "../../../../../../utils/getCharFromNumber"; import TextField from "./TextField"; -import File from "./File"; -import { FaTrash } from "react-icons/fa"; import { useObjectToEdit } from "../../../../../../zustand/ObjectToEditState"; -import { toast } from "react-toastify"; -import CheckboxField from "./CheckboxField"; -import HintField from "./HintField"; import ImageBoxField from "../../../../../../Components/CustomFields/ImageBoxField/ImageBoxField"; import { GoTrash } from "react-icons/go"; diff --git a/src/Pages/Admin/question/Model/Malty/Tags/DynamicTags.tsx b/src/Pages/Admin/question/Model/Malty/Tags/DynamicTags.tsx deleted file mode 100644 index 81b5fd8..0000000 --- a/src/Pages/Admin/question/Model/Malty/Tags/DynamicTags.tsx +++ /dev/null @@ -1,107 +0,0 @@ -import { useFormikContext } from "formik"; -import React from "react"; -import { useTranslation } from "react-i18next"; -import { FaCirclePlus } from "react-icons/fa6"; -import Tag from "./Tag"; -import { useObjectToEdit } from "../../../../../../zustand/ObjectToEditState"; -import { useGetAllTag } from "../../../../../../api/tags"; - -const DynamicTags = ({ parent_index }: { parent_index: number }) => { - const formik = useFormikContext(); - const [t] = useTranslation(); - const { TagsSearch, setTagsSearch, currentTag, currentParentIndex } = - useObjectToEdit(); - const { data } = useGetAllTag({ - name: TagsSearch, - }); - const suggests = data?.data; - - const handleAddChoice = () => { - const length = formik?.values?.Questions?.[parent_index]?.tags.length; - const lastElement = - formik?.values?.Questions?.[parent_index]?.tags[length - 1]?.name; - setTagsSearch(null); - - if (lastElement !== "") { - formik.setFieldValue(`Questions.[${parent_index}].tags`, [ - ...((formik?.values as any)?.Questions?.[parent_index]?.tags as any[]), - - { - id: length + "_new", - name: "", - key: length, - }, - ]); - } else { - } - }; - // console.log(formik?.values); - // console.log(currentTag); - - const handleChoice = (item: any) => { - const length = formik?.values?.Questions?.[parent_index]?.tags?.length; - console.log(currentTag); - - formik.setFieldValue(`Questions.[${parent_index}].tags[${currentTag}]`, { - ...item, - key: length, - }); - setTagsSearch(null); - }; - - // console.log(formik?.values?.tags?.length); - - return ( -
- {formik?.values?.Questions?.[parent_index]?.tags?.length < 1 && ( -

- {" "} - {t("header.add_tag")} -

- )} - -
-
- {( - ((formik?.values as any)?.Questions?.[parent_index] - ?.tags as any[]) || [] - ).map((item: any, index: number) => { - return ( - - ); - })} -
- - {formik?.values?.Questions?.[parent_index]?.tags?.length > 0 && ( -

- -

- )} -
- {TagsSearch && currentParentIndex === parent_index && ( -
- {suggests?.map((item: any, index: number) => { - console.log(currentParentIndex === parent_index); - - return ( -
handleChoice(item)} - > - {item?.name} -
- ); - })} -
- )} -
- ); -}; - -export default DynamicTags; diff --git a/src/Pages/Admin/question/Model/Malty/Tags/Tag.tsx b/src/Pages/Admin/question/Model/Malty/Tags/Tag.tsx deleted file mode 100644 index fbbfcd0..0000000 --- a/src/Pages/Admin/question/Model/Malty/Tags/Tag.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { useFormikContext } from "formik"; -import React, { useRef, useEffect } from "react"; -import { useObjectToEdit } from "../../../../../../zustand/ObjectToEditState"; -import { FaTrash } from "react-icons/fa"; - -const Tag = ({ - data, - index, - parent_index, -}: { - data: any; - index: number; - parent_index: number; -}) => { - const inputRef = useRef(null); - const timeoutRef = useRef(null); - const DEBOUNCE_DELAY = 500; - const formik = useFormikContext(); - const { setTagsSearch, setCurrentTag, setCurrentParentIndex } = - useObjectToEdit(); - console.log(formik?.values?.Questions); - - useEffect(() => { - if (inputRef.current) { - inputRef.current.style.width = `${(formik?.values?.Questions?.[parent_index]?.tags[index]?.name?.length + 1) * 8}px`; - } - }, [formik?.values?.Questions?.[parent_index]?.tags[index]?.name]); - - const handleEditInputChange = (e: React.ChangeEvent) => { - // console.log(e.target.value); - - formik.setFieldValue(`Questions.[${parent_index}].tags[${index}]`, { - key: parent_index, - name: e.target.value, - id: `${parent_index}_key`, - }); - setCurrentTag(index); - setCurrentParentIndex(parent_index); - if (timeoutRef.current) { - clearTimeout(timeoutRef.current); - } - - timeoutRef.current = setTimeout(() => { - setTagsSearch(e.target.value); - }, DEBOUNCE_DELAY); - }; - - const handleDeleteChoice = () => { - console.log(data); - - // Create a copy of current tags array - const currentTags = [...formik.values.tags]; - - // Remove the item at the specified index from the array - currentTags.splice(index, 1); - - console.log(currentTags); // Log the updated tags array - - // Update formik field value with the updated tags array - formik.setFieldValue(`Questions.[${parent_index}].tags`, currentTags); - - // Reset search state if needed - setTagsSearch(null); - }; - - return ( -
- - -
- ); -}; - -export default Tag; diff --git a/src/Pages/Admin/question/Model/formUtil.ts b/src/Pages/Admin/question/formUtil.ts similarity index 98% rename from src/Pages/Admin/question/Model/formUtil.ts rename to src/Pages/Admin/question/formUtil.ts index dc19acd..1a4f553 100644 --- a/src/Pages/Admin/question/Model/formUtil.ts +++ b/src/Pages/Admin/question/formUtil.ts @@ -1,5 +1,5 @@ import * as Yup from "yup"; -import { Question } from "../../../../types/Item"; +import { Question } from "../../../types/Item"; import { toast } from "react-toastify"; export const getInitialValues = (objectToEdit: Question): any => {