Merge branch 'fe/fixQna' into 'frontend'

[Front-end] fix: 강사의 Qna 관리부분 수정

See merge request s11-webmobile1-sub2/S11P12A701!117
This commit is contained in:
정기영 2024-08-08 17:58:34 +09:00
commit 546a226df8
4 changed files with 37 additions and 26 deletions

View File

@ -55,7 +55,7 @@ export default function ArticleDetail({
</div>
</div>
<div className={styles.actionGroup}>
{(isMine || userType === 'teacher') && (
{(isMine || (userType === 'teacher' && !isQna)) && (
<>
<Link
className={styles.edit}
@ -84,12 +84,16 @@ export default function ArticleDetail({
answer={submittedAnswer}
onEditClick={handleEditClick}
onDeleteSubmit={handleDeleteSubmit}
isTeacher={userType === 'teacher'}
/>
) : (
<ArticleDetailAnswerInput
onSubmit={handleAnswerSubmit}
initialAnswer={submittedAnswer}
/>
userType === 'teacher' && (
<ArticleDetailAnswerInput
onSubmit={handleAnswerSubmit}
initialAnswer={submittedAnswer}
isEditing={isEditing}
/>
)
))}
</div>
);

View File

@ -3,7 +3,7 @@ import ReplyIcon from '/src/assets/icons/reply.svg?react';
import { useParams } from 'react-router-dom';
import { useAnswerDelete } from '../../../../hooks/api/useAnswerDelete';
export default function ArticleDetailAnswer({ answer, onEditClick, onDeleteSubmit }) {
export default function ArticleDetailAnswer({ answer, onEditClick, onDeleteSubmit, isTeacher }) {
const { questionId } = useParams();
const { answerDelete } = useAnswerDelete();
@ -20,22 +20,24 @@ export default function ArticleDetailAnswer({ answer, onEditClick, onDeleteSubmi
<div className={styles.author}>
<ReplyIcon /> <span>선생님의 답변</span>
</div>
<div className={styles.actionGroup}>
<button
type="button"
className={styles.edit}
onClick={onEditClick}
>
수정
</button>
<button
type="button"
className={styles.delete}
onClick={handleDeleteSubmit}
>
<div>삭제</div>
</button>
</div>
{isTeacher && (
<div className={styles.actionGroup}>
<button
type="button"
className={styles.edit}
onClick={onEditClick}
>
수정
</button>
<button
type="button"
className={styles.delete}
onClick={handleDeleteSubmit}
>
<div>삭제</div>
</button>
</div>
)}
</div>
<p className={styles.content}>{answer}</p>
</section>

View File

@ -1,18 +1,24 @@
import styles from './ArticleDetailAnswerInput.module.css';
import { useAnswerWrite } from '../../../../hooks/api/useAnswerWrite';
import { useAnswerEdit } from '../../../../hooks/api/useAnswerEdit';
import { useParams } from 'react-router-dom';
import { useState } from 'react';
export default function ArticleDetailAnswerInput({ onSubmit, initialAnswer, isEditing = false }) {
import SendIcon from '/src/assets/icons/send.svg?react';
export default function ArticleDetailAnswerInput({ onSubmit, initialAnswer }) {
const { answerWrite } = useAnswerWrite();
const { answerEdit } = useAnswerEdit();
const { questionId } = useParams();
const [newAnswer, setNewAnswer] = useState(initialAnswer);
const handleSubmit = async (e) => {
e.preventDefault();
await answerWrite(questionId, newAnswer);
console.log(isEditing);
if (isEditing) {
await answerEdit(questionId, newAnswer);
} else {
await answerWrite(questionId, newAnswer);
}
onSubmit(newAnswer);
};

View File

@ -9,7 +9,6 @@ export default function QuestionListPage() {
const { data } = useQnas(lectureId);
const questions = data?.data;
const userType = useBoundStore((state) => state.userType);
return (
<ArticleBoard
title="Q&A"