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({ fetchDocuments, fetchChunks }) { const theme = useTheme(); const fileInputRef = useRef(null); const openExplorer = () => { fileInputRef.current.click(); }; const onHandleFileChange = async (event) => { const url = "/upload/document"; const uploadedfile = event.target.files[0]; if (!uploadedfile) return; const formData = new FormData(); formData.append("file", uploadedfile); try { await postDocument(url, formData); await fetchDocuments(); await fetchChunks(); } catch (error) { enqueueSnackbar(error.detail || error.message, { variant: "error", }); } }; return ( ); }