ConceptPortal-public/rsconcept/frontend/src/dialogs/DlgDeleteCst/DlgDeleteCst.tsx
Ivan bb33c1f212
Some checks are pending
Frontend CI / build (22.x) (push) Waiting to run
R: Move dialogs to form basis
2025-02-06 14:10:18 +03:00

67 lines
2.1 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.

'use client';
import clsx from 'clsx';
import { useState } from 'react';
import Checkbox from '@/components/ui/Checkbox';
import Modal from '@/components/ui/Modal';
import { ConstituentaID, IRSForm } from '@/models/rsform';
import { useDialogsStore } from '@/stores/dialogs';
import { prefixes } from '@/utils/constants';
import ListConstituents from './ListConstituents';
export interface DlgDeleteCstProps {
schema: IRSForm;
selected: ConstituentaID[];
onDelete: (items: ConstituentaID[]) => void;
}
function DlgDeleteCst() {
const { selected, schema, onDelete } = useDialogsStore(state => state.props as DlgDeleteCstProps);
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]
);
function handleSubmit() {
if (expandOut) {
onDelete(selected.concat(expansion));
} else {
onDelete(selected);
}
return true;
}
return (
<Modal
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
title='Зависимые конституенты'
list={expansion}
schema={schema}
prefix={prefixes.cst_dependant_list}
/>
<Checkbox
label='Удалить зависимые конституенты'
className='mb-2'
value={expandOut}
onChange={value => setExpandOut(value)}
/>
{hasInherited ? (
<p className='text-sm clr-text-red'>Внимание! Выбранные конституенты имеют наследников в ОСС</p>
) : null}
</Modal>
);
}
export default DlgDeleteCst;