import { FileAddOutlined, UploadOutlined } from '@ant-design/icons'; import { Alert, Button, Modal, Typography, Upload, message } from 'antd'; import type { UploadFile } from 'antd/es/upload/interface'; import { useState } from 'react'; import { ApiError } from '../../api/client'; import { summarizeUpload, uploadFiles } from '../../services/api/files'; type Props = { legalEntityId: string; consolidationId: string | null; organizationName?: string | null; open: boolean; onClose: () => void; onUploaded: () => void; }; type Summary = ReturnType; export function UploadDocumentsModal({ legalEntityId, consolidationId, organizationName, open, onClose, onUploaded }: Props) { const [fileList, setFileList] = useState([]); const [uploading, setUploading] = useState(false); const [summary, setSummary] = useState(null); const close = () => { if (uploading) return; setFileList([]); setSummary(null); onClose(); }; const handleOk = async () => { if (summary) { close(); return; } const files = fileList.map((f) => f.originFileObj).filter((f): f is NonNullable => Boolean(f)); setUploading(true); try { const result = summarizeUpload(await uploadFiles(legalEntityId, files, consolidationId)); setSummary(result); if (result.accepted.length > 0) onUploaded(); else message.error('Ни один файл не принят'); } catch (e: unknown) { message.error(e instanceof ApiError ? e.message : 'Не удалось загрузить файлы'); } finally { setUploading(false); } }; return ( , disabled: !summary && fileList.length === 0, style: { background: summary || fileList.length > 0 ? '#237804' : undefined }, }} cancelText='Отмена' confirmLoading={uploading} closable={!uploading} destroyOnHidden> {organizationName && ( {organizationName} )} {summary ? ( <> {summary.accepted.length > 0 && ( )} {summary.rejected.length > 0 && ( {summary.rejected.map((r, i) => (
  • {r.name} — {r.reason}
  • ))} } /> )} ) : ( { setFileList((prev) => prev.some((f) => f.uid === file.uid) ? prev : [...prev, { uid: file.uid, name: file.name, originFileObj: file }], ); return false; }} onRemove={(file) => setFileList((prev) => prev.filter((f) => f.uid !== file.uid))} showUploadList={{ showRemoveIcon: !uploading }}>

    Перетащите файлы сюда

    ОСВ, ББ, ОФР: xls, xlsx, xlsb, pdf, png, jpg — тип и период определятся автоматически

    )}
    ); }