2023-12-13 14:32:57 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
2023-12-18 19:42:27 +03:00
|
|
|
|
import clsx from 'clsx';
|
2024-12-13 21:31:09 +03:00
|
|
|
|
import { useState } from 'react';
|
2023-12-07 01:21:27 +03:00
|
|
|
|
|
2024-01-04 19:38:12 +03:00
|
|
|
|
import Checkbox from '@/components/ui/Checkbox';
|
2025-01-16 16:31:32 +03:00
|
|
|
|
import Modal from '@/components/ui/Modal';
|
2024-05-27 20:42:34 +03:00
|
|
|
|
import { ConstituentaID, IRSForm } from '@/models/rsform';
|
2025-01-16 16:31:32 +03:00
|
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
2024-03-19 19:19:08 +03:00
|
|
|
|
import { prefixes } from '@/utils/constants';
|
2023-12-13 14:32:57 +03:00
|
|
|
|
|
2024-06-26 19:47:31 +03:00
|
|
|
|
import ListConstituents from './ListConstituents';
|
2023-12-07 01:21:27 +03:00
|
|
|
|
|
2025-01-16 16:31:32 +03:00
|
|
|
|
export interface DlgDeleteCstProps {
|
2024-07-30 16:00:09 +03:00
|
|
|
|
schema: IRSForm;
|
2024-05-27 20:42:34 +03:00
|
|
|
|
selected: ConstituentaID[];
|
|
|
|
|
onDelete: (items: ConstituentaID[]) => void;
|
2023-12-07 01:21:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-16 16:31:32 +03:00
|
|
|
|
function DlgDeleteCst() {
|
|
|
|
|
const { selected, schema, onDelete } = useDialogsStore(state => state.props as DlgDeleteCstProps);
|
|
|
|
|
const hideDialog = useDialogsStore(state => state.hideDialog);
|
2023-12-07 01:21:27 +03:00
|
|
|
|
const [expandOut, setExpandOut] = useState(false);
|
2024-12-13 21:31:09 +03:00
|
|
|
|
const expansion: ConstituentaID[] = schema.graph.expandAllOutputs(selected);
|
|
|
|
|
const hasInherited = selected.some(
|
|
|
|
|
id => schema.inheritance.find(item => item.parent === id),
|
2024-11-19 22:58:43 +03:00
|
|
|
|
[selected, schema.inheritance]
|
|
|
|
|
);
|
2023-12-07 01:21:27 +03:00
|
|
|
|
|
|
|
|
|
function handleSubmit() {
|
2025-01-16 16:31:32 +03:00
|
|
|
|
hideDialog();
|
2023-12-07 01:21:27 +03:00
|
|
|
|
if (expandOut) {
|
|
|
|
|
onDelete(selected.concat(expansion));
|
|
|
|
|
} else {
|
|
|
|
|
onDelete(selected);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2023-12-28 14:04:44 +03:00
|
|
|
|
<Modal
|
|
|
|
|
canSubmit
|
|
|
|
|
header='Удаление конституент'
|
|
|
|
|
submitText={expandOut ? 'Удалить с зависимыми' : 'Удалить'}
|
|
|
|
|
onSubmit={handleSubmit}
|
2024-03-19 19:19:08 +03:00
|
|
|
|
className={clsx('cc-column', 'max-w-[60vw] min-w-[30rem]', 'px-6')}
|
2023-12-28 14:04:44 +03:00
|
|
|
|
>
|
2024-06-26 19:47:31 +03:00
|
|
|
|
<ListConstituents title='Выбраны к удалению' list={selected} schema={schema} prefix={prefixes.cst_delete_list} />
|
|
|
|
|
<ListConstituents
|
2023-12-28 14:04:44 +03:00
|
|
|
|
title='Зависимые конституенты'
|
|
|
|
|
list={expansion}
|
2024-04-07 15:38:24 +03:00
|
|
|
|
schema={schema}
|
2023-12-28 14:04:44 +03:00
|
|
|
|
prefix={prefixes.cst_dependant_list}
|
|
|
|
|
/>
|
2024-06-18 15:07:41 +03:00
|
|
|
|
<Checkbox
|
|
|
|
|
label='Удалить зависимые конституенты'
|
2024-11-19 22:58:43 +03:00
|
|
|
|
className='mb-2'
|
2024-06-18 15:07:41 +03:00
|
|
|
|
value={expandOut}
|
2025-02-04 20:35:55 +03:00
|
|
|
|
onChange={value => setExpandOut(value)}
|
2024-06-18 15:07:41 +03:00
|
|
|
|
/>
|
2024-11-19 22:58:43 +03:00
|
|
|
|
{hasInherited ? (
|
|
|
|
|
<p className='text-sm clr-text-red'>Внимание! Выбранные конституенты имеют наследников в ОСС</p>
|
|
|
|
|
) : null}
|
2023-12-28 14:04:44 +03:00
|
|
|
|
</Modal>
|
|
|
|
|
);
|
2023-12-07 01:21:27 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
|
export default DlgDeleteCst;
|