fix: 강사의 Qna 관리부분 수정

This commit is contained in:
minwucho 2024-08-08 17:51:22 +09:00
parent d3d6245c6b
commit 210f4b06c7
4 changed files with 37 additions and 25 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}
@ -85,12 +85,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,16 +1,23 @@
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 }) {
export default function ArticleDetailAnswerInput({ onSubmit, initialAnswer, isEditing = false }) {
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"