import postDocument from "@/services/api/basePostDocument"; import FileUploadIcon from "@mui/icons-material/FileUpload"; import { Button, Typography, useTheme } from "@mui/material"; import Grid from "@mui/material/Unstable_Grid2"; import { enqueueSnackbar } from "notistack"; import { useRef } from "react"; export default function UploadFile({ fetchChunks }) { const theme = useTheme(); const fileInputRef = useRef(null); const openExplorer = () => { fileInputRef.current.click(); }; const onHandleFileChange = async (event) => { const url = "/document/upload_file"; const uploadedfile = event.target.files[0]; if (!uploadedfile) return; const formData = new FormData(); formData.append("file", uploadedfile); try { await postDocument(url, formData); await fetchChunks(); } catch (error) { enqueueSnackbar( "Error uploading file: " + error.detail || error.message, { variant: "error", }); } }; return ( ); }