import { Button, Upload } from "antd"; import { UploadOutlined } from "@ant-design/icons"; import useFormField from "../../../Hooks/useFormField"; import { ImageBaseURL } from "../../../api/config"; const MaltyFile = ({ name, label, onChange, isDisabled, placeholder, className, props, }: any) => { const { formik, t, isError } = useFormField(name, props); let imageUrl = formik?.values?.[name] ?? null; // console.log(imageUrl); // Mapping formik values to fileList format const fileList = imageUrl ? imageUrl.map((file: any, index: number) => { let fileUrl = ""; if (typeof file === "string") { fileUrl = file.replace("public", "/storage"); } console.log(file instanceof File); return file instanceof File ? { uid: index, name: file?.name, status: "done", originFileObj: file, } : { uid: index, id: file?.id, name: file?.name, status: "done", url: ImageBaseURL + fileUrl || "", thumbUrl: ImageBaseURL + fileUrl || "", }; }) : []; const FilehandleChange = ({ fileList }: any) => { if (fileList.length === 0) { formik.setFieldValue(name, null); } else { formik.setFieldValue( name, fileList.map((file: any) => file?.originFileObj ?? file), ); } }; // Custom request function const customRequest = async ({ onSuccess }: any) => { // Perform any necessary actions before onSuccess is called onSuccess(); }; return (