Skip to content

Commit

Permalink
Merge branch 'fix/whitespace' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wildcatco committed Aug 9, 2023
2 parents bbc5431 + 8a2abef commit 563ab15
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/pages/collect-information/CollectInformationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function CollectInformationPage() {
});
await editProfile({
userId: user.id,
job,
job: job.trim(),
residenceId,
nickname,
sex: gender,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/edit-profile/EditProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/unregister/UnregisterPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function UnregisterPage() {
if (!reason) {
return '계정을 삭제하는 이유를 작성해주세요.';
}
if (reason.length < 5) {
if (reason.trim().length < 5) {
return '최소 5자 이상 입력해주세요.';
}
if (reason.length >= 5) {
Expand All @@ -44,7 +44,7 @@ function UnregisterPage() {
const handleUnregister = () => {
unregister({
userId: user.id,
reason: reason,
reason: reason.trim(),
});
};

Expand All @@ -66,7 +66,7 @@ function UnregisterPage() {
localStorage.removeItem('token');
queryClient.clear();
alert(
'탈퇴가 정상 처리되었습니다.\n고민이 있으면 언제든지 찾아와주세요!'
'탈퇴가 정상 처리되었습니다.\n고민이 있으면 언제든지 찾아와주세요!',
);
navigate('/');
}
Expand Down
6 changes: 3 additions & 3 deletions src/pages/write/WritePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ 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),
choices: voteOptions
.filter((option) => !!option.label)
.map((option, i) => ({
sequenceNumber: i,
label: option.label,
label: option.label.trim(),
url: option.image || null,
})),
worryCategoryId: categoryId,
Expand Down
15 changes: 8 additions & 7 deletions src/utils/validations/postForm.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { PostFormData } from '@/types/post';

export function validatePostForm(
formData: PostFormData
formData: PostFormData,
): [Record<string, string>, number | null] {
const errorMessage: Record<string, string> = {};
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') {
Expand All @@ -24,15 +24,15 @@ 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];
}
}
let count = 0;
for (const option of voteOptions) {
if (option.label) {
if (option.label.trim()) {
count += 1;
}
}
Expand Down Expand Up @@ -60,5 +60,6 @@ export function validatePostForm(
labels.push(option.label);
}
}
console.log(errorMessage.voteOptions);
return [errorMessage, voteOptionErrorIndex];
}

0 comments on commit 563ab15

Please sign in to comment.