2
0

ProjectCreate.tsx 1.9 KB

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