Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat: edit content in review will show toast msg

shuai2841e3eef27f
diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml
index 2b2819dc..daa1e4cd 100644
--- a/i18n/en_US.yaml
+++ b/i18n/en_US.yaml
@@ -682,6 +682,7 @@ ui:
update: update success
update_password: Password changed successfully.
flag_success: Thanks for flagging.
+ review: Your revision will show after review.
related_question:
title: Related Questions
btn: Add question
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index bdbff1b2..474b015a 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -440,3 +440,9 @@ export interface ReviewResp {
count: number;
list: ReviewItem[];
}
+
+export interface MemberActionItem {
+ action: string;
+ name: string;
+ type: string;
+}
diff --git a/ui/src/pages/Questions/Ask/index.tsx b/ui/src/pages/Questions/Ask/index.tsx
index 6bd338e5..ed0b93a9 100644
--- a/ui/src/pages/Questions/Ask/index.tsx
+++ b/ui/src/pages/Questions/Ask/index.tsx
@@ -234,8 +234,10 @@ const Ask = () => {
id: qid,
edit_summary: formData.edit_summary.value,
})
- .then(() => {
- navigate(`/questions/${qid}`);
+ .then((res) => {
+ navigate(`/questions/${qid}`, {
+ state: { isReview: res?.wait_for_review },
+ });
})
.catch((err) => {
if (err.isError) {
diff --git a/ui/src/pages/Questions/Detail/index.tsx b/ui/src/pages/Questions/Detail/index.tsx
index 36546cb3..1a4f11b6 100644
--- a/ui/src/pages/Questions/Detail/index.tsx
+++ b/ui/src/pages/Questions/Detail/index.tsx
@@ -1,9 +1,15 @@
import { useEffect, useState } from 'react';
import { Container, Row, Col } from 'react-bootstrap';
-import { useParams, useSearchParams, useNavigate } from 'react-router-dom';
+import {
+ useParams,
+ useSearchParams,
+ useNavigate,
+ useLocation,
+} from 'react-router-dom';
+import { useTranslation } from 'react-i18next';
import { Pagination, PageTitle } from '@/components';
-import { loggedUserInfoStore } from '@/stores';
+import { loggedUserInfoStore, toastStore } from '@/stores';
import { scrollTop } from '@/utils';
import { usePageUsers } from '@/hooks';
import type {
@@ -26,6 +32,7 @@ import './index.scss';
const Index = () => {
const navigate = useNavigate();
+ const { t } = useTranslation('translation');
const { qid = '', aid = '' } = useParams();
const [urlSearch] = useSearchParams();
@@ -40,6 +47,17 @@ const Index = () => {
const userInfo = loggedUserInfoStore((state) => state.user);
const isAuthor = userInfo?.username === question?.user_info?.username;
const isLogged = Boolean(userInfo?.access_token);
+ const { state: locationState } = useLocation();
+
+ useEffect(() => {
+ if (locationState?.isReview) {
+ toastStore.getState().show({
+ msg: t('review', { keyPrefix: 'toast' }),
+ variant: 'warning',
+ });
+ }
+ }, [locationState]);
+
const requestAnswers = async () => {
const res = await getAnswers({
order: order === 'updated' ? order : 'default',
diff --git a/ui/src/pages/Questions/EditAnswer/index.tsx b/ui/src/pages/Questions/EditAnswer/index.tsx
index 7591c74d..f32234db 100644
--- a/ui/src/pages/Questions/EditAnswer/index.tsx
+++ b/ui/src/pages/Questions/EditAnswer/index.tsx
@@ -109,8 +109,10 @@ const Ask = () => {
id: aid,
edit_summary: formData.description.value,
};
- modifyAnswer(params).then(() => {
- navigate(`/questions/${qid}/${aid}`);
+ modifyAnswer(params).then((res) => {
+ navigate(`/questions/${qid}/${aid}`, {
+ state: { isReview: res?.wait_for_review },
+ });
});
};
diff --git a/ui/src/pages/Tags/Edit/index.tsx b/ui/src/pages/Tags/Edit/index.tsx
index 11d26e53..d7f508b3 100644
--- a/ui/src/pages/Tags/Edit/index.tsx
+++ b/ui/src/pages/Tags/Edit/index.tsx
@@ -104,8 +104,11 @@ const Ask = () => {
tag_id: data?.tag_id,
edit_summary: formData.editSummary.value,
};
- modifyTag(params).then(() => {
- navigate(-1);
+ modifyTag(params).then((res) => {
+ navigate(`/tags/${formData.slugName.value}/info`, {
+ replace: true,
+ state: { isReview: res.wait_for_review },
+ });
});
};
diff --git a/ui/src/pages/Tags/Info/index.tsx b/ui/src/pages/Tags/Info/index.tsx
index 8e4a765a..c44d2b35 100644
--- a/ui/src/pages/Tags/Info/index.tsx
+++ b/ui/src/pages/Tags/Info/index.tsx
@@ -1,6 +1,6 @@
-import { useState } from 'react';
+import { useState, useEffect } from 'react';
import { Container, Row, Col, Button, Card } from 'react-bootstrap';
-import { useParams, useNavigate, Link } from 'react-router-dom';
+import { useParams, useNavigate, Link, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import classNames from 'classnames';
@@ -14,17 +14,28 @@ import {
editCheck,
} from '@/services';
import { pathFactory } from '@/router/pathFactory';
-import { loggedUserInfoStore } from '@/stores';
+import { loggedUserInfoStore, toastStore } from '@/stores';
const TagIntroduction = () => {
const userInfo = loggedUserInfoStore((state) => state.user);
+ const { state: locationState } = useLocation();
const isLogged = Boolean(userInfo?.access_token);
const [isEdit, setEditState] = useState(false);
const { tagName } = useParams();
const { data: tagInfo } = useTagInfo({ name: tagName });
const { t } = useTranslation('translation', { keyPrefix: 'tag_info' });
const navigate = useNavigate();
- const { data: synonymsTags, mutate } = useQuerySynonymsTags(tagInfo?.tag_id);
+ const { data: synonymsData, mutate } = useQuerySynonymsTags(tagInfo?.tag_id);
+
+ useEffect(() => {
+ if (locationState?.isReview) {
+ toastStore.getState().show({
+ msg: t('review', { keyPrefix: 'toast' }),
+ variant: 'warning',
+ });
+ }
+ }, [locationState]);
+
if (!tagInfo) {
return null;
}
@@ -34,6 +45,7 @@ const TagIntroduction = () => {
});
return null;
}
+
const handleEdit = () => {
setEditState(true);
};
@@ -41,7 +53,7 @@ const TagIntroduction = () => {
const handleSave = () => {
saveSynonymsTags({
tag_id: tagInfo?.tag_id,
- synonym_tag_list: synonymsTags,
+ synonym_tag_list: synonymsData?.synonyms,
}).then(() => {
mutate();
setEditState(false);
@@ -49,9 +61,12 @@ const TagIntroduction = () => {
};
const handleTagsChange = (value) => {
- mutate([...value], {
- revalidate: false,
- });
+ mutate(
+ { ...synonymsData, synonyms: [...value] },
+ {
+ revalidate: false,
+ },
+ );
};
const handleEditTag = () => {
@@ -60,7 +75,7 @@ const TagIntroduction = () => {
});
};
const handleDeleteTag = () => {
- if (synonymsTags && synonymsTags.length > 0) {
+ if (synonymsData?.synonyms && synonymsData.synonyms.length > 0) {
Modal.confirm({
title: t('delete.title'),
content: t('delete.content2'),
@@ -157,14 +172,16 @@ const TagIntroduction = () => {
onClick={handleSave}>
{t('synonyms.btn_save')}
</Button>
- ) : (
+ ) : synonymsData?.member_actions?.find(
+ (v) => v.action === 'edit',
+ ) ? (
<Button
variant="link"
className="p-0 btn-no-border"
onClick={handleEdit}>
{t('synonyms.btn_edit')}
</Button>
- )}
+ ) : null}
</Card.Header>
<Card.Body>
{isEdit && (
@@ -183,15 +200,16 @@ const TagIntroduction = () => {
/>
</div>
<TagSelector
- value={synonymsTags}
+ value={synonymsData?.synonyms}
onChange={handleTagsChange}
hiddenDescription
/>
</>
)}
{!isEdit &&
- (synonymsTags && synonymsTags.length > 0 ? (
- synonymsTags.map((item) => {
+ (synonymsData?.synonyms &&
+ synonymsData.synonyms.length > 0 ? (
+ synonymsData.synonyms.map((item) => {
return (
<Tag
key={item.tag_id}
@@ -205,12 +223,16 @@ const TagIntroduction = () => {
<div className="text-muted mb-3">
{t('synonyms.empty')}
</div>
- <Button
- variant="outline-primary"
- size="sm"
- onClick={handleEdit}>
- {t('synonyms.btn_add')}
- </Button>
+ {synonymsData?.member_actions?.find(
+ (v) => v.action === 'edit',
+ ) && (
+ <Button
+ variant="outline-primary"
+ size="sm"
+ onClick={handleEdit}>
+ {t('synonyms.btn_add')}
+ </Button>
+ )}
</>
))}
</Card.Body>
diff --git a/ui/src/services/client/tag.ts b/ui/src/services/client/tag.ts
index 55c18b6e..b13b9b52 100644
--- a/ui/src/services/client/tag.ts
+++ b/ui/src/services/client/tag.ts
@@ -15,7 +15,10 @@ export const modifyTag = (params) => {
export const useQuerySynonymsTags = (tagId) => {
const apiUrl = tagId ? `/answer/api/v1/tag/synonyms?tag_id=${tagId}` : '';
- return useSWR<Type.SynonymsTag[]>(apiUrl, request.instance.get);
+ return useSWR<{
+ synonyms: Type.SynonymsTag[];
+ member_actions?: Type.MemberActionItem[];
+ }>(apiUrl, request.instance.get);
};
export const saveSynonymsTags = (params) => {