import { CommentOutlined } from '@ant-design/icons'; import { Button, Empty, Form, Result, Select, Spin, Tooltip } from 'antd'; import { useCallback, useEffect, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { ApiError } from '../api/client'; import PageTitle from '../components/PageTitle'; import { TableTag } from '../components/TableTag/TableTag'; import { TAG_PRESETS } from '../components/TableTag/presets'; import { fetchLegalEntity } from '../services/api/directories/company_groups'; import { getDocument } from '../services/api/documents'; import { getFile, listLegalEntityFiles } from '../services/api/files'; import type { DocumentOut } from '../types/api'; import { documentTypeLabel, periodLabel } from '../utils/labels'; import CommentModal from '../widgets/DocumentReview/CommentModal'; import { OsvDocument } from '../widgets/DocumentReview/OsvDocument'; import { StatementReview } from '../widgets/DocumentReview/StatementReview'; import { documentPageTitle, documentSubtitle, optionStatusBadge, statusBadge } from '../widgets/DocumentReview/reviewView'; import { documentViewKind } from '../widgets/DocumentReview/viewKind'; import { type DocumentRow, buildDocumentRows } from '../widgets/FilesDrawer/documentRows'; type DocumentOption = { value: string | null; label: string; disabled: boolean; row: DocumentRow }; export function DocumentPage() { const { document_id } = useParams(); const navigate = useNavigate(); const [doc, setDoc] = useState(null); const [entityName, setEntityName] = useState(''); const [subtitle, setSubtitle] = useState(null); const [error, setError] = useState(null); const [documentOptions, setDocumentOptions] = useState([]); const [commentOpen, setCommentOpen] = useState(false); const load = useCallback(async () => { if (!document_id) return; try { const d = await getDocument(document_id); setDoc(d); setError(null); fetchLegalEntity(d.legal_entity_id) .then((le) => setEntityName(le.name)) .catch(() => setEntityName('')); getFile(d.file_id) .then((f) => { setSubtitle(documentSubtitle(f)); // переключатель документа — файлы того же ЮЛ в той же консолидации, что и файл документа (без неё — все файлы ЮЛ) listLegalEntityFiles(d.legal_entity_id, f.consolidation_id) .then((files) => setDocumentOptions( buildDocumentRows(files).map((row) => ({ value: row.documentId ?? row.fileId, label: row.name, disabled: !row.linkable, row, })), ), ) .catch(() => setDocumentOptions([])); }) .catch(() => setSubtitle(null)); } catch (e: unknown) { setError(e instanceof ApiError ? e.message : 'Не удалось открыть документ'); } }, [document_id]); useEffect(() => { void load(); }, [load]); if (error) { return navigate(-1)}>Назад} />; } if (!doc) { return ; } const badge = statusBadge(doc.status); const kind = documentViewKind(doc); // Документ в статусе ERROR — данных формы/строк нет: показываем карточку и понятный текст, а не пустой экран. const broken = doc.status === 'ERROR' && kind !== 'none'; return (
style={{ width: '100%' }} value={doc.id} options={documentOptions} onChange={(value) => navigate(`/documents/${value}`)} optionRender={(option) => (
{/* у ББ и ОФР из одного PDF имя файла одно — различаются второй строкой (тип · формат · дата) */}
{option.data.label}
{option.data.row.subtitle}
)} />
} />
{broken && } {!broken && kind === 'osv' && } {!broken && kind === 'statement' && } {kind === 'none' && }
setCommentOpen(false)} /> ); }