import {Box, Button, Paper, Typography} from "@mui/material"; import {useTranslations} from "next-intl"; import AddIcon from "@mui/icons-material/Add"; import DeleteForeverIcon from "@mui/icons-material/DeleteForever"; import {useRef} from "react"; const UploadSystem = ({ selectedImage, setselectedImage, handleUploadChange, fieldname, setFieldValue, imageAlt, imageSize, fileType, fileName, setShowAddIcon, showAddIcon, }) => { const t = useTranslations(); const fileInputRef = useRef(null); const handleClick = () => { fileInputRef.current.click(); }; const handleDeleteImage = () => { setselectedImage(null); setFieldValue(fieldname, null); setShowAddIcon(true); if (fileInputRef.current) { fileInputRef.current.value = ""; } }; const isDocumentFormat = (fileType) => { const documentFormats = [ "application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", ]; return documentFormats.includes(fileType); }; return ( {showAddIcon ? ( // Show the add icon and "Upload File" text when no image is selected <> {t("UploadSystem.upload_file")} ) : ( // Show the uploaded content along with the delete button when an image or document is selected <> {fileType && fileType.startsWith("image/") ? ( ) : ( fileType && isDocumentFormat(fileType) && ( {fileName} ) )} )} ); }; export default UploadSystem;