Updated approvals page ui
Deploy Frontend / build-and-deploy (push) Successful in 32s Details

This commit is contained in:
romanskijdev 2026-11-18 13:13:38 +03:00
parent a05a78f27e
commit 386c505ce1
3 changed files with 58 additions and 17 deletions

View File

@ -44,17 +44,4 @@ export const REVOCATION_STATUS: Record<string, StatusMeta> = {
pending: { label: 'Ожидает ответа', plural: 'Ожидают', color: 'blue' },
approved: { label: 'Одобрил отзыв', plural: 'Одобрили', color: 'green' },
rejected: { label: 'Против отзыва', plural: 'Против', color: 'red' },
}
export const TASK_STATUS: Record<string, StatusMeta> = {
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<string, StatusMeta> = {
active: { label: 'Активен', plural: 'Активные', color: 'green' },
blocked: { label: 'Заблокирован', plural: 'Заблокированные', color: 'red' },
fired: { label: 'Уволен', plural: 'Уволенные', color: 'gray' },
}

55
src/lib/fileApi.ts Normal file
View File

@ -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<Blob> {
const response = await apiClient.get<Blob>(url, { responseType: 'blob' })
return response.data
}
export async function saveFile(url: string, fileName: string): Promise<void> {
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<string, string> = {
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('.', ',')} МБ`
}

View File

@ -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<string, unknown> = { 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