AiModelCreate.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { useIntl } from "react-intl";
  2. import {
  3. ProForm,
  4. type ProFormInstance,
  5. ProFormText,
  6. } from "@ant-design/pro-components";
  7. import { message } from "antd";
  8. import { post } from "../../request";
  9. import { useRef } from "react";
  10. import type { IAiModelRequest, IAiModelResponse } from "../../api/ai";
  11. interface IWidget {
  12. studioName?: string;
  13. onCreate?: Function;
  14. }
  15. const AiModelCreate = ({ studioName, onCreate }: IWidget) => {
  16. const intl = useIntl();
  17. const formRef = useRef<ProFormInstance | undefined>(undefined);
  18. return (
  19. <ProForm<IAiModelRequest>
  20. formRef={formRef}
  21. onFinish={async (values: IAiModelRequest) => {
  22. if (typeof studioName === "undefined") {
  23. return;
  24. }
  25. const url = `/v2/ai-model`;
  26. console.info("api request", url, values);
  27. const res = await post<IAiModelRequest, IAiModelResponse>(url, values);
  28. console.info("api response", res);
  29. if (res.ok) {
  30. message.success(intl.formatMessage({ id: "flashes.success" }));
  31. if (typeof onCreate !== "undefined") {
  32. onCreate();
  33. formRef.current?.resetFields();
  34. }
  35. } else {
  36. message.error(res.message);
  37. }
  38. }}
  39. >
  40. <ProForm.Group>
  41. <ProFormText
  42. width="md"
  43. name="name"
  44. required
  45. label={intl.formatMessage({ id: "channel.name" })}
  46. rules={[
  47. {
  48. required: true,
  49. message: intl.formatMessage({
  50. id: "channel.create.message.noname",
  51. }),
  52. },
  53. ]}
  54. />
  55. <ProFormText
  56. width="md"
  57. name="studio_name"
  58. initialValue={studioName}
  59. hidden
  60. required
  61. />
  62. </ProForm.Group>
  63. </ProForm>
  64. );
  65. };
  66. export default AiModelCreate;