From eb32a6934f9c5e6bdc0c1d9b96031124938dee8b Mon Sep 17 00:00:00 2001 From: Kim0426 <706shin1728@naver.com> Date: Wed, 29 Nov 2023 14:59:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=A0=84?= =?UTF-8?q?=20=ED=94=BC=EB=93=9C=EB=B0=B1=EB=B0=98=EC=98=81=20(#90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: useRef bool -> number배열로 관리, 리뷰 전송 시 리뷰 디테일 다시 받게 설정 * refactor: 엔터 눌러도 바로 로그인 가능하게 설정 * refactor: axios 에러일 때 분기 처리 * refactor: 드롭다운 스타일 수정 * refactor: 설문 마감 시 최종 리뷰 결과 요청 전송안하게 설정 * refactor: 설문 상태에 따라 버튼 분기처리 * refactor: textarea 스타일 수정 --- src/apis/hooks/useSaveFinalResult.ts | 2 +- src/apis/hooks/useSendReview.ts | 18 +++++- .../components/AnswerGroup/index.tsx | 2 +- .../ReceiverTabReviewDatail/index.tsx | 16 +++-- .../ResponserTabReviewDetail/index.tsx | 4 +- src/pages/CreatedReviewManagePage/index.tsx | 64 +++++++++++-------- src/pages/LoginPage/components/LoginGroup.tsx | 12 +++- src/pages/LoginPage/index.tsx | 5 +- 8 files changed, 83 insertions(+), 40 deletions(-) diff --git a/src/apis/hooks/useSaveFinalResult.ts b/src/apis/hooks/useSaveFinalResult.ts index 98a05d38..b128e227 100644 --- a/src/apis/hooks/useSaveFinalResult.ts +++ b/src/apis/hooks/useSaveFinalResult.ts @@ -16,7 +16,7 @@ const useSaveFinalResult = (finalResult: T) => { return useMutation({ mutationFn: saveFinalResult, - onMutate: async () => { + onMutate: () => { const reviewId = finalResult.reviewId const userId = finalResult.userId diff --git a/src/apis/hooks/useSendReview.ts b/src/apis/hooks/useSendReview.ts index 72936643..5e55397d 100644 --- a/src/apis/hooks/useSendReview.ts +++ b/src/apis/hooks/useSendReview.ts @@ -1,4 +1,4 @@ -import { useMutation } from '@tanstack/react-query' +import { useMutation, useQueryClient } from '@tanstack/react-query' import apiClient from '@/apis/apiClient' interface Response { @@ -8,13 +8,25 @@ interface Response { } //NOTE - 대상자별 조합된 리뷰 결과를 저장 -const useSendReview = () => { - const sendReview = async ({ reviewId }: { reviewId: string }) => { +const useSendReview = ({ reviewId }: { reviewId: string }) => { + const queryClient = useQueryClient() + + const prevSendResultData = queryClient.getQueryData<{ + success: boolean + data: number[] + }>([`/final-results/${reviewId}/status`]) + + const sendReview = async () => { return await apiClient.post(`/final-results/${reviewId}`) } return useMutation({ mutationFn: sendReview, + onSuccess: () => { + queryClient.setQueryData([`/final-results/${reviewId}/status`], { + ...prevSendResultData, + }) + }, }) } export default useSendReview diff --git a/src/pages/CreatedReviewManagePage/components/AnswerGroup/index.tsx b/src/pages/CreatedReviewManagePage/components/AnswerGroup/index.tsx index db3cdffe..5493b3a9 100644 --- a/src/pages/CreatedReviewManagePage/components/AnswerGroup/index.tsx +++ b/src/pages/CreatedReviewManagePage/components/AnswerGroup/index.tsx @@ -106,7 +106,7 @@ const renderResponseByQuestion = (
diff --git a/src/pages/CreatedReviewManagePage/components/ReceiverTabReviewDatail/index.tsx b/src/pages/CreatedReviewManagePage/components/ReceiverTabReviewDatail/index.tsx index a25d0112..321c106a 100644 --- a/src/pages/CreatedReviewManagePage/components/ReceiverTabReviewDatail/index.tsx +++ b/src/pages/CreatedReviewManagePage/components/ReceiverTabReviewDatail/index.tsx @@ -26,7 +26,7 @@ const ReceiverReviewDetail = ({ //NOTE - 하나라도 응답 실패했을 떄 처리 const { addToast } = useToast() - const hasAnswered = useRef(false) + const hasAnswered = useRef([]) const { data: getReviewQuestion } = useGetReviewForCreator({ id: Number(reviewId), }) @@ -88,12 +88,15 @@ const ReceiverReviewDetail = ({ const { mutate: updateFinalReviewAnswer } = useUpdateFinalReviewAnswer() useEffect(() => { + if (getReviewQuestion.status === 'END') { + return + } if ( !ResponserList?.includes(Number(receiverId)) && - hasAnswered.current.valueOf() === false + !hasAnswered.current.includes(Number(receiverId)) ) { saveFinalResult() - hasAnswered.current = true + hasAnswered.current = [...hasAnswered.current, Number(receiverId)] } }, [receiverId]) @@ -126,9 +129,12 @@ const ReceiverReviewDetail = ({ return ( <> -
+
-
diff --git a/src/pages/CreatedReviewManagePage/components/ResponserTabReviewDetail/index.tsx b/src/pages/CreatedReviewManagePage/components/ResponserTabReviewDetail/index.tsx index 5faee63f..ff99c370 100644 --- a/src/pages/CreatedReviewManagePage/components/ResponserTabReviewDetail/index.tsx +++ b/src/pages/CreatedReviewManagePage/components/ResponserTabReviewDetail/index.tsx @@ -42,11 +42,11 @@ const ReceiverReviewDetail = ({ return ( <> -
+
diff --git a/src/pages/CreatedReviewManagePage/index.tsx b/src/pages/CreatedReviewManagePage/index.tsx index 63bc0b82..f3bed307 100644 --- a/src/pages/CreatedReviewManagePage/index.tsx +++ b/src/pages/CreatedReviewManagePage/index.tsx @@ -30,9 +30,10 @@ const CreatedReviewManagePage = () => { ) //NOTE - 리뷰의 질문을 가져온다! - const { data: getReviewQuestion } = useGetReviewForCreator({ - id: Number(reviewId), - }) + const { data: getReviewQuestion, refetch: getUpdatdReviewQuestion } = + useGetReviewForCreator({ + id: Number(reviewId), + }) const { data: checkAllReceiverReceived } = useCheckAllReceiverReceived({ id: reviewId, @@ -40,7 +41,7 @@ const CreatedReviewManagePage = () => { const { mutate: closeReview } = useCloseSurvey({ id: reviewId }) - const { mutate: sendReview } = useSendReview() + const { mutate: sendReview } = useSendReview({ reviewId }) const handleClickSurveyClose = () => { closeReview(undefined, { onSuccess: () => { @@ -70,23 +71,21 @@ const CreatedReviewManagePage = () => { return } - sendReview( - { reviewId }, - { - onSuccess: ({ data }) => { - if (data.errorCode && data.message) { - addToast({ message: data.message, type: 'error' }) + sendReview(undefined, { + onSuccess: ({ data }) => { + if (data.errorCode && data.message) { + addToast({ message: data.message, type: 'error' }) - return - } + return + } - addToast({ - message: '리뷰가 성공적으로 전송되었어요!', - type: 'success', - }) - }, + addToast({ + message: '리뷰가 성공적으로 전송되었어요!', + type: 'success', + }) + getUpdatdReviewQuestion() }, - ) + }) } const REVIEW_MANAGE_TAB_CONTENT = { @@ -111,7 +110,13 @@ const CreatedReviewManagePage = () => { > receiver.receiverId, + ) + : checkAllReceiverReceived?.data + } /> ), @@ -132,7 +137,7 @@ const CreatedReviewManagePage = () => { {getReviewQuestion?.description}
{REVIEW_MANAGE_TAB_CONTENT[activeTab]}
- {getReviewQuestion?.status === 'PROCEEDING' ? ( + {getReviewQuestion?.status === 'PROCEEDING' && ( - ) : ( + )} + + {getReviewQuestion.status === 'DEADLINE' && ( )} + + {getReviewQuestion.status === 'END' && ( + + )}
) diff --git a/src/pages/LoginPage/components/LoginGroup.tsx b/src/pages/LoginPage/components/LoginGroup.tsx index 76740091..d3224490 100644 --- a/src/pages/LoginPage/components/LoginGroup.tsx +++ b/src/pages/LoginPage/components/LoginGroup.tsx @@ -8,7 +8,11 @@ interface LoginGroupProps { } const LoginGroup = ({ handleLogin }: LoginGroupProps) => { const navigate = useNavigate() - const { register, handleSubmit } = useForm() + const { register, handleSubmit } = useForm({ + mode: 'onChange', + }) + + const { onChange: onChangePassword } = register('password') return (
{
- +
diff --git a/src/pages/LoginPage/index.tsx b/src/pages/LoginPage/index.tsx index 8562c2e8..2461f31c 100644 --- a/src/pages/LoginPage/index.tsx +++ b/src/pages/LoginPage/index.tsx @@ -1,3 +1,4 @@ +import { AxiosError } from 'axios' import { useNavigate } from 'react-router-dom' import { Header } from '@/components' import { useLogin, useUser } from '@/apis/hooks' @@ -25,7 +26,9 @@ const LoginPage = () => { navigate('/') }, onError(data) { - addToast({ message: data.message, type: 'error' }) + if (data instanceof AxiosError) { + addToast({ message: data.response?.data.message, type: 'error' }) + } }, }, )