import { useDocuments, useDownload, useFolders } from '../hooks/swrHooks' import { IDocument, IDocumentFolder } from '../interfaces/documents' import React, { useEffect, useState } from 'react' import DocumentService from '../services/DocumentService' import { mutate } from 'swr' import FileViewer from './modals/FileViewer' import { IconCancel, IconDownload, IconFileUpload, IconX } from '@tabler/icons-react' import { Breadcrumb, BreadcrumbButton, BreadcrumbDivider, BreadcrumbItem, Button, createTableColumn, DataGrid, DataGridBody, DataGridCell, DataGridHeader, DataGridHeaderCell, DataGridRow, Divider, Field, ProgressBar, Spinner, TableCellLayout } from '@fluentui/react-components' import { DocumentAdd20Regular, DocumentColor, DocumentRegular, DocumentTextColor, FolderRegular, ImageColor, TableColor } from '@fluentui/react-icons' interface DocumentProps { doc: IDocument; } const handleSave = async (file: Blob, filename: string) => { const link = document.createElement('a') link.href = window.URL.createObjectURL(file) link.download = filename link.click() link.remove() window.URL.revokeObjectURL(link.href) } function getFileExtension(filename: string): string { return filename.split('.').pop()?.toLowerCase() || ''; } function handleDocFormatIcon(docName: string) { const ext = getFileExtension(docName); switch (ext) { case 'docx': return case 'pdf': return case 'xlsx': return case 'jpg': return default: return } } function ItemDocument({ doc }: DocumentProps) { const [shouldFetch, setShouldFetch] = useState(false) const { file, isLoading } = useDownload(shouldFetch ? doc?.document_folder_id : null, shouldFetch ? doc?.id : null) useEffect(() => { if (shouldFetch) { if (file) { handleSave(file, doc.name) setShouldFetch(false) } } }, [shouldFetch, file, doc.name]) return ( {filesToUpload.length > 0 && <> } {isUploading && } {filesToUpload.length > 0 &&
{filesToUpload.map((file, index) => (
))}
} }
({ kind: "doc", data: doc })) : (folders ?? []).map((folder: IDocumentFolder) => ({ kind: "folder", data: folder }))} columns={[ createTableColumn({ columnId: "name", renderHeaderCell: () => "Название", renderCell: (item) => ( }> {item.data.name} ), }), createTableColumn({ columnId: "date", renderHeaderCell: () => "Дата создания", renderCell: (item) => new Date(item.data.create_date).toLocaleDateString(), }), createTableColumn({ columnId: "actions", renderHeaderCell: () => "", renderCell: (item) => { if (item.kind === "doc") { // replace with your return ; } return null; }, }), ]} focusMode="cell" resizableColumns getRowId={(item) => item.data.id} > {({ renderHeaderCell }) => ( {renderHeaderCell()} )} {({ item, rowId }: { item: { kind: string, data: any }, rowId: any }) => ( { if (item.kind === "doc") { const index = documents?.findIndex((d: any) => d.id === item.data.id) ?? -1; handleDocumentClick(index); } else { handleFolderClick(item.data as IDocumentFolder); } }} > {({ renderCell }) => {renderCell(item)}} )}
) }