Skip to content

Commit be02e83

Browse files
committed
chore: merge
1 parent ed22d65 commit be02e83

File tree

7 files changed

+56
-11
lines changed

7 files changed

+56
-11
lines changed

โ€Žsrc/components/Join/EmailInput.tsxโ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import InputForm from '../common/InputForm.tsx';
22
import { useJoinState } from '../../stores/joinStore.ts';
3-
import { isValidEmail } from '../../utils/authUtils.ts';
3+
import { LooseValidation, ValidateProcessor } from '../../utils/authUtils.ts';
44

55
const EmailInput = () => {
66
const { email, emailHandler } = useJoinState();
7+
const validator = new ValidateProcessor(new LooseValidation());
78

89
return (
910
<InputForm
@@ -16,7 +17,7 @@ const EmailInput = () => {
1617
name={'email'}
1718
id={'email-input'}
1819
aria-label={'join-email-input'}
19-
error={!isValidEmail(email)}
20+
error={!validator.isValidEmail(email)}
2021
errorText={'โ€ป ์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.'}
2122
/>
2223
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function FormatPhone(phone: string) {
2+
const formatted = phone.replace(/(\d{3})(\d{4})(\d{4})/, '$1-$2-$3');
3+
return formatted;
4+
}

โ€Žsrc/components/Join/NameInput.tsxโ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import InputForm from '../common/InputForm.tsx';
22
import { useJoinState } from '../../stores/joinStore.ts';
3-
import { isValidName } from '../../utils/authUtils.ts';
3+
import { LooseValidation, ValidateProcessor } from '../../utils/authUtils.ts';
44

55
const NameInput = () => {
66
const { name, nameHandler } = useJoinState();
7+
const validator = new ValidateProcessor(new LooseValidation());
78

89
return (
910
<InputForm
@@ -16,7 +17,7 @@ const NameInput = () => {
1617
name={'name'}
1718
id={'name-input'}
1819
aria-label={'join-name-input'}
19-
error={!isValidName(name)}
20+
error={!validator.isValidName(name)}
2021
errorText={'โ€ป ์ด๋ฆ„์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.'}
2122
/>
2223
);

โ€Žsrc/components/Join/PasswordInput.tsxโ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import InputForm from '../common/InputForm.tsx';
22
import { useJoinState } from '../../stores/joinStore.ts';
3-
import { isValidPassword } from '../../utils/authUtils.ts';
3+
import { LooseValidation, ValidateProcessor } from '../../utils/authUtils.ts';
44

55
const PasswordInput = () => {
66
const { password, passwordHandler } = useJoinState();
7+
const validator = new ValidateProcessor(new LooseValidation());
78

89
return (
910
<InputForm
@@ -16,7 +17,7 @@ const PasswordInput = () => {
1617
type={'password'}
1718
id={'password-input'}
1819
aria-label={'join-password-input'}
19-
error={!isValidPassword(password)}
20+
error={!validator.isValidPassword(password)}
2021
errorText={'โ€ป ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” 6์ž๋ฆฌ ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.'}
2122
/>
2223
);

โ€Žsrc/components/Join/PhoneInput.tsxโ€Ž

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import InputForm from '../common/InputForm.tsx';
22
import { useJoinState } from '../../stores/joinStore.ts';
3-
import { isValidPhone, formatPhone } from '../../utils/authUtils.ts';
3+
import { FormatPhone } from './formatPhone.tsx';
4+
import { LooseValidation, ValidateProcessor } from '../../utils/authUtils.ts';
45

56
const PhoneInput = () => {
67
const { phone, phoneHandler } = useJoinState();
7-
const formattedPhone = isValidPhone(phone) ? formatPhone(phone) : phone;
8+
const validator = new ValidateProcessor(new LooseValidation());
9+
const formattedPhone = validator.isValidPhone(phone) ? FormatPhone(phone) : phone;
810

911
return (
1012
<InputForm
@@ -16,7 +18,7 @@ const PhoneInput = () => {
1618
name={'phone'}
1719
id={'phone-input'}
1820
aria-label={'join-phone-input'}
19-
error={!isValidPhone(phone)}
21+
error={!validator.isValidPhone(phone)}
2022
value={formattedPhone}
2123
errorText={"โ€ป '-' ์ œ์™ธ 11์ž๋ฆฌ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”"}
2224
/>

โ€Žsrc/components/Join/PwCheckInput.tsxโ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import InputForm from '../common/InputForm.tsx';
22
import { useJoinState } from '../../stores/joinStore.ts';
3-
import { isValidPwCheck } from '../../utils/authUtils.ts';
3+
import { LooseValidation, ValidateProcessor } from '../../utils/authUtils.ts';
44

55
const PwCheckInput = () => {
66
const { pwCheck, password, pwCheckHandler } = useJoinState();
7+
const validator = new ValidateProcessor(new LooseValidation());
78

89
return (
910
<InputForm
@@ -16,7 +17,7 @@ const PwCheckInput = () => {
1617
name={'pwCheck'}
1718
id={'pwCheck-input'}
1819
aria-label={'join-pwCheck-input'}
19-
error={!isValidPwCheck(pwCheck, password)}
20+
error={!validator.isValidPwCheck(pwCheck, password)}
2021
errorText={'โ€ป ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.'}
2122
/>
2223
);

โ€Žsrc/utils/authUtils.tsโ€Ž

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
export interface ValidationStrategy {
2+
nameValidate(input: string): boolean;
3+
phoneValidate(input: string): boolean;
24
emailValidate(input: string): boolean;
35
passwordValidate(input: string): boolean;
6+
pwCheckValidate(pwCheck: string, password: string): boolean;
47
}
58

69
export class LooseValidation implements ValidationStrategy {
10+
nameValidate(name: string): boolean {
11+
return name.length >= 2;
12+
}
13+
phoneValidate(phone: string): boolean {
14+
return phone.length == 11;
15+
}
16+
17+
pwCheckValidate(pwCheck: string, password: string): boolean {
18+
return pwCheck == password;
19+
}
20+
721
emailValidate(email: string): boolean {
822
return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/.test(email);
923
}
@@ -13,6 +27,15 @@ export class LooseValidation implements ValidationStrategy {
1327
}
1428

1529
export class StrongValidation implements ValidationStrategy {
30+
nameValidate(name: string): boolean {
31+
return name.length >= 2;
32+
}
33+
phoneValidate(phone: string): boolean {
34+
return phone.length == 11;
35+
}
36+
pwCheckValidate(pwCheck: string, password: string): boolean {
37+
return pwCheck == password;
38+
}
1639
emailValidate(password: string): boolean {
1740
return password.length >= 6;
1841
}
@@ -32,11 +55,23 @@ export class ValidateProcessor {
3255
this.#validator = validator;
3356
}
3457

58+
isValidName(name: string) {
59+
return this.#validator.nameValidate(name);
60+
}
61+
62+
isValidPhone(phone: string) {
63+
return this.#validator.phoneValidate(phone);
64+
}
65+
3566
isValidEmail(email: string) {
3667
return this.#validator.emailValidate(email);
3768
}
3869

3970
isValidPassword(password: string) {
4071
return this.#validator.passwordValidate(password);
4172
}
73+
74+
isValidPwCheck(password: string, pwCheck: string) {
75+
return this.#validator.pwCheckValidate(password, pwCheck);
76+
}
4277
}

0 commit comments

Comments
ย (0)