AnthologyCreate.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { ProForm, ProFormText } from "@ant-design/pro-components";
  2. import { useIntl } from "react-intl";
  3. import { message } from "antd";
  4. import LangSelect from "../general/LangSelect";
  5. import { IAnthologyCreateRequest, IAnthologyResponse } from "../api/Article";
  6. import { post } from "../../request";
  7. interface IFormData {
  8. title: string;
  9. lang: string;
  10. studio: string;
  11. }
  12. type IWidgetAnthologyCreate = {
  13. studio?: string;
  14. };
  15. const Widget = (prop: IWidgetAnthologyCreate) => {
  16. const intl = useIntl();
  17. return (
  18. <ProForm<IFormData>
  19. onFinish={async (values: IFormData) => {
  20. // TODO
  21. values.studio = prop.studio ? prop.studio : "";
  22. console.log(values);
  23. const res = await post<IAnthologyCreateRequest, IAnthologyResponse>(
  24. `/v2/anthology`,
  25. values
  26. );
  27. console.log(res);
  28. if (res.ok) {
  29. message.success(intl.formatMessage({ id: "flashes.success" }));
  30. } else {
  31. message.error(res.message);
  32. }
  33. }}
  34. >
  35. <ProForm.Group>
  36. <ProFormText
  37. width="md"
  38. name="title"
  39. required
  40. label={intl.formatMessage({
  41. id: "forms.fields.title.label",
  42. })}
  43. rules={[
  44. {
  45. required: true,
  46. message: intl.formatMessage({
  47. id: "forms.message.title.required",
  48. }),
  49. max: 255,
  50. },
  51. ]}
  52. />
  53. </ProForm.Group>
  54. <ProForm.Group>
  55. <LangSelect />
  56. </ProForm.Group>
  57. </ProForm>
  58. );
  59. };
  60. export default Widget;