From 4814e09bd09b1a6c47c5b4279178a522c7f9a1c5 Mon Sep 17 00:00:00 2001 From: JUHA KIM <88622675+hayamaster@users.noreply.github.com> Date: Mon, 4 Dec 2023 16:24:57 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=88=98=EC=8B=A0=EC=9E=90=20=ED=81=B4?= =?UTF-8?q?=EB=A6=AD=EC=8B=9C=201=EB=B2=88=20=EC=A7=88=EB=AC=B8=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99=20(#114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReplyCategory/ReplyRating/index.tsx | 25 +++++++------------ .../ReviewReplyEdit/ReviewReply.tsx | 5 ++++ .../components/ReviewReplyEnd/ReviewReply.tsx | 5 ++++ .../ReviewReplyStart/ReviewReply.tsx | 5 ++++ 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/pages/ReviewReplyPage/components/ReplyCategory/ReplyRating/index.tsx b/src/pages/ReviewReplyPage/components/ReplyCategory/ReplyRating/index.tsx index e7eb8a69..c37f137b 100644 --- a/src/pages/ReviewReplyPage/components/ReplyCategory/ReplyRating/index.tsx +++ b/src/pages/ReviewReplyPage/components/ReplyCategory/ReplyRating/index.tsx @@ -34,7 +34,6 @@ const ReplyRating = ({ [registerPath, getValues], ) - const [score, setScore] = useState(prevScore || 0) const [zero, setZero] = useState(false) useEffect(() => { @@ -43,16 +42,13 @@ const ReplyRating = ({ ? Array.from({ length: 5 }, (_, index) => index < prevScore) : Array(5).fill(false), ) - setScore(prevScore || 0) - }, [prevScore, receiverIndex, setRates, questionIndex]) + }, [prevScore, setRates, receiverIndex, questionIndex]) - useEffect(() => { - setValue(`${registerPath}.answerRating`, score) - }, [score, registerPath, setValue]) - - useEffect(() => { - handleCheckReply({ value: score }) - }, [score, handleCheckReply]) + const clickStar = (index: number) => { + setValue(`${registerPath}.answerRating`, index) + handleCheckReply({ value: index }) + changeStar(index - 1) + } const handleClickStar = (index: number) => { if (state.status === 'END' || state.status === 'DEADLINE') { @@ -61,20 +57,17 @@ const ReplyRating = ({ if (index !== 0) { setZero(false) - setScore(index + 1) - changeStar(index) + clickStar(index + 1) return } if (zero) { setZero(false) - setScore(index) - changeStar(index - 1) + clickStar(index) } else { setZero(true) - setScore(index + 1) - changeStar(index) + clickStar(index + 1) } } diff --git a/src/pages/ReviewReplyPage/components/ReviewReplyEdit/ReviewReply.tsx b/src/pages/ReviewReplyPage/components/ReviewReplyEdit/ReviewReply.tsx index 1c218b08..200876e6 100644 --- a/src/pages/ReviewReplyPage/components/ReviewReplyEdit/ReviewReply.tsx +++ b/src/pages/ReviewReplyPage/components/ReviewReplyEdit/ReviewReply.tsx @@ -1,3 +1,4 @@ +import { useEffect } from 'react' import { useFormContext } from 'react-hook-form' import { Modal } from '@/components' import { ReviewDetailedData } from '@/types' @@ -48,6 +49,10 @@ const ReviewReply = ({ reviewData, handleSubmit }: ReviewReplyProps) => { const { individualReplyCompletes, allReplyComplete, checkReplyComplete } = useReplyComplete({ receivers, selectedReceiverIndex, editPage: true }) + useEffect(() => { + setSelectedQuestionIndex(0) + }, [selectedReceiver, setSelectedQuestionIndex]) + const questionArray = questions.map((question, index) => ( { setSelectedReceiverIndex, }) + useEffect(() => { + setSelectedQuestionIndex(0) + }, [selectedReceiver, setSelectedQuestionIndex]) + const questionArray = questions.map((question, index) => ( { const { individualReplyCompletes, allReplyComplete, checkReplyComplete } = useReplyComplete({ receivers, selectedReceiverIndex }) + useEffect(() => { + setSelectedQuestionIndex(0) + }, [selectedReceiver, setSelectedQuestionIndex]) + const questionArray = questions.map((question, index) => (