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); }, }, );