import { useEffect, useState } from 'react'; import { useLocation } from 'react-router-dom'; import { toast } from 'react-toastify'; import BackendError from '../components/BackendError'; import Button from '../components/Common/Button'; import Checkbox from '../components/Common/Checkbox'; import FileInput from '../components/Common/FileInput'; import Form from '../components/Common/Form'; import SubmitButton from '../components/Common/SubmitButton'; import TextArea from '../components/Common/TextArea'; import TextInput from '../components/Common/TextInput'; import RequireAuth from '../components/RequireAuth'; import { useLibrary } from '../context/LibraryContext'; import { useConceptNavigation } from '../context/NagivationContext'; import { IRSFormCreateData, LibraryItemType } from '../utils/models'; function CreateRSFormPage() { const location = useLocation(); const { navigateTo, navigateHistory } = useConceptNavigation(); const { createSchema, error, setError, processing } = useLibrary(); const [title, setTitle] = useState(''); const [alias, setAlias] = useState(''); const [comment, setComment] = useState(''); const [common, setCommon] = useState(false); const [file, setFile] = useState() useEffect(() => { setError(undefined); }, [title, alias, setError]); function handleFile(event: React.ChangeEvent) { if (event.target.files && event.target.files.length > 0) { setFile(event.target.files[0]); } else { setFile(undefined); } } function handleCancel() { if (location.key !== 'default') { navigateHistory(-1); } else { navigateTo('/library'); } } function handleSubmit(event: React.FormEvent) { event.preventDefault(); if (processing) { return; } const data: IRSFormCreateData = { item_type: LibraryItemType.RSFORM, title: title, alias: alias, comment: comment, is_common: common, is_canonical: false, file: file, fileName: file?.name }; createSchema(data, (newSchema) => { toast.success('Схема успешно создана'); navigateTo(`/rsforms/${newSchema.id}`); }); } return (
setTitle(event.target.value)} /> setAlias(event.target.value)} />