fix: question add reopen operation

This commit is contained in:
shuai 2022-12-02 17:19:31 +08:00
parent ca576d9b12
commit 57804fc4d9
4 changed files with 48 additions and 2 deletions

View File

@ -713,6 +713,10 @@ ui:
<p>Are you sure you want to add another answer?</p><p>You could use the <p>Are you sure you want to add another answer?</p><p>You could use the
edit link to refine and improve your existing answer, instead.</p> edit link to refine and improve your existing answer, instead.</p>
empty: Answer cannot be empty. empty: Answer cannot be empty.
reopen:
title: Reopen this post
content: Are you sure you want to reopen?
success: This post has been reopened
delete: delete:
title: Delete this post title: Delete this post
question: >- question: >-

View File

@ -6,7 +6,12 @@ import { useTranslation } from 'react-i18next';
import { Modal } from '@/components'; import { Modal } from '@/components';
import { useReportModal, useToast } from '@/hooks'; import { useReportModal, useToast } from '@/hooks';
import Share from '../Share'; import Share from '../Share';
import { deleteQuestion, deleteAnswer, editCheck } from '@/services'; import {
deleteQuestion,
deleteAnswer,
editCheck,
reopenQuestion,
} from '@/services';
import { tryNormalLogged } from '@/utils/guard'; import { tryNormalLogged } from '@/utils/guard';
interface IProps { interface IProps {
@ -32,7 +37,11 @@ const Index: FC<IProps> = ({
const { t } = useTranslation('translation', { keyPrefix: 'delete' }); const { t } = useTranslation('translation', { keyPrefix: 'delete' });
const toast = useToast(); const toast = useToast();
const reportModal = useReportModal(); const reportModal = useReportModal();
const closeModal = useReportModal();
const refershQuestion = () => {
callback?.('default');
};
const closeModal = useReportModal(refershQuestion);
const editUrl = const editUrl =
type === 'answer' ? `/posts/${qid}/${aid}/edit` : `/posts/${qid}/edit`; type === 'answer' ? `/posts/${qid}/${aid}/edit` : `/posts/${qid}/edit`;
@ -106,6 +115,25 @@ const Index: FC<IProps> = ({
}); });
}; };
const handleReopen = () => {
Modal.confirm({
title: t('title', { keyPrefix: 'question_detail.reopen' }),
content: t('content', { keyPrefix: 'question_detail.reopen' }),
cancelBtnVariant: 'link',
onConfirm: () => {
reopenQuestion({
question_id: qid,
}).then(() => {
toast.onShow({
msg: t('success', { keyPrefix: 'question_detail.reopen' }),
variant: 'success',
});
refershQuestion();
});
},
});
};
const handleAction = (action) => { const handleAction = (action) => {
if (!tryNormalLogged(true)) { if (!tryNormalLogged(true)) {
return; return;
@ -121,6 +149,10 @@ const Index: FC<IProps> = ({
if (action === 'close') { if (action === 'close') {
handleClose(); handleClose();
} }
if (action === 'reopen') {
handleReopen();
}
}; };
return ( return (

View File

@ -89,6 +89,12 @@ const Index = () => {
}, 1000); }, 1000);
return; return;
} }
if (type === 'default') {
window.scrollTo(0, 0);
getDetail();
return;
}
requestAnswers(); requestAnswers();
}; };

View File

@ -248,3 +248,7 @@ export const changeEmailVerify = (params: { code: string }) => {
export const getAppSettings = () => { export const getAppSettings = () => {
return request.get<Type.SiteSettings>('/answer/api/v1/siteinfo'); return request.get<Type.SiteSettings>('/answer/api/v1/siteinfo');
}; };
export const reopenQuestion = (params: { question_id: string }) => {
return request.put('/answer/api/v1/question/reopen', params);
};