2024-03-01 18:19:33 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
2024-12-13 21:31:09 +03:00
|
|
|
import { useState } from 'react';
|
2024-03-01 18:19:33 +03:00
|
|
|
|
2024-07-30 16:00:09 +03:00
|
|
|
import PickSubstitutions from '@/components/select/PickSubstitutions';
|
2025-01-16 16:31:32 +03:00
|
|
|
import Modal from '@/components/ui/Modal';
|
2024-10-29 12:06:43 +03:00
|
|
|
import { HelpTopic } from '@/models/miscellaneous';
|
2025-01-27 15:03:48 +03:00
|
|
|
import { ICstSubstitute, ICstSubstitutions } from '@/models/oss';
|
2024-07-30 16:00:09 +03:00
|
|
|
import { IRSForm } from '@/models/rsform';
|
2025-01-16 16:31:32 +03:00
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
2024-03-01 18:19:33 +03:00
|
|
|
|
2025-01-16 16:31:32 +03:00
|
|
|
export interface DlgSubstituteCstProps {
|
2024-07-30 16:00:09 +03:00
|
|
|
schema: IRSForm;
|
2025-01-27 15:03:48 +03:00
|
|
|
onSubstitute: (data: ICstSubstitutions) => void;
|
2024-03-01 18:19:33 +03:00
|
|
|
}
|
|
|
|
|
2025-01-16 16:31:32 +03:00
|
|
|
function DlgSubstituteCst() {
|
|
|
|
const { onSubstitute, schema } = useDialogsStore(state => state.props as DlgSubstituteCstProps);
|
2024-07-30 16:00:09 +03:00
|
|
|
const [substitutions, setSubstitutions] = useState<ICstSubstitute[]>([]);
|
2024-12-13 21:31:09 +03:00
|
|
|
const canSubmit = substitutions.length > 0;
|
2024-03-01 18:19:33 +03:00
|
|
|
|
|
|
|
function handleSubmit() {
|
2025-01-27 15:03:48 +03:00
|
|
|
const data: ICstSubstitutions = {
|
2024-07-30 16:00:09 +03:00
|
|
|
substitutions: substitutions
|
2024-03-01 18:19:33 +03:00
|
|
|
};
|
|
|
|
onSubstitute(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
2024-03-27 22:54:24 +03:00
|
|
|
header='Отождествление'
|
2024-03-01 18:19:33 +03:00
|
|
|
submitText='Отождествить'
|
2024-08-23 22:53:53 +03:00
|
|
|
submitInvalidTooltip='Выберите две различные конституенты'
|
2024-03-01 18:19:33 +03:00
|
|
|
canSubmit={canSubmit}
|
|
|
|
onSubmit={handleSubmit}
|
2024-03-27 22:54:24 +03:00
|
|
|
className={clsx('w-[40rem]', 'px-6 pb-3')}
|
2024-10-29 12:06:43 +03:00
|
|
|
helpTopic={HelpTopic.UI_SUBSTITUTIONS}
|
2024-03-01 18:19:33 +03:00
|
|
|
>
|
2024-07-30 16:00:09 +03:00
|
|
|
<PickSubstitutions
|
|
|
|
allowSelfSubstitution
|
2025-02-04 20:35:55 +03:00
|
|
|
value={substitutions}
|
|
|
|
onChange={setSubstitutions}
|
2024-03-27 22:54:24 +03:00
|
|
|
rows={6}
|
2024-07-30 16:00:09 +03:00
|
|
|
schemas={[schema]}
|
2024-03-01 18:19:33 +03:00
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DlgSubstituteCst;
|