SignupForm.js 5.23 KB
Newer Older
1
2
3
4
5
6
import React from 'react';
import { Formik } from 'formik';
import * as Yup from 'yup';

const SignupForm = () => {
  return (
Kim, Subin's avatar
Kim, Subin committed
7
8
9
    <>
      <div className="py-5">
        <h1 className="text-center">회원가입</h1>
10
11
12
      </div>
      <Formik
        initialValues={{
13
          userId: '',
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
          password: '',
          repassword: '',
          userName: '',
          userStudNum: ''
        }}
        validationSchema={Yup.object({
          userId: Yup.string()
            .required('아이디를 입력해주세요.')
            .max(15, '15자 이내로 입력해주세요.')
            .min(5, '최소 5자 이상 입력해주세요.'),
          password: Yup.string()
            .required('비밀번호를 입력해주세요.')
            .min(8, '최소 8자 이상 입력해주세요.'),
          repassword: Yup.string()
            .required('비밀번호를 입력해주세요.')
            .min(8, '최소 8자 이상 입력해주세요.')
            .oneOf([Yup.ref("password"), null], '비밀번호가 일치하지 않습니다.'),
          userName: Yup.string()
            .required('이름을 입력해주세요.'),
          userStudNum: Yup.string()
            .required('학번을 입력해주세요.')
            .min(7, '학번을 정확히 입력해주세요.'),
        })}
        onSubmit={(values, { setSubmitting }) => {
          setTimeout(() => {
            alert(JSON.stringify(values, null, 2));
            setSubmitting(false);
          }, 400);
        }}
      >
        {formik => (
Kim, Subin's avatar
Kim, Subin committed
45
          <form onSubmit={formik.handleSubmit} className="mt-3">
46
47
48
49
50
51
52
53
            <div className="mb-3 d-flex flex-row">
              <label className="form-label" style={{ width: "100px" }}>아이디</label>
              <div className="flex-col">
                <input type="text" name="userId"
                  className="form-control border-top-0 border-end-0 border-start-0"
                  style={{ boxShadow: "none", borderRadius: "0" }}
                  {...formik.getFieldProps('userId')} />
                {formik.touched.userId && formik.errors.userId ? (
54
                  <div className="text-danger mt-1" style={{ fontSize: "10px" }}>{formik.errors.userId}</div>
55
56
57
58
59
60
61
62
63
64
65
                ) : null}
              </div>
            </div>
            <div className="mb-3 d-flex flex-row">
              <label className="form-label" style={{ width: "100px" }}>비밀번호</label>
              <div className="flex-col">
                <input type="password" name="password"
                  className="form-control border-top-0 border-end-0 border-start-0"
                  style={{ boxShadow: "none", borderRadius: "0" }}
                  {...formik.getFieldProps('password')} />
                {formik.touched.password && formik.errors.password ? (
66
                  <div className="text-danger mt-1" style={{ fontSize: "10px" }}>{formik.errors.password}</div>
67
68
                ) : null}
              </div>
69
            </div>
70
71
72
73
74
75
76
77
            <div className="mb-3 d-flex flex-row">
              <label className="form-label" style={{ width: "100px", wordBreak: "keep-all" }}>비밀번호 확인</label>
              <div className="flex-col">
                <input type="password" name="repassword"
                  className="form-control border-top-0 border-end-0 border-start-0"
                  style={{ boxShadow: "none", borderRadius: "0" }}
                  {...formik.getFieldProps('repassword')} />
                {formik.touched.repassword && formik.errors.repassword ? (
78
                  <div className="text-danger mt-1" style={{ fontSize: "10px" }}>{formik.errors.repassword}</div>
79
80
                ) : null}
              </div>
81
            </div>
82
83
84
85
86
87
88
89
            <div className="mb-3 d-flex flex-row">
              <label className="form-label" style={{ width: "100px" }}>이름</label>
              <div className="flex-col">
                <input type="text" name="userName"
                  className="form-control border-top-0 border-end-0 border-start-0"
                  style={{ boxShadow: "none", borderRadius: "0" }}
                  {...formik.getFieldProps('userName')} />
                {formik.touched.userName && formik.errors.userName ? (
90
                  <div className="text-danger mt-1" style={{ fontSize: "10px" }}>{formik.errors.userName}</div>
91
92
                ) : null}
              </div>
93
            </div>
94
95
96
97
98
99
100
101
            <div className="mb-3 d-flex flex-row">
              <label className="form-label" style={{ width: "100px" }}>학번</label>
              <div className="flex-col">
                <input type="text" name="userStudNum"
                  className="form-control border-top-0 border-end-0 border-start-0"
                  style={{ boxShadow: "none", borderRadius: "0" }}
                  {...formik.getFieldProps('userStudNum')} />
                {formik.touched.userStudNum && formik.errors.userStudNum ? (
102
                  <div className="text-danger mt-1" style={{ fontSize: "10px" }}>{formik.errors.userStudNum}</div>
103
104
                ) : null}
              </div>
105
            </div>
106
107
            <div className="d-grid gap-2 ">
              <button type="submit" className="btn btn-crimson my-5">확인</button>
108
109
110
111
            </div>
          </form>
        )}
      </Formik>
Kim, Subin's avatar
Kim, Subin committed
112
    </>
113
114
115
  );
}

Kim, Subin's avatar
Kim, Subin committed
116
export default SignupForm;