|
|
@@ -5,6 +5,7 @@ import {
|
|
|
Dropdown,
|
|
|
message,
|
|
|
Modal,
|
|
|
+ notification,
|
|
|
Space,
|
|
|
Tag,
|
|
|
Typography,
|
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
MessageOutlined,
|
|
|
ExclamationCircleOutlined,
|
|
|
CloseOutlined,
|
|
|
+ SyncOutlined,
|
|
|
} from "@ant-design/icons";
|
|
|
import type { MenuProps } from "antd";
|
|
|
|
|
|
@@ -30,24 +32,29 @@ import { fullUrl } from "../../utils";
|
|
|
import { ICommentRequest, ICommentResponse } from "../api/Comment";
|
|
|
import { useState } from "react";
|
|
|
import MdView from "../template/MdView";
|
|
|
+import { TDiscussionType } from "./Discussion";
|
|
|
|
|
|
const { Text } = Typography;
|
|
|
|
|
|
interface IWidget {
|
|
|
data: IComment;
|
|
|
+ hideTitle?: boolean;
|
|
|
onEdit?: Function;
|
|
|
onSelect?: Function;
|
|
|
onDelete?: Function;
|
|
|
onReply?: Function;
|
|
|
onClose?: Function;
|
|
|
+ onConvert?: Function;
|
|
|
}
|
|
|
const DiscussionShowWidget = ({
|
|
|
data,
|
|
|
+ hideTitle = false,
|
|
|
onEdit,
|
|
|
onSelect,
|
|
|
onDelete,
|
|
|
onReply,
|
|
|
onClose,
|
|
|
+ onConvert,
|
|
|
}: IWidget) => {
|
|
|
const intl = useIntl();
|
|
|
const [closed, setClosed] = useState(data.status);
|
|
|
@@ -104,6 +111,23 @@ const DiscussionShowWidget = ({
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const convert = (newType: TDiscussionType) => {
|
|
|
+ put<ICommentRequest, ICommentResponse>(`/v2/discussion/${data.id}`, {
|
|
|
+ title: data.title,
|
|
|
+ content: data.content,
|
|
|
+ status: data.status,
|
|
|
+ type: newType,
|
|
|
+ }).then((json) => {
|
|
|
+ console.log(json);
|
|
|
+ if (json.ok) {
|
|
|
+ notification.info({ message: "转换成功" });
|
|
|
+ if (typeof onConvert !== "undefined") {
|
|
|
+ onConvert(newType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
const onClick: MenuProps["onClick"] = (e) => {
|
|
|
console.log("click ", e);
|
|
|
switch (e.key) {
|
|
|
@@ -130,12 +154,18 @@ const DiscussionShowWidget = ({
|
|
|
break;
|
|
|
case "close":
|
|
|
close(true);
|
|
|
-
|
|
|
break;
|
|
|
-
|
|
|
case "reopen":
|
|
|
close(false);
|
|
|
-
|
|
|
+ break;
|
|
|
+ case "convert_qa":
|
|
|
+ convert("qa");
|
|
|
+ break;
|
|
|
+ case "convert_help":
|
|
|
+ convert("help");
|
|
|
+ break;
|
|
|
+ case "convert_discussion":
|
|
|
+ convert("discussion");
|
|
|
break;
|
|
|
case "delete":
|
|
|
if (data.id) {
|
|
|
@@ -181,6 +211,29 @@ const DiscussionShowWidget = ({
|
|
|
icon: <CheckOutlined />,
|
|
|
disabled: closed === "active",
|
|
|
},
|
|
|
+ {
|
|
|
+ type: "divider",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: "convert",
|
|
|
+ label: intl.formatMessage({
|
|
|
+ id: "buttons.convert",
|
|
|
+ }),
|
|
|
+ icon: <SyncOutlined />,
|
|
|
+ disabled: data.parent ? true : false,
|
|
|
+ children: [
|
|
|
+ { key: "convert_qa", label: "qa", disabled: data.type === "qa" },
|
|
|
+ { key: "convert_help", label: "help", disabled: data.type === "help" },
|
|
|
+ {
|
|
|
+ key: "convert_discussion",
|
|
|
+ label: "discussion",
|
|
|
+ disabled: data.type === "discussion",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: "divider",
|
|
|
+ },
|
|
|
{
|
|
|
key: "delete",
|
|
|
label: intl.formatMessage({
|
|
|
@@ -191,76 +244,97 @@ const DiscussionShowWidget = ({
|
|
|
disabled: data.childrenCount && data.childrenCount > 0 ? true : false,
|
|
|
},
|
|
|
];
|
|
|
- return (
|
|
|
- <Card
|
|
|
- size="small"
|
|
|
- title={
|
|
|
- <Space direction="vertical" size={"small"}>
|
|
|
- {data.title ? (
|
|
|
- <Text
|
|
|
- style={{ fontSize: 16 }}
|
|
|
- strong
|
|
|
- onClick={(e) => {
|
|
|
- if (typeof onSelect !== "undefined") {
|
|
|
- onSelect(e);
|
|
|
- }
|
|
|
- }}
|
|
|
- >
|
|
|
- {data.title}
|
|
|
- </Text>
|
|
|
- ) : undefined}
|
|
|
- <Text type="secondary" style={{ fontSize: "80%" }}>
|
|
|
- <Space>
|
|
|
- {closed === "close" ? (
|
|
|
- <Tag style={{ backgroundColor: "#8250df", color: "white" }}>
|
|
|
- {"closed"}
|
|
|
- </Tag>
|
|
|
- ) : undefined}
|
|
|
- {data.user.nickName}
|
|
|
- <TimeShow
|
|
|
- type="secondary"
|
|
|
- updatedAt={data.updatedAt}
|
|
|
- createdAt={data.createdAt}
|
|
|
- />
|
|
|
- </Space>
|
|
|
- </Text>
|
|
|
- </Space>
|
|
|
- }
|
|
|
- extra={
|
|
|
- <Space>
|
|
|
- <span
|
|
|
- style={{
|
|
|
- display: data.childrenCount === 0 ? "none" : "inline",
|
|
|
- cursor: "pointer",
|
|
|
- }}
|
|
|
+
|
|
|
+ const editInfo = () => {
|
|
|
+ return (
|
|
|
+ <Space direction="vertical" size={"small"}>
|
|
|
+ {data.title && !hideTitle ? (
|
|
|
+ <Text
|
|
|
+ style={{ fontSize: 16 }}
|
|
|
+ strong
|
|
|
onClick={(e) => {
|
|
|
if (typeof onSelect !== "undefined") {
|
|
|
- onSelect(e, data);
|
|
|
+ onSelect(e);
|
|
|
}
|
|
|
}}
|
|
|
>
|
|
|
- {data.childrenCount ? (
|
|
|
- <>
|
|
|
- <MessageOutlined /> {data.childrenCount}
|
|
|
- </>
|
|
|
+ {data.title}
|
|
|
+ </Text>
|
|
|
+ ) : undefined}
|
|
|
+ <Text type="secondary" style={{ fontSize: "80%" }}>
|
|
|
+ <Space>
|
|
|
+ {!data.parent && closed === "close" ? (
|
|
|
+ <Tag style={{ backgroundColor: "#8250df", color: "white" }}>
|
|
|
+ {"closed"}
|
|
|
+ </Tag>
|
|
|
) : undefined}
|
|
|
- </span>
|
|
|
- <Dropdown
|
|
|
- menu={{ items, onClick }}
|
|
|
- placement="bottomRight"
|
|
|
- trigger={["click"]}
|
|
|
- >
|
|
|
- <Button
|
|
|
- shape="circle"
|
|
|
- size="small"
|
|
|
- icon={<MoreOutlined />}
|
|
|
- ></Button>
|
|
|
- </Dropdown>
|
|
|
- </Space>
|
|
|
- }
|
|
|
+ {data.user.nickName}
|
|
|
+ <TimeShow
|
|
|
+ type="secondary"
|
|
|
+ updatedAt={data.updatedAt}
|
|
|
+ createdAt={data.createdAt}
|
|
|
+ />
|
|
|
+ </Space>
|
|
|
+ </Text>
|
|
|
+ </Space>
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
+ const editMenu = () => {
|
|
|
+ return (
|
|
|
+ <Space>
|
|
|
+ <span
|
|
|
+ style={{
|
|
|
+ display: data.childrenCount === 0 ? "none" : "inline",
|
|
|
+ cursor: "pointer",
|
|
|
+ }}
|
|
|
+ onClick={(e) => {
|
|
|
+ if (typeof onSelect !== "undefined") {
|
|
|
+ onSelect(e, data);
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {data.childrenCount ? (
|
|
|
+ <>
|
|
|
+ <MessageOutlined /> {data.childrenCount}
|
|
|
+ </>
|
|
|
+ ) : undefined}
|
|
|
+ </span>
|
|
|
+ <Dropdown
|
|
|
+ menu={{ items, onClick }}
|
|
|
+ placement="bottomRight"
|
|
|
+ trigger={["click"]}
|
|
|
+ >
|
|
|
+ <Button shape="circle" size="small" icon={<MoreOutlined />}></Button>
|
|
|
+ </Dropdown>
|
|
|
+ </Space>
|
|
|
+ );
|
|
|
+ };
|
|
|
+ return (
|
|
|
+ <Card
|
|
|
+ size="small"
|
|
|
+ title={data.type === "qa" && data.parent ? undefined : editInfo()}
|
|
|
+ extra={data.type === "qa" && data.parent ? undefined : editMenu()}
|
|
|
style={{ width: "100%" }}
|
|
|
>
|
|
|
- {data.html ? <MdView html={data.html} /> : <Marked text={data.content} />}
|
|
|
+ <div>
|
|
|
+ {data.html ? (
|
|
|
+ <MdView html={data.html} />
|
|
|
+ ) : (
|
|
|
+ <Marked text={data.content} />
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
+ {data.type === "qa" && data.parent ? (
|
|
|
+ <div style={{ display: "flex", justifyContent: "space-between" }}>
|
|
|
+ <div></div>
|
|
|
+ <div>
|
|
|
+ {editInfo()}
|
|
|
+ {editMenu()}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ) : (
|
|
|
+ <></>
|
|
|
+ )}
|
|
|
</Card>
|
|
|
);
|
|
|
};
|