ConceptPortal-public/rsconcept/frontend/src/dialogs/DlgCreateCst/DlgCreateCst.tsx

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-04-01 15:11:17 +03:00
'use client';
2024-08-29 12:42:26 +03:00
import { useState } from 'react';
2024-04-01 15:11:17 +03:00
import Modal, { ModalProps } from '@/components/ui/Modal';
import usePartialUpdate from '@/hooks/usePartialUpdate';
import { CstType, ICstCreateData, IRSForm } from '@/models/rsform';
2024-08-29 12:42:26 +03:00
import { generateAlias } from '@/models/rsformAPI';
2024-04-01 15:11:17 +03:00
import FormCreateCst from './FormCreateCst';
interface DlgCreateCstProps extends Pick<ModalProps, 'hideWindow'> {
initial?: ICstCreateData;
schema: IRSForm;
onCreate: (data: ICstCreateData) => void;
}
function DlgCreateCst({ hideWindow, initial, schema, onCreate }: DlgCreateCstProps) {
const [validated, setValidated] = useState(false);
const [cstData, updateCstData] = usePartialUpdate(
initial || {
cst_type: CstType.BASE,
insert_after: null,
2024-08-29 12:42:26 +03:00
alias: generateAlias(CstType.BASE, schema),
2024-04-01 15:11:17 +03:00
convention: '',
definition_formal: '',
definition_raw: '',
term_raw: '',
term_forms: []
}
);
const handleSubmit = () => onCreate(cstData);
return (
<Modal
header='Создание конституенты'
hideWindow={hideWindow}
canSubmit={validated}
onSubmit={handleSubmit}
submitText='Создать'
className='cc-column w-[35rem] h-[30rem] py-2 px-6'
>
<FormCreateCst schema={schema} state={cstData} partialUpdate={updateCstData} setValidated={setValidated} />
</Modal>
);
}
export default DlgCreateCst;