CommentEdit.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { useIntl } from "react-intl";
  2. import { Button, Card } from "antd";
  3. import { message } from "antd";
  4. import { ProForm, ProFormTextArea } from "@ant-design/pro-components";
  5. import { Col, Row, Space } from "antd";
  6. import { IComment } from "./CommentItem";
  7. import { put } from "../../request";
  8. import { ICommentRequest, ICommentResponse } from "../api/Comment";
  9. interface IWidget {
  10. data: IComment;
  11. onCreated?: Function;
  12. }
  13. const Widget = ({ data, onCreated }: IWidget) => {
  14. const intl = useIntl();
  15. const formItemLayout = {
  16. labelCol: { span: 4 },
  17. wrapperCol: { span: 20 },
  18. };
  19. return (
  20. <div>
  21. <Card
  22. title={<span>{data.user.nickName}</span>}
  23. extra={
  24. <Button shape="circle" size="small">
  25. xxx
  26. </Button>
  27. }
  28. style={{ width: "auto" }}
  29. >
  30. <ProForm<IComment>
  31. {...formItemLayout}
  32. layout="horizontal"
  33. submitter={{
  34. render: (props, doms) => {
  35. return (
  36. <Row>
  37. <Col span={14} offset={4}>
  38. <Space>{doms}</Space>
  39. </Col>
  40. </Row>
  41. );
  42. },
  43. }}
  44. onFinish={async (values) => {
  45. //新建
  46. put<ICommentRequest, ICommentResponse>(
  47. `/v2/discussion/${data.id}`,
  48. {
  49. title: values.title,
  50. content: values.content,
  51. }
  52. )
  53. .then((json) => {
  54. console.log(json);
  55. if (json.ok) {
  56. console.log(intl.formatMessage({ id: "flashes.success" }));
  57. if (typeof onCreated !== "undefined") {
  58. onCreated(json.data);
  59. }
  60. } else {
  61. message.error(json.message);
  62. }
  63. })
  64. .catch((e) => {
  65. message.error(e.message);
  66. });
  67. }}
  68. params={{}}
  69. request={async () => {
  70. return data;
  71. }}
  72. >
  73. <ProFormTextArea
  74. name="content"
  75. label={intl.formatMessage({ id: "forms.fields.content.label" })}
  76. placeholder={intl.formatMessage({
  77. id: "forms.fields.content.placeholder",
  78. })}
  79. />
  80. </ProForm>
  81. </Card>
  82. </div>
  83. );
  84. };
  85. export default Widget;