From 8a2abef22e8015092ec7a8bbae898b245f43e5b2 Mon Sep 17 00:00:00 2001 From: Jihoo Kim Date: Thu, 10 Aug 2023 04:28:52 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B3=B5=EB=B0=B1=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=20=EC=A0=9C=ED=95=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectInformationPage.tsx | 2 +- src/pages/edit-profile/EditProfilePage.tsx | 2 +- src/pages/unregister/UnregisterPage.tsx | 6 +++--- src/pages/write/WritePage.tsx | 6 +++--- src/utils/validations/postForm.ts | 15 ++++++++------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/pages/collect-information/CollectInformationPage.tsx b/src/pages/collect-information/CollectInformationPage.tsx index e77bab8f..0692c628 100644 --- a/src/pages/collect-information/CollectInformationPage.tsx +++ b/src/pages/collect-information/CollectInformationPage.tsx @@ -41,7 +41,7 @@ function CollectInformationPage() { }); await editProfile({ userId: user.id, - job, + job: job.trim(), residenceId, nickname, sex: gender, diff --git a/src/pages/edit-profile/EditProfilePage.tsx b/src/pages/edit-profile/EditProfilePage.tsx index bb137a60..b1d3abf5 100644 --- a/src/pages/edit-profile/EditProfilePage.tsx +++ b/src/pages/edit-profile/EditProfilePage.tsx @@ -73,7 +73,7 @@ function EditProfilePage() { editProfile({ userId: user.id, nickname: formData.nickname, - job: formData.job, + job: formData.job.trim(), worryCategories: formData.categoryIds.length > 0 ? formData.categoryIds : [], sex: formData.gender, diff --git a/src/pages/unregister/UnregisterPage.tsx b/src/pages/unregister/UnregisterPage.tsx index 46ab5b8d..858fa450 100644 --- a/src/pages/unregister/UnregisterPage.tsx +++ b/src/pages/unregister/UnregisterPage.tsx @@ -33,7 +33,7 @@ function UnregisterPage() { if (!reason) { return '계정을 삭제하는 이유를 작성해주세요.'; } - if (reason.length < 5) { + if (reason.trim().length < 5) { return '최소 5자 이상 입력해주세요.'; } if (reason.length >= 5) { @@ -44,7 +44,7 @@ function UnregisterPage() { const handleUnregister = () => { unregister({ userId: user.id, - reason: reason, + reason: reason.trim(), }); }; @@ -66,7 +66,7 @@ function UnregisterPage() { localStorage.removeItem('token'); queryClient.clear(); alert( - '탈퇴가 정상 처리되었습니다.\n고민이 있으면 언제든지 찾아와주세요!' + '탈퇴가 정상 처리되었습니다.\n고민이 있으면 언제든지 찾아와주세요!', ); navigate('/'); } diff --git a/src/pages/write/WritePage.tsx b/src/pages/write/WritePage.tsx index 348faad4..ddba6b16 100644 --- a/src/pages/write/WritePage.tsx +++ b/src/pages/write/WritePage.tsx @@ -51,8 +51,8 @@ function WritePage() { } addPost({ - title, - content, + title: title.trim(), + content: content.trim(), files: images.map((image) => ({ url: image.url, contentType: 'image' })), userId: user?.id, expirationTime: getFutureDateTime(deadline), @@ -60,7 +60,7 @@ function WritePage() { .filter((option) => !!option.label) .map((option, i) => ({ sequenceNumber: i, - label: option.label, + label: option.label.trim(), url: option.image || null, })), worryCategoryId: categoryId, diff --git a/src/utils/validations/postForm.ts b/src/utils/validations/postForm.ts index 6f4f4c27..9c4ab581 100644 --- a/src/utils/validations/postForm.ts +++ b/src/utils/validations/postForm.ts @@ -1,19 +1,19 @@ import { PostFormData } from '@/types/post'; export function validatePostForm( - formData: PostFormData + formData: PostFormData, ): [Record, number | null] { const errorMessage: Record = {}; let voteOptionErrorIndex: null | number = null; const { title, content, deadline, categoryId, voteOptions } = formData; - if (!title) { + if (!title.trim()) { errorMessage.title = '제목을 입력해주세요.'; - } else if (title.length < 2) { + } else if (title.trim().length < 2) { errorMessage.title = '제목을 최소 2자 이상 입력해주세요.'; } - if (!content) { + if (!content.trim()) { errorMessage.content = '내용을 입력해주세요.'; - } else if (content.length < 5) { + } else if (content.trim().length < 5) { errorMessage.content = '내용을 최소 5자 이상 입력해주세요.'; } if (typeof categoryId !== 'number') { @@ -24,7 +24,7 @@ export function validatePostForm( } for (let i = 0; i < voteOptions.length; i++) { const option = voteOptions[i]; - if (option.image && !option.label) { + if (!option.label.trim() || (option.image && !option.label.trim())) { errorMessage.voteOptions = '투표 항목은 텍스트를 포함해야 합니다.'; voteOptionErrorIndex = i; return [errorMessage, voteOptionErrorIndex]; @@ -32,7 +32,7 @@ export function validatePostForm( } let count = 0; for (const option of voteOptions) { - if (option.label) { + if (option.label.trim()) { count += 1; } } @@ -60,5 +60,6 @@ export function validatePostForm( labels.push(option.label); } } + console.log(errorMessage.voteOptions); return [errorMessage, voteOptionErrorIndex]; }