Skip to content

Commit 611906a

Browse files
authored
Merge pull request #120 from imaginer-dev/8-회원가입-폼을-입력하고-유효성-검증을-할-수-있어야-한다
8 회원가입 폼을 입력하고 유효성 검증을 할 수 있어야 한다
2 parents 42f2a5d + 4b90103 commit 611906a

File tree

13 files changed

+157
-25
lines changed

13 files changed

+157
-25
lines changed

src/components/Join/EmailInput.tsx

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

45
const EmailInput = () => {
56
const { email, emailHandler } = useJoinState();
7+
const validator = new ValidateProcessor(new LooseValidation());
68

79
return (
810
<InputForm
911
defaultValue={email}
1012
title={'이메일'}
11-
placeholder={'이메일을 입력하세요'}
12-
hint={'Hint Text'}
13+
placeholder={'이메일 입력'}
14+
hint={''}
1315
onChange={(e) => emailHandler(e.target.value)}
1416
type={'email'}
1517
name={'email'}
18+
id={'email-input'}
19+
aria-label={'join-email-input'}
20+
error={!validator.isValidEmail(email)}
21+
errorText={'※ 올바른 이메일을 입력해 주세요.'}
1622
/>
1723
);
1824
};
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/JoinButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useJoinState } from '../../stores/joinStore';
22

33
const JoinButton = () => {
4-
const { name, phone, email, password, pwCheck, useTermsCheck, privacyTermsCheck } = useJoinState();
4+
const { nickName, name, phone, email, password, pwCheck, useTermsCheck, privacyTermsCheck } = useJoinState();
55

66
const onClick = () => {
7+
console.log('nickName: ', nickName);
78
console.log('name: ', name);
89
console.log('phone: ', phone);
910
console.log('email: ', email);

src/components/Join/NameInput.tsx

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

45
const NameInput = () => {
56
const { name, nameHandler } = useJoinState();
7+
const validator = new ValidateProcessor(new LooseValidation());
68

79
return (
810
<InputForm
911
defaultValue={name}
1012
title={'이름'}
11-
placeholder={'이름을 입력하세요'}
12-
hint={'Hint Text'}
13+
placeholder={'이름(필수)'}
14+
hint={''}
1315
onChange={(e) => nameHandler(e.target.value)}
1416
type={'name'}
1517
name={'name'}
18+
id={'name-input'}
19+
aria-label={'join-name-input'}
20+
error={!validator.isValidName(name)}
21+
errorText={'※ 이름을 입력해 주세요.'}
1622
/>
1723
);
1824
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import InputForm from '../common/InputForm.tsx';
2+
import { useJoinState } from '../../stores/joinStore.ts';
3+
4+
const NickNameInput = () => {
5+
const { nickName, nickNameHandler } = useJoinState();
6+
7+
return (
8+
<InputForm
9+
defaultValue={nickName}
10+
title={'닉네임'}
11+
placeholder={'닉네임 입력'}
12+
hint={''}
13+
onChange={(e) => nickNameHandler(e.target.value)}
14+
type={'name'}
15+
name={'nickName'}
16+
id={'nickName-input'}
17+
aria-label={'join-nickName-input'}
18+
/>
19+
);
20+
};
21+
22+
export default NickNameInput;

src/components/Join/PasswordInput.tsx

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

45
const PasswordInput = () => {
56
const { password, passwordHandler } = useJoinState();
7+
const validator = new ValidateProcessor(new LooseValidation());
68

79
return (
810
<InputForm
911
defaultValue={password}
1012
title={'비밀번호'}
11-
placeholder={'Password'}
12-
hint={'Hint Text'}
13+
placeholder={'비밀번호 입력'}
14+
hint={''}
1315
onChange={(e) => passwordHandler(e.target.value)}
1416
name={'password'}
1517
type={'password'}
18+
id={'password-input'}
19+
aria-label={'join-password-input'}
20+
error={!validator.isValidPassword(password)}
21+
errorText={'※ 비밀번호는 6자리 이상이어야 합니다.'}
1622
/>
1723
);
1824
};

src/components/Join/PhoneInput.tsx

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

46
const PhoneInput = () => {
57
const { phone, phoneHandler } = useJoinState();
8+
const validator = new ValidateProcessor(new LooseValidation());
9+
const formattedPhone = validator.isValidPhone(phone) ? FormatPhone(phone) : phone;
610

711
return (
812
<InputForm
9-
defaultValue={phone}
10-
title={'핸드폰 번호'}
11-
placeholder={'핸드폰 번호를 입력하세요'}
12-
hint={'Hint Text'}
13+
title={'휴대폰 번호'}
14+
placeholder={"휴대폰 번호 입력 ('-' 제외 11자리 입력)"}
15+
hint={''}
1316
onChange={(e) => phoneHandler(e.target.value)}
1417
type={'phone'}
1518
name={'phone'}
19+
id={'phone-input'}
20+
aria-label={'join-phone-input'}
21+
error={!validator.isValidPhone(phone)}
22+
value={formattedPhone}
23+
errorText={"※ '-' 제외 11자리를 입력해 주세요"}
1624
/>
1725
);
1826
};

src/components/Join/PwCheckInput.tsx

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

45
const PwCheckInput = () => {
5-
const { pwCheck, pwCheckHandler } = useJoinState();
6+
const { pwCheck, password, pwCheckHandler } = useJoinState();
7+
const validator = new ValidateProcessor(new LooseValidation());
68

79
return (
810
<InputForm
911
defaultValue={pwCheck}
1012
title={'비밀번호 확인'}
11-
placeholder={'Password Check'}
12-
hint={'Hint Text'}
13+
placeholder={'비밀번호 확인'}
14+
hint={''}
1315
onChange={(e) => pwCheckHandler(e.target.value)}
14-
name={'pwCheck'}
1516
type={'password'}
17+
name={'pwCheck'}
18+
id={'pwCheck-input'}
19+
aria-label={'join-pwCheck-input'}
20+
error={!validator.isValidPwCheck(pwCheck, password)}
21+
errorText={'※ 비밀번호가 일치하지 않습니다.'}
1622
/>
1723
);
1824
};

src/components/Join/TermsCheckInput.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ const TermsCheckInput = () => {
1010
</div>
1111
<div className="mt-2 flex items-center justify-between">
1212
<label htmlFor="termsOne">이용약관 동의 (필수)</label>
13-
<input type="radio" className="radio-primary radio" checked={useTermsCheck} onClick={useTermsCheckHandler} />
13+
<input
14+
type="radio"
15+
className="radio-primary radio"
16+
checked={useTermsCheck}
17+
onClick={useTermsCheckHandler}
18+
readOnly
19+
/>
1420
</div>
1521
{!useTermsCheck ? <span className="text-red-500">이용약관에 동의해 주세요.</span> : <span className="h-6"></span>}
1622
<div className="mt-2 flex items-center justify-between">
@@ -20,6 +26,7 @@ const TermsCheckInput = () => {
2026
className="radio-primary radio"
2127
checked={privacyTermsCheck}
2228
onClick={privacyTermsCheckHandler}
29+
readOnly
2330
/>
2431
</div>
2532
{!privacyTermsCheck ? (

src/components/Join/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import EmailInput from './EmailInput.tsx';
2+
import JoinButton from './JoinButton.tsx';
3+
import JoinForm from './JoinForm.tsx';
4+
import JoinFormActions from './JoinFormActions.tsx';
5+
import NameInput from './NameInput.tsx';
6+
import NickNameInput from './NickNameInput.tsx';
7+
import PasswordInput from './PasswordInput.tsx';
8+
import PhoneInput from './PhoneInput.tsx';
9+
import PwCheckInput from './PwCheckInput.tsx';
10+
import TermsCheckInput from './TermsCheckInput.tsx';
11+
12+
export {
13+
EmailInput,
14+
JoinButton,
15+
JoinForm,
16+
JoinFormActions,
17+
NameInput,
18+
NickNameInput,
19+
PasswordInput,
20+
PhoneInput,
21+
PwCheckInput,
22+
TermsCheckInput,
23+
};

0 commit comments

Comments
 (0)