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

View File

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

View File

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

View File

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