Portal/rsconcept/frontend/src/dialogs/DlgDeleteCst/DlgDeleteCst.tsx

67 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
'use client';
import clsx from 'clsx';
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';
import { useDialogsStore } from '@/stores/dialogs';
2024-06-07 20:17:03 +03:00
import { prefixes } from '@/utils/constants';
import ListConstituents from './ListConstituents';
2024-06-07 20:17:03 +03:00
export interface DlgDeleteCstProps {
schema: IRSForm;
2024-06-07 20:17:03 +03:00
selected: ConstituentaID[];
onDelete: (items: ConstituentaID[]) => void;
}
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);
const expansion: ConstituentaID[] = schema.graph.expandAllOutputs(selected);
const hasInherited = selected.some(
id => schema.inheritance.find(item => item.parent === id),
[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')}
>
<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='Удалить зависимые конституенты'
className='mb-2'
2024-06-18 15:06:52 +03:00
value={expandOut}
onChange={value => setExpandOut(value)}
2024-06-18 15:06:52 +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;