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.
fix: admin user or moderator or author can accepted answer
shuaib0e4b3afe92f
diff --git a/ui/src/pages/Questions/Detail/components/Answer/index.tsx b/ui/src/pages/Questions/Detail/components/Answer/index.tsxindex ebb7d8a6..dfbefa3d 100644--- a/ui/src/pages/Questions/Detail/components/Answer/index.tsx+++ b/ui/src/pages/Questions/Detail/components/Answer/index.tsx@@ -1,5 +1,5 @@import { memo, FC, useEffect, useRef } from 'react';-import { Button, Alert } from 'react-bootstrap';+import { Button, Alert, Badge } from 'react-bootstrap';import { useTranslation } from 'react-i18next';import { Link, useSearchParams } from 'react-router-dom';@@ -20,8 +20,7 @@ interface Props {data: AnswerItem;/** router answer id */aid?: string;- /** is author */- isAuthor: boolean;+ canAccept: boolean;questionTitle: string;slugTitle: string;isLogged: boolean;@@ -30,11 +29,11 @@ interface Props {const Index: FC<Props> = ({aid,data,- isAuthor,isLogged,questionTitle = '',slugTitle,callback,+ canAccept = false,}) => {const { t } = useTranslation('translation', {keyPrefix: 'question_detail',@@ -77,6 +76,14 @@ const Index: FC<Props> = ({{t('post_deleted', { keyPrefix: 'messages' })}</Alert>)}+ {data?.accepted === 2 && (+ <div style={{ lineHeight: '20px' }} className="mb-3">+ <Badge bg="success" pill>+ <Icon name="check-circle-fill me-1" />+ Best answer+ </Badge>+ </div>+ )}<articledangerouslySetInnerHTML={{ __html: data?.html }}className="fmt text-break text-wrap"@@ -96,24 +103,17 @@ const Index: FC<Props> = ({}}/>- {data?.accepted === 2 && (- <Button- disabled={!isAuthor}- variant="outline-success"- className="ms-3 active opacity-100 bg-success text-white"- onClick={acceptAnswer}>- <Icon name="check-circle-fill" className="me-2" />- <span>{t('answers.btn_accepted')}</span>- </Button>- )}-- {isAuthor && data.accepted === 1 && (+ {canAccept && (<Button- variant="outline-success"+ variant={data.accepted === 2 ? 'success' : 'outline-success'}className="ms-3"onClick={acceptAnswer}><Icon name="check-circle-fill" className="me-2" />- <span>{t('answers.btn_accept')}</span>+ <span>+ {data.accepted === 2+ ? t('answers.btn_accepted')+ : t('answers.btn_accept')}+ </span></Button>)}</div>diff --git a/ui/src/pages/Questions/Detail/index.tsx b/ui/src/pages/Questions/Detail/index.tsxindex 479fa5b7..7397c527 100644--- a/ui/src/pages/Questions/Detail/index.tsx+++ b/ui/src/pages/Questions/Detail/index.tsx@@ -56,6 +56,7 @@ const Index = () => {const userInfo = loggedUserInfoStore((state) => state.user);const isAuthor = userInfo?.username === question?.user_info?.username;const isAdmin = userInfo?.role_id === 2;+ const isModerator = userInfo?.role_id === 3;const isLogged = Boolean(userInfo?.access_token);const loggedUserRank = userInfo?.rank;const { state: locationState } = useLocation();@@ -222,7 +223,7 @@ const Index = () => {data={item}questionTitle={question?.title || ''}slugTitle={question?.url_title}- isAuthor={isAuthor}+ canAccept={isAuthor || isAdmin || isModerator}callback={initPage}isLogged={isLogged}/>