visuddhinanda 1 год назад
Родитель
Сommit
4573d6cda3
1 измененных файлов с 24 добавлено и 55 удалено
  1. 24 55
      dashboard/src/components/tag/TagSelectButton.tsx

+ 24 - 55
dashboard/src/components/tag/TagSelectButton.tsx

@@ -1,18 +1,16 @@
-import { Button, message } from "antd";
+import { Button } from "antd";
 import { TagOutlined } from "@ant-design/icons";
 import { TagOutlined } from "@ant-design/icons";
 
 
-import TagSelect from "./TagSelect";
-import { ITagData, ITagMapRequest, ITagMapResponseList } from "../api/Tag";
 import { useAppSelector } from "../../hooks";
 import { useAppSelector } from "../../hooks";
 import { courseInfo } from "../../reducers/current-course";
 import { courseInfo } from "../../reducers/current-course";
 import { currentUser } from "../../reducers/current-user";
 import { currentUser } from "../../reducers/current-user";
-import { post } from "../../request";
-import { useIntl } from "react-intl";
+import TagsManager from "./TagsManager";
 
 
 interface IWidget {
 interface IWidget {
   resId?: string;
   resId?: string;
   resType?: string;
   resType?: string;
   disabled?: boolean;
   disabled?: boolean;
+  trigger?: React.ReactNode;
   onSelect?: Function;
   onSelect?: Function;
   onCreate?: Function;
   onCreate?: Function;
   onOpen?: Function;
   onOpen?: Function;
@@ -22,70 +20,41 @@ const TagSelectButtonWidget = ({
   resId,
   resId,
   resType,
   resType,
   disabled = false,
   disabled = false,
+  trigger,
   onSelect,
   onSelect,
   onCreate,
   onCreate,
   onOpen,
   onOpen,
 }: IWidget) => {
 }: IWidget) => {
-  const intl = useIntl();
   const course = useAppSelector(courseInfo);
   const course = useAppSelector(courseInfo);
   const user = useAppSelector(currentUser);
   const user = useAppSelector(currentUser);
 
 
   const studioName =
   const studioName =
     course?.course?.studio?.realName ?? user?.nickName ?? undefined;
     course?.course?.studio?.realName ?? user?.nickName ?? undefined;
 
 
+  console.debug("TagSelectButton studioName", studioName);
+
   return (
   return (
-    <TagSelect
+    <TagsManager
       studioName={studioName}
       studioName={studioName}
+      resId={resId}
+      resType={resType}
       trigger={
       trigger={
-        <Button
-          disabled={disabled}
-          type="text"
-          icon={
-            <TagOutlined
-              onClick={() => {
-                if (typeof onOpen !== "undefined") {
-                  onOpen();
-                }
-              }}
-            />
-          }
-        />
-      }
-      onSelect={(tag: ITagData) => {
-        if (typeof onSelect !== "undefined") {
-          onSelect(tag);
-        } else {
-          if (studioName || course) {
-            const data: ITagMapRequest = {
-              table_name: resType,
-              anchor_id: resId,
-              tag_id: tag.id,
-              course: course ? course.courseId : undefined,
-              studio: studioName,
-            };
-
-            const url = `/v2/tag-map`;
-            console.info("tag-map  api request", url, data);
-            post<ITagMapRequest, ITagMapResponseList>(url, data)
-              .then((json) => {
-                console.info("tag-map api response", json);
-                if (json.ok) {
-                  message.success(
-                    intl.formatMessage({ id: "flashes.success" })
-                  );
-                  if (typeof onCreate !== "undefined") {
-                    onCreate(json.data.rows);
+        trigger ?? (
+          <Button
+            disabled={disabled}
+            type="text"
+            icon={
+              <TagOutlined
+                onClick={() => {
+                  if (typeof onOpen !== "undefined") {
+                    onOpen();
                   }
                   }
-                } else {
-                  message.error(json.message);
-                }
-              })
-              .catch((e) => console.error(e));
-          } else {
-            console.error("no studio");
-          }
-        }
-      }}
+                }}
+              />
+            }
+          />
+        )
+      }
     />
     />
   );
   );
 };
 };