import { ProForm, type ProFormInstance, ProFormSelect, ProFormText, } from "@ant-design/pro-components"; import { message, Space, Typography } from "antd"; import { useRef, useState } from "react"; import { useIntl } from "react-intl"; import { Link } from "react-router"; import { get, post, put } from "../../request"; import type { IWebhookRequest, IWebhookResponse } from "../../api/webhook"; import type { TResType } from "../discussion/DiscussionListCard"; import WebhookTpl, { type IWebhookEvent } from "./WebhookTpl"; const { Title } = Typography; interface IWidget { studioName?: string; channelId?: string; id?: string; res_type?: TResType; res_id?: string; onSuccess?: Function; } const WebhookEditWidget = ({ studioName, channelId, id, res_type = "channel", res_id = "", onSuccess, }: IWidget) => { const formRef = useRef(undefined); const [event, setEvent] = useState([]); const intl = useIntl(); return ( <Link to={`/studio/${studioName}/channel/${channelId}/setting/webhooks`} > List </Link>{" "} / {id ? "Manage webhook" : "New"} formRef={formRef} autoFocusFirstInput onFinish={async (values) => { console.log("submit", values); const data: IWebhookRequest = values; data.res_id = res_id; data.res_type = res_type; data.event2 = event; let res: IWebhookResponse; if (typeof id === "undefined") { res = await post( `/v2/webhook`, data ); } else { res = await put( `/v2/webhook/${id}`, data ); } console.log(res); if (res.ok) { message.success("提交成功"); if (typeof onSuccess !== "undefined") { onSuccess(); } } else { message.error(res.message); } return true; }} request={ id ? async () => { const url = `/v2/webhook/${id}`; const res: IWebhookResponse = await get(url); console.log("get", res); if (res.ok) { return res.data; } else { return { res_type: res_type, res_id: res_id, url: "", receiver: "wechat", event: [], status: "normal", }; } } : undefined } > { return { value: item, label: item, }; })} fieldProps={{ mode: "tags", }} width="md" name="event" allowClear={false} label={intl.formatMessage({ id: "forms.fields.event.label" })} /> { return { value: item, label: item, }; })} width="md" name="status" allowClear={false} label={intl.formatMessage({ id: "forms.fields.status.label" })} /> setEvent(value)} /> ); }; export default WebhookEditWidget;