import { useIntl } from "react-intl"; import { ProForm, ProFormText, ProFormTextArea, } from "@ant-design/pro-components"; import { Alert, message } from "antd"; import type { IApiResponseChannel, IApiResponseChannelData, } from "../../api/Channel"; import { get, put } from "../../request"; import ChannelTypeSelect from "./ChannelTypeSelect"; import LangSelect from "../general/LangSelect"; import PublicitySelect from "../studio/PublicitySelect"; import { useState } from "react"; import { useAppSelector } from "../../hooks"; import { currentUser } from "../../reducers/current-user"; interface IFormData { name: string; type: string; lang: string; summary: string; status: number; studio: string; isSystem: boolean; } interface IWidget { studioName?: string; channelId?: string; onLoad?: Function; } const EditWidget = ({ studioName, channelId, onLoad }: IWidget) => { const intl = useIntl(); const [isSystem, setIsSystem] = useState(); const [data, setData] = useState(); const user = useAppSelector(currentUser); return ( <> {isSystem ? ( ) : ( <> )} submitter={{ resetButtonProps: { disabled: isSystem ? true : false }, submitButtonProps: { disabled: isSystem ? true : false }, }} onFinish={async (values: IFormData) => { console.log(values); const res = await put(`/v2/channel/${channelId}`, values); console.log(res); message.success(intl.formatMessage({ id: "flashes.success" })); }} formKey="channel_edit" request={async () => { const res = await get( `/v2/channel/${channelId}` ); if (res.ok === false) { return { name: "", type: "", lang: "", summary: "", status: 0, studio: "", isSystem: true, }; } setData(res.data); if (typeof onLoad !== "undefined") { onLoad(res.data); } setIsSystem(res.data.is_system); return { name: res.data.name, type: res.data.type, lang: res.data.lang, summary: res.data.summary, status: res.data.status, studio: studioName ? studioName : "", isSystem: res.data.is_system, }; }} > ); }; export default EditWidget;