Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/fe/develop' into fe-590-_COM_C…
Browse files Browse the repository at this point in the history
…REATE_APPLY_01
  • Loading branch information
seongjinme committed Aug 21, 2024
2 parents 6855d5f + 7ef48ba commit e629c83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
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

0 comments on commit e629c83

Please sign in to comment.