arm-core/web/src/layouts/ConsolidationsList.tsx
Andrey Epifancev d71c46e846 fix(web): список консолидаций и «Взять в работу» по спеке (AURORA-1589, PR #166)
«Только в работе» выключен по умолчанию, параметр — boolean; ошибка загрузки списка
показывается; пункты «⋯» disabled с подсказкой «Будет позже», клик не выбирает строку;
«Взять в работу» неактивна по коду CANCELLED. Модалка [35]: опечатки, плейсхолдер,
≤ 1000 символов, «К3», ошибки (403 и прочие) — текст сервера, ФИО без второй точки;
после взятия в работу перечитываются список и панель «Организации» («Ответственный»).
Боковое меню: thunk списка с объектом, отступ секций. Порядок импортов (biome).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 01:15:55 +04:00

118 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { message } from 'antd';
import { useEffect, useState } from 'react';
import { useParams, useSearchParams } from 'react-router-dom';
import { ApiError } from '../api/client';
import PageTitle from '../components/PageTitle';
import { fetchOneCompanyGroup } from '../services/api/directories/company_groups';
import { setSelectedVersion } from '../store/slices/consolidations/consolidationsSlice';
import { useAppDispatch } from '../store/store';
import { ConsoleLegalEntitiesTable } from '../widgets/ConsoleLegalEntities/ConsoleLegalEntities';
import { ConsoleTableWidget } from '../widgets/ConsoleTable/ConsoleTable';
import { DocumentsDrawer } from '../widgets/FilesDrawer/FilesDrawer';
// список консолидаций грузит ConsoleTableWidget (с фильтром «Только в работе»), здесь — только группа
function errorText(e: unknown): string {
if (e instanceof ApiError) return e.message;
return 'Не удалось загрузить группу компаний';
}
export function ConsolidationPage() {
const [drawerOpen, setDrawerOpen] = useState(false);
const [reloadKey, setReloadKey] = useState(0);
const { group_id } = useParams();
const [searchParams] = useSearchParams();
const versionParam = searchParams.get('version');
const dispatch = useAppDispatch();
const [comGroupName, setComGroupName] = useState('');
const [locationPath, setLocationPath] = useState('Отчётность>');
const [desc, setDesc] = useState('');
useEffect(() => {
if (!group_id) return;
async function getAllInfo(id: string) {
try {
const data = await fetchOneCompanyGroup(id);
setComGroupName(data.name);
setLocationPath(`Отчётность>${data.name}>Консолидации`);
setDesc(`${data.legal_entities_count} организаций`);
} catch (e: unknown) {
message.error(errorText(e));
}
}
getAllInfo(group_id);
}, [group_id]);
// выбор версии следует за ?version= и не перезагружает список
useEffect(() => {
dispatch(setSelectedVersion(versionParam));
}, [dispatch, versionParam]);
// уход со страницы сбрасывает выбор (при смене группы ?version= пропадает из URL — выбор сбросит эффект выше)
useEffect(() => {
return () => {
dispatch(setSelectedVersion(null));
};
}, [dispatch]);
return (
<div
style={{
padding: 12,
display: 'flex',
flexDirection: 'column',
height: '100vh',
}}>
<PageTitle backable location={locationPath} header={comGroupName} description={desc} />
<main
style={{
flex: '1 1 auto',
minHeight: 0,
overflow: 'auto',
display: 'flex',
flexDirection: 'column',
gap: 10,
}}>
<div
style={{
flex: '2 1 0',
backgroundColor: 'white',
borderTopLeftRadius: 12,
borderTopRightRadius: 12,
overflowY: 'hidden',
display: 'flex',
flexDirection: 'column',
minHeight: 0,
}}>
{/* после «Взять в работу» перечитываем и панель «Организации»: в ней «Ответственный» */}
<ConsoleTableWidget onVersionLocked={() => setReloadKey((k) => k + 1)} />
</div>
<div
style={{
flex: '3 1 0',
backgroundColor: 'white',
borderTopLeftRadius: 12,
borderTopRightRadius: 12,
overflowY: 'hidden',
display: 'flex',
flexDirection: 'column',
minHeight: 0,
}}>
<ConsoleLegalEntitiesTable
reloadKey={reloadKey}
onDrawerOpen={() => {
setDrawerOpen(true);
}}
/>
</div>
</main>
<DocumentsDrawer
open={drawerOpen}
onClose={() => {
setDrawerOpen(false);
setReloadKey((k) => k + 1);
}}
/>
</div>
);
}