Signup.js 6.28 KB
Newer Older
한규민's avatar
한규민 committed
1
import styles from "./signup.module.scss";
2
import { useState } from 'react';
한규민's avatar
한규민 committed
3
4

const Signup = () => {
5
6

    const [userText, setUserState] = useState({
한규민's avatar
한규민 committed
7
        userID: '',
8
        userName: '',
한규민's avatar
한규민 committed
9
10
        userBirthday: '',
        userMbnum: '',
11
        userPassword: '',
한규민's avatar
한규민 committed
12
        userRePassword: '',
13
    })
한규민's avatar
signup    
한규민 committed
14
// 비밀번호와 비밀번호 확인 일치여부, 중복확인 창
15
    const [passwordError,setPasswordError] = useState(false);
한규민's avatar
signup    
한규민 committed
16
    const [overlapId,setOverlapIdError] = useState(false);
17
18
19
20
21
22

    const handleUserOnChange = (e) => {
        setUserState({
            ...userText,
            [e.target.name]: e.target.value
        })
23
24
25
        if(e.target.name === "userRePassword"){
        setPasswordError(e.target.value !== userText.userPassword);
    }}
26

한규민's avatar
signup    
한규민 committed
27
28
29
30
31
32
    //중복되었으면 중복확인 창 띄우는 여부를 state에 전달
    const handleOverlapIdError = (e) => {
        e.preventDefault();
        setOverlapIdError(true);
    }
    //가입완료 누르면 콘솔창에 전달하려는 state 보여줌
33
34
    const onSubmit = (e) => {
        e.preventDefault();
한규민's avatar
signup    
한규민 committed
35
        console.log(userText)
한규민's avatar
한규민 committed
36
    }
37

한규민's avatar
한규민 committed
38
    return (
한규민's avatar
한규민 committed
39
        <form className={`d-flex col-md-6 col-12 justify-content-center`}>
한규민's avatar
한규민 committed
40
            <div className="d-flex flex-column">
한규민's avatar
signup    
한규민 committed
41
42
43
44
45
46
47
48
49
50
                <span className={styles.title}>회원가입</span>
                <div className="d-flex flex-column">
                    <div className={styles.inputContent}>
                        <label className={styles.signupLabel}>아이디</label>
                        <div className="d-flex col-md-auto">
                            <input className={styles.input} type="text" name="userID" id="userID" placeholder="8자리입력" onChange={handleUserOnChange} maxLength="8" minlength="8" required />
                            <button type="button" className={`rounded-2 mt-2 ${styles.butterYellowAndBtn} ${styles.btnHover}`} onClick={handleOverlapIdError} data-bs-toggle="modal" data-bs-target="#exampleModal">중복확인</button>
                        </div>
                    </div> 
                    {overlapId && <p className={styles.passwordConfirmError}>아이디 중복확인이 되었습니다.</p>}
51
                </div>
한규민's avatar
한규민 committed
52
                <div className={styles.inputContent}>
53
                    <label className={styles.signupLabel}>별명</label>
54
                    <input className={`${styles.input} ${styles.inputSize}`} type="text" name="userName" id="userName" placeholder="10자리 이내" onChange={handleUserOnChange} maxLength="10" required />
55
                </div>
한규민's avatar
한규민 committed
56
                <div className={styles.inputContent}>
57
                    <label className={styles.signupLabel}>생년월일</label>
58
                    <input className={`${styles.input} ${styles.inputSize} ${styles.input.placeholder}`} type="number" name="userBirthday" id="userBirthday" placeholder="6자리(예시: 991225)" onChange={handleUserOnChange} min="0" max="999999" required />
59
                </div>
한규민's avatar
한규민 committed
60
                <div className={styles.inputContent}>
61
                    <label className={styles.signupLabel}>휴대폰 번호</label>
62
                    <input className={`${styles.input} ${styles.inputSize}`} type="number" name="userMbnum" id="userMbnum" placeholder="-없이 11자리 입력" onChange={handleUserOnChange} min="0" max="99999999999" required />
63
                </div>
한규민's avatar
한규민 committed
64
                <div className={`${styles.inputContent}`}>
65
                    <label className={styles.signupLabel}>비밀번호</label>
한규민's avatar
signup    
한규민 committed
66
                    <input className={`${styles.input} ${styles.inputSize}`} type="password" name="userPassword" id="password" placeholder="8자리 입력" onChange={handleUserOnChange} maxLength="8" minlength="8" required />
67
                </div>
68
69
70
                <div className="d-flex flex-column">
                    <div className={styles.inputContent}>                    
                        <label className={styles.signupLabel}>비밀번호 확인</label>
한규민's avatar
signup    
한규민 committed
71
                        <input className={`${styles.input} ${styles.inputSize}`} type="password" name="userRePassword" id="userRePassword" placeholder="8자리 입력" onChange={handleUserOnChange} maxLength="8" minlength="8" required />
한규민's avatar
한규민 committed
72
                    </div>
73
                    {passwordError && <p className={styles.passwordConfirmError}>비밀번호가 일치하지 않습니다.</p>}
한규민's avatar
한규민 committed
74
75
                </div>

한규민's avatar
signup    
한규민 committed
76
                <buttom type="button" className={`rounded- my-3 py-2 fs-5 ${styles.butterYellowAndBtn} ${styles.btnHover}`} type="submit" onClick={onSubmit} data-bs-toggle="modal" data-bs-target="#exampleModal2">가입하기</buttom>
한규민's avatar
한규민 committed
77
            </div>
78

한규민's avatar
한규민 committed
79
80
81
82
83
84
85
86
87
88
89
            {/* 아이디 중복 확인 모달창 */}
            <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">아이디 중복 확인</h5>
                        </div>
                        <div class="modal-body">
                             아이디는 사용가능합니다.
                        </div>
                        <div class="modal-footer">
90
                            <button type="button" className="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
한규민's avatar
한규민 committed
91
92
93
                        </div>
                    </div>
                </div>
94
            </div>
한규민's avatar
signup    
한규민 committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

            {/* 회원가입 완료 모달창 */}
            <div class="modal fade" id="exampleModal2" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">회원가입</h5>
                        </div>
                        <div class="modal-body">
                            회원가입이 완료되었습니다. 
                        </div>
                        <div class="modal-footer">
                            <button type="button" className="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
                        </div>
                    </div>
                </div>
            </div>
한규민's avatar
한규민 committed
112
113
114
        </form>


한규민's avatar
한규민 committed
115
116
117
118
    )
}

export default Signup