import React, { useState, useEffect } from "react"; import { Button, Form, Image, Input, message, Modal, Upload, } from "antd"; import { useStore } from "../../utils/useStore"; import { appConfig } from "../../config/app"; import { LoadingOutlined, UploadOutlined } from "@ant-design/icons"; export const PaybackModal = ({ visible, onCreate, onCancel, initialData }) => { const [form] = Form.useForm(); const store = useStore(); const [fileList, setFileList] = useState([]); const [previewTitle, setPreviewTitle] = useState(""); const [previewImage, setPreviewImage] = useState(""); const [loading, setLoading] = useState(false); const [fileUrl, setFileUrl] = useState(""); const firstIndexFileList = fileList[0]; const [isLoading, setIsLoading] = useState(false); useEffect(() => { const init = async () => { try { setIsLoading(true); //await store.membership.getData(); //await store.role.getData(); await store.authentication.getProfile(); setIsLoading(false); } catch (e) { setIsLoading(false); } }; init(); }, []); const beforeUpload = (file) => { let isPdf, isLt2M; let allowedFile = ["image/jpeg", "image/png", "application/pdf"]; let isValid = allowedFile.includes(file.type); if (!isValid) { message.error("You can only upload PDF or Image file!"); } // return file.type === 'application/pdf' ? true : Upload.LIST_IGNORE; isLt2M = file.size / 1024 / 1024 < 2; if (!isLt2M) { message.error("File must smaller than 2MB!"); } return isValid && isLt2M ? true : Upload.LIST_IGNORE; }; const handlePreview = async (file) => { const fileUrl = appConfig.apiUrl + file.response.path; setPreviewTitle(file.url?.substring(file.url?.lastIndexOf("/") + 1)); }; const handleChange = ({ fileList }) => { setFileList(fileList); if (fileList.length && fileList[0].status === "done") { form.setFieldsValue({ file_url: fileList[0].response.path, }); console.log(fileList, "apaaaaaa"); setFileUrl(fileList[0].response.path); setPreviewImage(fileList[0].response.path); setPreviewTitle(fileList[0].name); } }; const uploadButton = (