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';
|
2024-03-01 18:19:33 +03:00
|
|
|
import Modal, { ModalProps } from '@/components/ui/Modal';
|
2024-10-29 12:06:43 +03:00
|
|
|
import { HelpTopic } from '@/models/miscellaneous';
|
2024-07-30 16:00:09 +03:00
|
|
|
import { ICstSubstitute, ICstSubstituteData } from '@/models/oss';
|
|
|
|
import { IRSForm } from '@/models/rsform';
|
2024-03-27 22:54:24 +03:00
|
|
|
import { prefixes } from '@/utils/constants';
|
2024-03-01 18:19:33 +03:00
|
|
|
|
|
|
|
interface DlgSubstituteCstProps extends Pick<ModalProps, 'hideWindow'> {
|
2024-07-30 16:00:09 +03:00
|
|
|
schema: IRSForm;
|
2024-03-01 18:19:33 +03:00
|
|
|
onSubstitute: (data: ICstSubstituteData) => void;
|
|
|
|
}
|
|
|
|
|
2024-07-30 16:00:09 +03:00
|
|
|
function DlgSubstituteCst({ hideWindow, onSubstitute, schema }: DlgSubstituteCstProps) {
|
|
|
|
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() {
|
|
|
|
const data: ICstSubstituteData = {
|
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
|
|
|
hideWindow={hideWindow}
|
|
|
|
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
|
|
|
|
substitutions={substitutions}
|
|
|
|
setSubstitutions={setSubstitutions}
|
2024-03-27 22:54:24 +03:00
|
|
|
rows={6}
|
|
|
|
prefixID={prefixes.dlg_cst_substitutes_list}
|
2024-07-30 16:00:09 +03:00
|
|
|
schemas={[schema]}
|
2024-03-01 18:19:33 +03:00
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DlgSubstituteCst;
|