Ver código fonte

add onSelect

visuddhinanda 2 anos atrás
pai
commit
ac00f94e2a
1 arquivos alterados com 28 adições e 9 exclusões
  1. 28 9
      dashboard/src/components/channel/ChannelPicker.tsx

+ 28 - 9
dashboard/src/components/channel/ChannelPicker.tsx

@@ -1,4 +1,4 @@
-import { useState } from "react";
+import React, { useEffect, useState } from "react";
 import { Button, Modal } from "antd";
 import { Button, Modal } from "antd";
 
 
 import ChannelPickerTable from "./ChannelPickerTable";
 import ChannelPickerTable from "./ChannelPickerTable";
@@ -6,13 +6,28 @@ import { IChannel } from "./Channel";
 import { ArticleType } from "../article/Article";
 import { ArticleType } from "../article/Article";
 
 
 interface IWidget {
 interface IWidget {
+  trigger?: React.ReactNode;
   type?: ArticleType | "editable";
   type?: ArticleType | "editable";
   articleId?: string;
   articleId?: string;
   multiSelect?: boolean;
   multiSelect?: boolean;
+  open?: boolean;
+  onClose?: Function;
+  onSelect?: Function;
 }
 }
-const ChannelPickerWidget = ({ type, articleId, multiSelect }: IWidget) => {
-  const [isModalOpen, setIsModalOpen] = useState(false);
+const ChannelPickerWidget = ({
+  trigger,
+  type,
+  articleId,
+  multiSelect,
+  open = false,
+  onClose,
+  onSelect,
+}: IWidget) => {
+  const [isModalOpen, setIsModalOpen] = useState(open);
 
 
+  useEffect(() => {
+    setIsModalOpen(open);
+  }, [open]);
   const showModal = () => {
   const showModal = () => {
     setIsModalOpen(true);
     setIsModalOpen(true);
   };
   };
@@ -27,9 +42,7 @@ const ChannelPickerWidget = ({ type, articleId, multiSelect }: IWidget) => {
 
 
   return (
   return (
     <>
     <>
-      <Button type="primary" onClick={showModal}>
-        Select channel
-      </Button>
+      <span onClick={showModal}>{trigger}</span>
       <Modal
       <Modal
         width={"80%"}
         width={"80%"}
         title="选择版本风格"
         title="选择版本风格"
@@ -40,10 +53,16 @@ const ChannelPickerWidget = ({ type, articleId, multiSelect }: IWidget) => {
         <ChannelPickerTable
         <ChannelPickerTable
           type={type}
           type={type}
           articleId={articleId}
           articleId={articleId}
-          multiSelect={multiSelect}
-          onSelect={(e: IChannel) => {
-            console.log(e);
+          multiSelect={true}
+          onSelect={(channels: IChannel[]) => {
+            console.log(channels);
             handleCancel();
             handleCancel();
+            if (typeof onClose !== "undefined") {
+              onClose();
+            }
+            if (typeof onSelect !== "undefined") {
+              onSelect(channels);
+            }
           }}
           }}
         />
         />
       </Modal>
       </Modal>