Skip to content

Commit

Permalink
feat: 수신자 클릭시 1번 질문으로 이동 (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
hayamaster authored Dec 4, 2023
1 parent fb1863d commit 4814e09
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const ReplyRating = ({
[registerPath, getValues],
)

const [score, setScore] = useState(prevScore || 0)
const [zero, setZero] = useState(false)

useEffect(() => {
Expand All @@ -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') {
Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { Modal } from '@/components'
import { ReviewDetailedData } from '@/types'
Expand Down Expand Up @@ -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) => (
<Questions
question={question}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { ReviewDetailedData } from '@/types'
import { ReceiverItem, QuestionItem } from '../'
Expand Down Expand Up @@ -42,6 +43,10 @@ const ReviewReply = ({ reviewData }: ReviewReplyProps) => {
setSelectedReceiverIndex,
})

useEffect(() => {
setSelectedQuestionIndex(0)
}, [selectedReceiver, setSelectedQuestionIndex])

const questionArray = questions.map((question, index) => (
<Questions
question={question}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { Modal } from '@/components'
import { ReviewDetailedData } from '@/types'
Expand Down Expand Up @@ -48,6 +49,10 @@ const ReviewReply = ({ reviewData, handleSubmit }: ReviewReplyProps) => {
const { individualReplyCompletes, allReplyComplete, checkReplyComplete } =
useReplyComplete({ receivers, selectedReceiverIndex })

useEffect(() => {
setSelectedQuestionIndex(0)
}, [selectedReceiver, setSelectedQuestionIndex])

const questionArray = questions.map((question, index) => (
<Questions
question={question}
Expand Down

0 comments on commit 4814e09

Please sign in to comment.