import { useIntl } from 'react-intl'; import Checkbox from '../../components/Common/Checkbox'; import SubmitButton from '../../components/Common/SubmitButton'; import TextArea from '../../components/Common/TextArea'; import TextInput from '../../components/Common/TextInput'; import { useRSForm } from '../../context/RSFormContext'; import { useCallback, useEffect, useState } from 'react'; import Button from '../../components/Common/Button'; import { CrownIcon, DownloadIcon, DumpBinIcon, SaveIcon, ShareIcon } from '../../components/Icons'; import { useUsers } from '../../context/UsersContext'; import { useNavigate } from 'react-router-dom'; import { toast } from 'react-toastify'; import fileDownload from 'js-file-download'; import { AxiosResponse } from 'axios'; import { useAuth } from '../../context/AuthContext'; import { claimOwnershipProc, deleteRSFormProc, downloadRSFormProc, shareCurrentURLProc } from '../../utils/procedures'; function RSFormCard() { const navigate = useNavigate(); const intl = useIntl(); const { getUserLabel } = useUsers(); const { schema, update, download, reload, isEditable, isOwned, isClaimable, processing, destroy, claim } = useRSForm(); const { user } = useAuth(); const [title, setTitle] = useState(''); const [alias, setAlias] = useState(''); const [comment, setComment] = useState(''); const [common, setCommon] = useState(false); useEffect(() => { setTitle(schema!.title) setAlias(schema!.alias) setComment(schema!.comment) setCommon(schema!.is_common) }, [schema]); const handleSubmit = (event: React.FormEvent) => { event.preventDefault(); const data = { 'title': title, 'alias': alias, 'comment': comment, 'is_common': common, }; update(data, () => { toast.success('Изменения сохранены'); reload(); }); }; const handleDelete = useCallback(() => deleteRSFormProc(destroy, navigate), [destroy, navigate]); const handleDownload = useCallback(() => { const fileName = (schema?.alias || 'Schema') + '.trs'; downloadRSFormProc(download, fileName); }, [download, schema?.alias]); return (
setTitle(event.target.value)} /> setAlias(event.target.value)} />