From d603b54b56588cc5f7e20f784bffbb242ef0b999 Mon Sep 17 00:00:00 2001 From: jinsil Date: Mon, 4 Nov 2024 10:59:57 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20isFormValid=EA=B0=80=20false=EC=9D=BC=20?= =?UTF-8?q?=EB=95=8C=20=EC=84=9C=EB=B2=84=20=EC=9A=94=EC=B2=AD=20=EC=95=88?= =?UTF-8?q?=20=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RevieweeFeedbackLayout.tsx | 27 +++++++++---------- .../ReviewerFeedbackLayout.tsx | 22 +++++++-------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/frontend/src/components/feedback/revieweeFeedbackLayout/RevieweeFeedbackLayout.tsx b/frontend/src/components/feedback/revieweeFeedbackLayout/RevieweeFeedbackLayout.tsx index 1f9e5297a..78ab7c5fe 100644 --- a/frontend/src/components/feedback/revieweeFeedbackLayout/RevieweeFeedbackLayout.tsx +++ b/frontend/src/components/feedback/revieweeFeedbackLayout/RevieweeFeedbackLayout.tsx @@ -49,6 +49,11 @@ const RevieweeFeedbackLayout = ({ const displayedKeywords = roomInfo.keywords.filter((keyword) => keyword !== ""); + const isFormValid = + formState.evaluationPoint !== 0 && + formState.feedbackKeywords.length > 0 && + formState.recommendationPoint !== 0; + useEffect(() => { if (feedbackData) { setFormState(getInitialFormState(reviewee, feedbackData)); @@ -72,34 +77,28 @@ const RevieweeFeedbackLayout = ({ } }; - const isFormValid = formState.evaluationPoint !== 0 && formState.feedbackKeywords.length > 0; - const handleSubmit = () => { setIsClicked(true); - if (feedbackType === "view") return; - const formattedFormState = { - ...formState, - feedbackText: formState.feedbackText, - feedbackKeywords: formState.feedbackKeywords, - evaluationPoint: formState.evaluationPoint, - }; + if (!isFormValid || feedbackType === "view") return; if (feedbackType === "create") { postRevieweeFeedbackMutation.mutate( - { feedbackData: formattedFormState }, + { feedbackData: formState }, { onSuccess: () => { - navigate(`/rooms/${roomInfo.id}`); + navigate(-1); }, }, ); - } else if (feedbackType === "edit") { + } + + if (feedbackType === "edit") { putRevieweeFeedbackMutation.mutate( - { feedbackId: formState.feedbackId, feedbackData: formattedFormState }, + { feedbackId: formState.feedbackId, feedbackData: formState }, { onSuccess: () => { - navigate(`/rooms/${roomInfo.id}`); + navigate(-1); }, }, ); diff --git a/frontend/src/components/feedback/reviewerFeedbackLayout/ReviewerFeedbackLayout.tsx b/frontend/src/components/feedback/reviewerFeedbackLayout/ReviewerFeedbackLayout.tsx index 01db54650..bf0f8f238 100644 --- a/frontend/src/components/feedback/reviewerFeedbackLayout/ReviewerFeedbackLayout.tsx +++ b/frontend/src/components/feedback/reviewerFeedbackLayout/ReviewerFeedbackLayout.tsx @@ -48,6 +48,8 @@ const ReviewerFeedbackLayout = ({ const displayedKeywords = roomInfo.keywords.filter((keyword) => keyword !== ""); + const isFormValid = formState.evaluationPoint !== 0 && formState.feedbackKeywords.length > 0; + useEffect(() => { if (feedbackData) { setFormState(getInitialFormState(reviewer, feedbackData)); @@ -73,30 +75,26 @@ const ReviewerFeedbackLayout = ({ const handleSubmit = () => { setIsClicked(true); - if (feedbackType === "view") return; - const formattedFormState = { - ...formState, - feedbackText: formState.feedbackText, - feedbackKeywords: formState.feedbackKeywords, - evaluationPoint: formState.evaluationPoint, - }; + if (!isFormValid || feedbackType === "view") return; if (feedbackType === "create") { postReviewerFeedbackMutation.mutate( - { feedbackData: formattedFormState }, + { feedbackData: formState }, { onSuccess: () => { - navigate(`/rooms/${roomInfo.id}`); + navigate(-1); }, }, ); - } else if (feedbackType === "edit") { + } + + if (feedbackType === "edit") { putReviewerFeedbackMutation.mutate( - { feedbackId: formState.feedbackId, feedbackData: formattedFormState }, + { feedbackId: formState.feedbackId, feedbackData: formState }, { onSuccess: () => { - navigate(`/rooms/${roomInfo.id}`); + navigate(-1); }, }, );