| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- import { useEffect, useState } from "react";
- import { Tabs } from "antd";
- import type { TResType } from "./DiscussionListCard"
- import Discussion from "./Discussion";
- import { get } from "../../request";
- import QaBox from "./QaBox";
- interface IInteractive {
- ok: boolean;
- data: ITypeData;
- message: string;
- }
- interface ITypeData {
- qa: IPower;
- help: IPower;
- discussion: IPower;
- }
- interface IPower {
- can_create: boolean;
- can_reply: boolean;
- count: number;
- }
- interface IWidget {
- resId?: string;
- resType?: TResType;
- }
- const InteractiveAreaWidget = ({ resId, resType }: IWidget) => {
- const [showQa, setShowQa] = useState(false);
- const [_qaCanEdit, setQaCanEdit] = useState(false);
- const [showHelp, setShowHelp] = useState(false);
- const [showDiscussion, setShowDiscussion] = useState(false);
- useEffect(() => {
- get<IInteractive>(`/v2/interactive/${resId}?res_type=${resType}`).then(
- (json) => {
- if (json.ok) {
- console.debug("interactive", json);
- if (json.data.qa.can_create || json.data.qa.can_reply) {
- setShowQa(true);
- setQaCanEdit(true);
- } else if (json.data.qa.count > 0) {
- setShowQa(true);
- } else {
- setShowQa(false);
- }
- if (json.data.help.can_create) {
- setShowHelp(true);
- } else if (json.data.help.can_reply) {
- if (json.data.help.count > 0) {
- setShowHelp(true);
- }
- } else {
- setShowHelp(false);
- }
- if (
- json.data.discussion.can_create ||
- json.data.discussion.can_reply ||
- json.data.discussion.count > 0
- ) {
- setShowDiscussion(true);
- } else {
- setShowDiscussion(false);
- }
- }
- }
- );
- }, [resId, resType]);
- return showQa || showHelp || showDiscussion ? (
- <Tabs
- size="small"
- items={[
- {
- label: `问答`,
- key: "qa",
- children: <QaBox resId={resId} resType={resType} />,
- },
- {
- label: `求助`,
- key: "help",
- children: <Discussion resId={resId} resType={resType} type="help" />,
- },
- {
- label: `讨论`,
- key: "discussion",
- children: (
- <Discussion resId={resId} resType={resType} type="discussion" />
- ),
- },
- ].filter((value) => {
- if (value.key === "qa") {
- return showQa;
- } else if (value.key === "help") {
- return showHelp;
- } else if (value.key === "discussion") {
- return showDiscussion;
- } else {
- return false;
- }
- })}
- />
- ) : (
- <></>
- );
- };
- export default InteractiveAreaWidget;
|