import axios from "axios"; import { Box, SxProps, Theme, Typography, useTheme } from "@mui/material"; import { Document, Page } from "react-pdf"; import { Buffer } from "buffer"; import { downloadFileToDevice } from "@root/utils/downloadFileToDevice"; interface Props { text: string; documentUrl: string; sx?: SxProps; } export default function DocumentItem({ text, documentUrl = "", sx }: Props) { const theme = useTheme(); const downloadFile = async () => { const { data } = await axios.get(documentUrl, { responseType: "arraybuffer", }); if (!data) { return; } downloadFileToDevice("document.pdf", Buffer.from(data)); return; }; return ( {text} {documentUrl && ( <> {documentUrl.split("/").pop()?.split(".")?.[0]} )} ); }