Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-fe: 전화번호 포맷팅 버그 #585

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions frontend/src/components/recruitmentPost/ApplyForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { validateEmail, validateName, validatePhoneNumber } from '@domain/valida
import { ApplicantData, ApplyRequestBody, Question } from '@customTypes/apply';
import { applyMutations, applyQueries } from '@hooks/apply';
import useForm from '@hooks/utils/useForm';
import { formatPhoneNumber } from '@utils/formatPhoneNumber';
import { useParams } from 'react-router-dom';

import CheckBox from '@components/common/CheckBox';
Expand Down Expand Up @@ -57,7 +56,7 @@ export default function ApplyForm({ questions, isClosed }: ApplyFormProps) {
body: {
applicant: {
...applicant,
phone: applicant.phone.replace(/-/g, ''),
phone: applicant.phone,
},
answers: Object.entries(answers).map(([questionId, answer]) => ({
questionId,
Expand Down Expand Up @@ -95,7 +94,6 @@ export default function ApplyForm({ questions, isClosed }: ApplyFormProps) {
onBlur: validatePhoneNumber.onBlur,
onChange: validatePhoneNumber.onChange,
},
formatter: formatPhoneNumber,
})}
inputMode="numeric"
label="전화 번호"
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/domain/validations/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isEmptyString, isNumber } from './common';

const regex = {
email: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
phone: /^\d{3}-\d{3,4}-\d{4}$/,
phone: /^\d{11}$/,
name: /[^ㄱ-ㅎ가-힣a-zA-Z\s-]/,
};

Expand All @@ -14,9 +14,12 @@ const isValidEmail = (email: string): email is EmailAddress => regex.email.test(
type PhoneNumber = Branded<string, 'PhoneNumber'>;
const isValidPhoneNumber = (phone: string): phone is PhoneNumber => regex.phone.test(phone);

type Name = Branded<string, 'Name'>;
const isValidName = (name: string): name is Name => !regex.name.test(name);

export const validateName = {
onBlur: (name: string) => {
if (regex.name.test(name)) {
if (!isValidName(name)) {
throw new ValidationError({ inputName: 'name', message: '한글, 영문, 공백, - 만 입력해 주세요.' });
}

Expand All @@ -26,7 +29,7 @@ export const validateName = {
},

onChange: (name: string) => {
if (regex.name.test(name)) {
if (!isValidName(name)) {
throw new ValidationError({ inputName: 'name', message: '한글, 영문, 공백, - 만 입력해 주세요.' });
}
},
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/pages/SignUp/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useState } from 'react';
import { Link } from 'react-router-dom';
import InputField from '@components/common/InputField';
import Button from '@components/common/Button';
import InputField from '@components/common/InputField';
import Spinner from '@components/common/Spinner';
import { validateEmail, validatePhoneNumber } from '@domain/validations/apply';
import useSignUp from '@hooks/useSignUp';
import useForm from '@hooks/utils/useForm';
import { validateEmail, validatePhoneNumber } from '@domain/validations/apply';
import { formatPhoneNumber } from '@utils/formatPhoneNumber';
import Spinner from '@components/common/Spinner';
import { useState } from 'react';
import { Link } from 'react-router-dom';
import PasswordInput from './PasswordInput';
import S from './style';

Expand All @@ -29,7 +28,7 @@ export default function SignUp() {
return;
}

signUpMutate.mutate({ ...formData, phone: formData.phone.split('-').join('') });
signUpMutate.mutate({ ...formData });
};

const deleteHangulFormatter = (value: string) => {
Expand All @@ -56,7 +55,6 @@ export default function SignUp() {
<InputField
{...register('phone', {
validate: validatePhoneNumber,
formatter: formatPhoneNumber,
placeholder: '전화번호',
inputMode: 'numeric',
maxLength: 13,
Expand Down
Loading