import { observer } from 'mobx-react-lite'; import React, { useEffect } from 'react'; import { useStore } from 'App/mstore'; import { CircularLoader, Loader } from 'UI'; import { Form, Input, Button, Select } from 'antd'; import { toast } from 'react-toastify'; import { useTranslation } from 'react-i18next'; interface Props { closeHandler: () => void; sessionId: string; errors: string[]; } const IssueForm: React.FC = observer( ({ closeHandler, sessionId, errors }) => { const { issueReportingStore: { createLoading: creating, projects, projectsLoading, users, instance, metaLoading, issueTypes, saveIssue, init, editInstance: edit, fetchMeta, fetchList, }, } = useStore(); const { t } = useTranslation(); useEffect(() => { init({ projectId: projects[0]?.id || '', issueType: issueTypes[0]?.id || '', }); }, []); useEffect(() => { if (instance?.projectId) { fetchMeta(instance.projectId).then(() => { edit({ issueType: '', assignee: '', projectId: instance.projectId }); }); } }, [instance?.projectId]); const onFinish = async () => { await saveIssue(sessionId, instance) .then(() => { closeHandler(); }) .catch(() => { toast(t('Failed to create issue'), { type: 'error' }); }); // if (!errors || errors.length === 0) { // init({ projectId: instance?.projectId }); // fetchList(sessionId); // closeHandler(); // } }; const handleChange = ( e: React.ChangeEvent, ) => { const { name, value } = e.target; edit({ [name]: value }); }; const handleSelect = (field: string) => (value: string) => { edit({ [field]: value }); }; const projectOptions = projects.map( ({ name, id }: { name: string; id: string }) => ({ label: name, value: id, }), ); const userOptions = users.map( ({ name, id }: { name: string; id: string }) => ({ label: name, value: id, }), ); const issueTypeOptions = issueTypes.map((opt: any) => ({ label: opt.name, value: opt.id, iconUrl: opt.iconUrl, })); return (
{t('Project')} } className="mb-15-imp" >
); }, ); export default IssueForm;