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