SignUp.js 4.58 KB
Newer Older
Kim, Chaerin's avatar
Kim, Chaerin committed
1
2
3
4
5
6
7
8
9
10
11
12
import { useEffect, useState } from "react";

const INIT_USER = {
  name: "",
  idNumber1: "",
  idNumber2: "",
  id: "",
  password: "",
  checkpw: "",
  phone: "",
};

Kim, Chaerin's avatar
Kim, Chaerin committed
13
const Signup = () => {
Kim, Chaerin's avatar
Kim, Chaerin committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
  const [user, setUser] = useState(INIT_USER);
  const [error, setError] = useState("");
  const [success, setSuccess] = useState(false);
  let disabled = false;

  useEffect(() => {
    disabled = !(
      user.name &&
      user.idNumber1 &&
      user.idNumber2 &&
      user.id &&
      user.password &&
      user.checkpw
    );
  }, [user]);

  function handleChange(event) {
    const { name, value } = event.target;
    setUser({ ...user, [name]: value });
    console.log(user);
  }

  async function handleSubmit() {
    try {
      // setLoading(true);
      // setError("");
      //   const success = await login(user.email, user.password);
      console.log(user);
      setSuccess(success);
    } catch (error) {
      // catchErrors(error, setError);
    } finally {
      // setLoading(false);
    }
  }

  const { name, idNumber1, idNumber2, id, password, checkpw, phone } = user;
  return (
    <div className="modal-content">
      <form onSubmit={handleSubmit}>
        <div className="modal-header">
          <h5 className="modal-title" id="loginModalLabel">
            회원가입
          </h5>
          <button
            type="button"
            className="btn-close"
            data-bs-dismiss="modal"
            aria-label="Close"
          ></button>
        </div>
        <div className="modal-body">
          <div className="p-2">
            <label className="p-1">이름</label>
            <input
              className="form-control"
              id="name"
              type="text"
              name="name"
              placeholder="이름을 입력하세요"
              value={name}
              onChange={handleChange}
            />
          </div>
          <div className="p-2">
            <label className="p-1">주민등록번호</label>
            <div className="d-flex text-center">
              <div className="col-4">
                <input
                  className="m-2 form-control"
                  id="idNumber1"
                  type="text"
                  name="idNumber1"
                  placeholder="●●●●●●"
                  value={idNumber1}
                  onChange={handleChange}
                />
              </div>
              <div className="col-1"></div>
              <div className="col-1">
                <input
                  className="m-2 form-control"
                  id="idNumber2"
                  type="text"
                  name="idNumber2"
                  placeholder=""
                  value={idNumber2}
                  onChange={handleChange}
                />
              </div>
              ******
            </div>
          </div>
          <div className="p-2">
            <label className="p-1">아이디</label>
            <input
              className="form-control"
              id="id"
              type="text"
              name="id"
              placeholder="아이디를 입력하세요"
              value={id}
              onChange={handleChange}
            />
          </div>
          <div className="p-2">
            <label className="p-1">비밀번호</label>
            <input
              className="form-control"
              id="password"
              type="password"
              name="password"
              placeholder="비밀번호를 입력하세요"
              value={password}
              onChange={handleChange}
            />
          </div>
          <div className="p-2">
            <label className="p-1">비밀번호확인</label>
            <input
              className="form-control"
              id="checkpw"
              type="password"
              name="checkpw"
              placeholder="비밀번호를 다시 입력하세요"
              value={checkpw}
              onChange={handleChange}
            />
          </div>
          <div className="p-2">
            <label className="p-1">전화번호(선택)</label>
            <input
              className="form-control"
              id="phone"
              type="text"
              name="phone"
              placeholder="숫자만 입력하세요"
              value={phone}
              onChange={handleChange}
            />
          </div>
        </div>
        <div className="modal-footer">
          <button type="submit" className="btn btn-primary" disabled={disabled}>
            회원가입
          </button>
Kim, Chaerin's avatar
Kim, Chaerin committed
160
        </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
161
162
163
      </form>
    </div>
  );
Kim, Chaerin's avatar
Kim, Chaerin committed
164
165
166
};

export default Signup;