diff --git a/public/Icon/QuestionIcon.svg b/public/Icon/QuestionIcon.svg new file mode 100644 index 0000000..bb52f40 --- /dev/null +++ b/public/Icon/QuestionIcon.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx b/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx index d55e2f6..d76796f 100644 --- a/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx +++ b/src/Components/CustomFields/ImageBoxField/ImageBoxField.tsx @@ -1,25 +1,34 @@ import { useFormikContext } from "formik"; -import { useTranslation } from "react-i18next"; -import { useState, useRef } from "react"; +import { useState, useRef, useEffect } from "react"; import './ImageBoxField.scss'; import ImageIcon from "./ImageIcon"; import ImageCancelIcon from "./ImageCancelIcon"; +import { getNestedValue } from "../../../utils/getNestedValue"; +import { generateImagePreview } from "./generateImagePreview"; + +// Helper function to generate image preview from a File + const ImageBoxField = ({ name }: any) => { const formik = useFormikContext(); - const [imagePreview, setImagePreview] = useState(""); - const [t] = useTranslation(); - - const fileInputRef = useRef(null); + const value = getNestedValue(formik.values, name); + const [imagePreview, setImagePreview] = useState(null); + const fileInputRef = useRef(null); + + useEffect(() => { + if (value instanceof File) { + generateImagePreview(value, setImagePreview); + } else if (typeof value === 'string') { + setImagePreview(value); + } else { + setImagePreview(null); + } + }, [value]); const handleFileChange = (event: any) => { const file = event.target.files[0]; if (file) { - const reader = new FileReader(); - reader.onloadend = () => { - setImagePreview(reader.result as string); - }; - reader.readAsDataURL(file); + generateImagePreview(file, setImagePreview); formik.setFieldValue(name, file); } }; @@ -27,7 +36,7 @@ const ImageBoxField = ({ name }: any) => { const handleButtonClick = () => { const fileInput = fileInputRef.current; if (fileInput) { - fileInput.click(); + fileInput.click(); } }; @@ -49,7 +58,9 @@ const ImageBoxField = ({ name }: any) => { ) : ( - <> +
+ hidden +
)}
@@ -62,7 +73,7 @@ const ImageBoxField = ({ name }: any) => { void) => { + const reader = new FileReader(); + reader.onloadend = () => { + setImagePreview(reader.result as string); + }; + reader.readAsDataURL(file); + }; \ No newline at end of file diff --git a/src/Components/DataTable/SearchField.tsx b/src/Components/DataTable/SearchField.tsx index 6b8c058..93eb200 100644 --- a/src/Components/DataTable/SearchField.tsx +++ b/src/Components/DataTable/SearchField.tsx @@ -62,7 +62,7 @@ const SearchField: React.FC = ({ placeholder, searchBy }) => { return (
- + {/* */} void; + withIcon?:boolean } const SearchFieldWithSelect: React.FC = ({ options, placeholder, onSelect, + withIcon=false }) => { const [isOpen, setIsOpen] = useState(false); const [selectedOption, setSelectedOption] = useState