import { useIntl } from "react-intl"; import { ProForm, ProFormInstance, ProFormText, } from "@ant-design/pro-components"; import { message } from "antd"; import { post } from "../../request"; import { IArticleCreateRequest, IArticleResponse } from "../api/Article"; import LangSelect from "../general/LangSelect"; import { useRef } from "react"; interface IFormData { title: string; lang: string; studio: string; anthologyId?: string; } interface IWidget { studio?: string; anthologyId?: string; onSuccess?: Function; } const ArticleCreateWidget = ({ studio, anthologyId, onSuccess }: IWidget) => { const intl = useIntl(); const formRef = useRef(); return ( formRef={formRef} onFinish={async (values: IFormData) => { console.log(values); if (typeof studio === "undefined") { return; } values.studio = studio; values.anthologyId = anthologyId; const res = await post( `/v2/article`, values ); console.log(res); if (res.ok) { message.success(intl.formatMessage({ id: "flashes.success" })); if (typeof onSuccess !== "undefined") { onSuccess(); formRef.current?.resetFields(["title"]); } } else { message.error(res.message); } }} > ); }; export default ArticleCreateWidget;