diff --git a/src/components/ui/statuses.ts b/src/components/ui/statuses.ts index 2f6add0..c9af615 100644 --- a/src/components/ui/statuses.ts +++ b/src/components/ui/statuses.ts @@ -44,17 +44,4 @@ export const REVOCATION_STATUS: Record = { pending: { label: 'Ожидает ответа', plural: 'Ожидают', color: 'blue' }, approved: { label: 'Одобрил отзыв', plural: 'Одобрили', color: 'green' }, rejected: { label: 'Против отзыва', plural: 'Против', color: 'red' }, -} - -export const TASK_STATUS: Record = { - pending: { label: 'В работе', plural: 'В работе', color: 'blue' }, - waiting: { label: 'В очереди', plural: 'В очереди', color: 'gray' }, - completed: { label: 'Выполнена', plural: 'Выполнены', color: 'green' }, - cancelled: { label: 'Отменена', plural: 'Отменены', color: 'red' }, -} - -export const USER_STATUS: Record = { - active: { label: 'Активен', plural: 'Активные', color: 'green' }, - blocked: { label: 'Заблокирован', plural: 'Заблокированные', color: 'red' }, - fired: { label: 'Уволен', plural: 'Уволенные', color: 'gray' }, } \ No newline at end of file diff --git a/src/lib/fileApi.ts b/src/lib/fileApi.ts new file mode 100644 index 0000000..071c723 --- /dev/null +++ b/src/lib/fileApi.ts @@ -0,0 +1,55 @@ +import apiClient from '@/api/client' + +export const approvalFileUrl = (approvalId: number, fileId: number, download = false) => + `/approvals/${approvalId}/files/${fileId}${download ? '/download' : ''}` + +export const taskFileUrl = (taskId: number, fileId: number, download = false) => + `/approval-tasks/${taskId}/files/${fileId}${download ? '/download' : ''}` + +export async function fetchFileBlob(url: string): Promise { + const response = await apiClient.get(url, { responseType: 'blob' }) + return response.data +} + +export async function saveFile(url: string, fileName: string): Promise { + const blob = await fetchFileBlob(url) + const objectUrl = window.URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = objectUrl + link.setAttribute('download', fileName) + document.body.appendChild(link) + link.click() + link.remove() + window.URL.revokeObjectURL(objectUrl) +} + +const MIME_BY_EXT: Record = { + pdf: 'application/pdf', + png: 'image/png', + jpg: 'image/jpeg', + jpeg: 'image/jpeg', + gif: 'image/gif', + webp: 'image/webp', + svg: 'image/svg+xml', + txt: 'text/plain', + csv: 'text/csv', + doc: 'application/msword', + docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + xls: 'application/vnd.ms-excel', + xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + zip: 'application/zip', +} + +export function getMimeType(fileName: string): string { + const ext = fileName.split('.').pop()?.toLowerCase() ?? '' + return MIME_BY_EXT[ext] ?? 'application/octet-stream' +} + +export function isPreviewable(mime: string): boolean { + return mime.startsWith('image/') || mime === 'application/pdf' || mime === 'text/plain' +} + +export function formatFileSize(kb: number): string { + if (kb < 1024) return `${kb} КБ` + return `${(kb / 1024).toFixed(1).replace('.', ',')} МБ` +} \ No newline at end of file diff --git a/src/pages/approvals/ApprovalsPage.tsx b/src/pages/approvals/ApprovalsPage.tsx index aa2665d..f71bfc1 100644 --- a/src/pages/approvals/ApprovalsPage.tsx +++ b/src/pages/approvals/ApprovalsPage.tsx @@ -13,7 +13,7 @@ import { useTopics } from '@/features/topics/hooks/useTopics' import { useDepartments } from '@/features/departments/hooks/useDepartments' import { useCategories } from '@/features/categories/hooks/useCategories' import { useUsers } from '@/features/users/hooks/useUsers' -import { approvalsApi } from '@/api/approvals' +import { approvalsApi, type ApprovalsListParams, type ApprovalsReportParams } from '@/api/approvals' import { formatMsk } from '@/utils/date' import { PageHeader } from '@/components/ui/PageHeader' @@ -94,7 +94,7 @@ function ReportButton() { const handleDownload = async () => { setLoading(true) try { - const params: Record = { all_access: true } + const params: ApprovalsReportParams = { all_access: true } if (range[0]) params.date_from = fmtDate(range[0]) if (range[1]) params.date_to = fmtDate(range[1]) @@ -246,8 +246,7 @@ export default function ApprovalsPage() { // === Запрос === const requestParams = useMemo(() => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const params: any = { offset: (page - 1) * LIMIT, limit: LIMIT } + const params: ApprovalsListParams = { offset: (page - 1) * LIMIT, limit: LIMIT } if (filters.id) params.id = Number(filters.id) if (search) params.content = search if (filters.status) params.status = filters.status