Explorar el Código

添加成员后 隐藏添加窗口

visuddhinanda hace 3 años
padre
commit
af54132df9
Se han modificado 1 ficheros con 15 adiciones y 6 borrados
  1. 15 6
      dashboard/src/components/group/AddMember.tsx

+ 15 - 6
dashboard/src/components/group/AddMember.tsx

@@ -1,14 +1,11 @@
 import { useIntl } from "react-intl";
 import { useIntl } from "react-intl";
-import {
-  ProForm,
-  ProFormSelect,
-  ProFormText,
-} from "@ant-design/pro-components";
+import { ProForm, ProFormSelect } from "@ant-design/pro-components";
 import { Button, message, Popover } from "antd";
 import { Button, message, Popover } from "antd";
 import { UserAddOutlined } from "@ant-design/icons";
 import { UserAddOutlined } from "@ant-design/icons";
 import { get, post } from "../../request";
 import { get, post } from "../../request";
 import { IUserListResponse } from "../api/Auth";
 import { IUserListResponse } from "../api/Auth";
 import { IGroupMemberData, IGroupMemberResponse } from "../api/Group";
 import { IGroupMemberData, IGroupMemberResponse } from "../api/Group";
+import { useState } from "react";
 
 
 interface IFormData {
 interface IFormData {
   userId: string;
   userId: string;
@@ -16,9 +13,11 @@ interface IFormData {
 
 
 interface IWidget {
 interface IWidget {
   groupId?: string;
   groupId?: string;
+  onCreated?: Function;
 }
 }
-const Widget = ({ groupId }: IWidget) => {
+const Widget = ({ groupId, onCreated }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
+  const [open, setOpen] = useState(false);
 
 
   const form = (
   const form = (
     <ProForm<IFormData>
     <ProForm<IFormData>
@@ -30,8 +29,13 @@ const Widget = ({ groupId }: IWidget) => {
             user_id: values.userId,
             user_id: values.userId,
             group_id: groupId,
             group_id: groupId,
           }).then((json) => {
           }).then((json) => {
+            console.log("add member", json);
             if (json.ok) {
             if (json.ok) {
               message.success(intl.formatMessage({ id: "flashes.success" }));
               message.success(intl.formatMessage({ id: "flashes.success" }));
+              setOpen(false);
+              if (typeof onCreated !== "undefined") {
+                onCreated();
+              }
             }
             }
           });
           });
         }
         }
@@ -72,12 +76,17 @@ const Widget = ({ groupId }: IWidget) => {
       </ProForm.Group>
       </ProForm.Group>
     </ProForm>
     </ProForm>
   );
   );
+  const handleClickChange = (open: boolean) => {
+    setOpen(open);
+  };
   return (
   return (
     <Popover
     <Popover
       placement="bottom"
       placement="bottom"
       arrowPointAtCenter
       arrowPointAtCenter
       content={form}
       content={form}
       trigger="click"
       trigger="click"
+      open={open}
+      onOpenChange={handleClickChange}
     >
     >
       <Button icon={<UserAddOutlined />} key="add" type="primary">
       <Button icon={<UserAddOutlined />} key="add" type="primary">
         {intl.formatMessage({ id: "buttons.group.add.member" })}
         {intl.formatMessage({ id: "buttons.group.add.member" })}