|
@@ -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");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }}
|
|
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ }
|
|
|
|
|
+ />
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|