Skip to content

Commit

Permalink
fix: isFormValid가 false일 때 서버 요청 안 하기
Browse files Browse the repository at this point in the history
  • Loading branch information
chlwlstlf committed Nov 4, 2024
1 parent 71a515f commit d603b54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
},
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
},
},
);
Expand Down

0 comments on commit d603b54

Please sign in to comment.