import { CloseOutlined, UploadOutlined } from '@ant-design/icons'; import { Button, Drawer, Switch, Tooltip, Typography } from 'antd'; import { useEffect, useState } from 'react'; import { fetchLegalEntity } from '../../services/api/directories/company_groups'; import { isInWork, useCurrentConsolidation } from '../../store/slices/consolidations/selectors'; import { useAppSelector } from '../../store/store'; import type { FileOut, LegalEntityBrief } from '../../types/api'; import { FilesList } from './FilesList'; import { UploadDocumentsModal } from './UploadDocumentsModal'; import { consolidationLabel } from './consolidationLabel'; import { useLegalEntityFiles } from './useLegalEntityFiles'; const UPLOAD_DISABLED_HINT = 'Загрузка доступна только в версии в работе'; export function DocumentsDrawer({ open, onClose }: { open: boolean; onClose: () => void }) { const [uploadOpen, setUploadOpen] = useState(false); const [entity, setEntity] = useState(null); const [showAll, setShowAll] = useState(false); const { current_legal_entity_id, consolidations } = useAppSelector((s) => s.consolidations); const current = useCurrentConsolidation(); // консолидация не определена (версии нет в списке ГК) — режим «все» без переключателя (design D-3) const desk = current !== null && !showAll; const consolidationId = desk ? current.consolidation_id : null; const { files, loading, reload } = useLegalEntityFiles(current_legal_entity_id, consolidationId, open); const canUpload = current !== null && isInWork(current.version_status); const labelFor = desk ? undefined : (f: FileOut) => consolidationLabel(f.consolidation_id, consolidations, current?.consolidation_id ?? null); useEffect(() => { setShowAll(false); // новая панель открывается столом консоли setEntity(null); if (!open || !current_legal_entity_id) return; let cancelled = false; fetchLegalEntity(current_legal_entity_id) .then((e) => { if (!cancelled) setEntity(e); }) .catch(() => { // без имени: шапка остаётся с подписью, панель не падает }); return () => { cancelled = true; }; }, [open, current_legal_entity_id]); const uploadButton = ( ); return ( } aria-label='Закрыть' onClick={onClose} />} title={
Первичные документы {entity && ( <>
{entity.name}
{entity.inn} )}
}>
{canUpload ? ( uploadButton ) : ( {uploadButton} )} {current !== null && ( Все документы организации )}
{current_legal_entity_id && ( setUploadOpen(false)} onUploaded={() => void reload()} /> )}
); }