upd: dokument
Deskripsi: - unduh file No Issues
This commit is contained in:
@@ -38,6 +38,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
const [share, setShare] = useState(false)
|
const [share, setShare] = useState(false)
|
||||||
const [more, setMore] = useState(false)
|
const [more, setMore] = useState(false)
|
||||||
const [shareSelected, setShareSelected] = useState(false)
|
const [shareSelected, setShareSelected] = useState(false)
|
||||||
|
const [copyAllowed, setCopyAllowed] = useState(true)
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const path = searchParams.get('path')
|
const path = searchParams.get('path')
|
||||||
const [dataDocument, setDataDocument] = useState<IDataDocument[]>([])
|
const [dataDocument, setDataDocument] = useState<IDataDocument[]>([])
|
||||||
@@ -89,6 +90,13 @@ export default function NavbarDocumentDivision() {
|
|||||||
} else {
|
} else {
|
||||||
setShareSelected(false)
|
setShareSelected(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cek = selectedFiles.some((i: any) => i?.category == 'FOLDER')
|
||||||
|
if (cek || shareSelected || selectedFiles.length > 1) {
|
||||||
|
setCopyAllowed(false)
|
||||||
|
} else {
|
||||||
|
setCopyAllowed(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSelectAll = () => {
|
const handleSelectAll = () => {
|
||||||
@@ -218,6 +226,28 @@ export default function NavbarDocumentDivision() {
|
|||||||
setRename(true)
|
setRename(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onDownload = async () => {
|
||||||
|
try {
|
||||||
|
const fileUrl = `https://wibu-storage.wibudev.com/api/files/${selectedFiles[0].idStorage}`;
|
||||||
|
const response = await fetch(fileUrl);
|
||||||
|
const blob = await response.blob();
|
||||||
|
|
||||||
|
// Create a link element, use Blob URL
|
||||||
|
const link = document.createElement("a");
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
link.href = url;
|
||||||
|
link.download = `${selectedFiles[0].name}.${selectedFiles[0].extension}`; // Nama file yang akan diunduh
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(link);
|
||||||
|
} catch (error) {
|
||||||
|
alert(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
{(selectedFiles.length > 0 || dariSelectAll) && (
|
{(selectedFiles.length > 0 || dariSelectAll) && (
|
||||||
@@ -247,9 +277,14 @@ export default function NavbarDocumentDivision() {
|
|||||||
}}>
|
}}>
|
||||||
<Flex justify={"center"} align={"center"} h={"100%"} w={"100%"}>
|
<Flex justify={"center"} align={"center"} h={"100%"} w={"100%"}>
|
||||||
<SimpleGrid cols={{ base: 5, sm: 5, lg: 5 }} spacing="xs">
|
<SimpleGrid cols={{ base: 5, sm: 5, lg: 5 }} spacing="xs">
|
||||||
<Flex justify={'center'} align={'center'} direction={'column'}>
|
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||||
<BsDownload size={20} color={(selectedFiles.length > 0) ? 'white' : '#656060'} />
|
onClick={() => {
|
||||||
<Text fz={12} ta={"center"} c={(selectedFiles.length > 0) ? 'white' : '#656060'}>Unduh</Text>
|
if ((selectedFiles.length > 0 && copyAllowed)) {
|
||||||
|
onDownload()
|
||||||
|
}
|
||||||
|
}}>
|
||||||
|
<BsDownload size={20} color={(selectedFiles.length > 0 && copyAllowed) ? 'white' : '#656060'} />
|
||||||
|
<Text fz={12} ta={"center"} c={(selectedFiles.length > 0 && copyAllowed) ? 'white' : '#656060'}>Unduh</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex justify={'center'} align={'center'} direction={'column'}>
|
<Flex justify={'center'} align={'center'} direction={'column'}>
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
|
|||||||
Reference in New Issue
Block a user