2024-06-07 20:17:03 +03:00
|
|
|
'use client';
|
|
|
|
|
2024-08-29 12:41:59 +03:00
|
|
|
import { useState } from 'react';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-01-23 19:41:31 +03:00
|
|
|
import { ICstCreateDTO } from '@/backend/rsform/api';
|
2025-01-16 16:31:03 +03:00
|
|
|
import Modal from '@/components/ui/Modal';
|
2024-06-07 20:17:03 +03:00
|
|
|
import usePartialUpdate from '@/hooks/usePartialUpdate';
|
2025-01-23 19:41:31 +03:00
|
|
|
import { CstType, IRSForm } from '@/models/rsform';
|
2024-08-29 12:41:59 +03:00
|
|
|
import { generateAlias } from '@/models/rsformAPI';
|
2025-01-16 16:31:03 +03:00
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
import FormCreateCst from './FormCreateCst';
|
|
|
|
|
2025-01-16 16:31:03 +03:00
|
|
|
export interface DlgCreateCstProps {
|
2025-01-23 19:41:31 +03:00
|
|
|
initial?: ICstCreateDTO;
|
2024-06-07 20:17:03 +03:00
|
|
|
schema: IRSForm;
|
2025-01-23 19:41:31 +03:00
|
|
|
onCreate: (data: ICstCreateDTO) => void;
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
|
|
|
|
2025-01-16 16:31:03 +03:00
|
|
|
function DlgCreateCst() {
|
|
|
|
const { initial, schema, onCreate } = useDialogsStore(state => state.props as DlgCreateCstProps);
|
2025-02-06 14:09:20 +03:00
|
|
|
|
2024-06-07 20:17:03 +03:00
|
|
|
const [validated, setValidated] = useState(false);
|
|
|
|
const [cstData, updateCstData] = usePartialUpdate(
|
|
|
|
initial || {
|
|
|
|
cst_type: CstType.BASE,
|
|
|
|
insert_after: null,
|
2024-08-29 12:41:59 +03:00
|
|
|
alias: generateAlias(CstType.BASE, schema),
|
2024-06-07 20:17:03 +03:00
|
|
|
convention: '',
|
|
|
|
definition_formal: '',
|
|
|
|
definition_raw: '',
|
|
|
|
term_raw: '',
|
|
|
|
term_forms: []
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2025-02-06 14:09:20 +03:00
|
|
|
const handleSubmit = () => {
|
|
|
|
onCreate(cstData);
|
|
|
|
return true;
|
|
|
|
};
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
header='Создание конституенты'
|
|
|
|
canSubmit={validated}
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
submitText='Создать'
|
2024-09-16 14:02:27 +03:00
|
|
|
className='cc-column w-[35rem] max-h-[30rem] py-2 px-6'
|
2024-06-07 20:17:03 +03:00
|
|
|
>
|
|
|
|
<FormCreateCst schema={schema} state={cstData} partialUpdate={updateCstData} setValidated={setValidated} />
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DlgCreateCst;
|