fix: conflict

This commit is contained in:
shuai 2022-12-01 19:01:33 +08:00
commit 0fd2a807b0
8 changed files with 85 additions and 29 deletions

View File

@ -702,6 +702,7 @@ ui:
update_password: Password changed successfully.
flag_success: Thanks for flagging.
fobidden_operate_self: Forbidden to operate on yourself
review: Your revision will show after review.
related_question:
title: Related Questions
btn: Add question

View File

@ -451,3 +451,8 @@ export interface UserRoleItem {
name: string;
description: string;
}
export interface MemberActionItem {
action: string;
name: string;
type: string;
}

View File

@ -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) {

View File

@ -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',

View File

@ -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 },
});
});
};

View File

@ -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 },
});
});
};

View File

@ -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>

View File

@ -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) => {