ApplyPage.js 8.33 KB
Newer Older
Choi Ga Young's avatar
Choi Ga Young committed
1
import React from 'react';
2
import { Formik } from 'formik';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
3
import Menu from '../Components/Menu';
4
import axios from 'axios';
Choi Ga Young's avatar
Choi Ga Young committed
5
6
import 'bootstrap/dist/css/bootstrap.css';
import * as Yup from 'yup';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
7
8
9
10
11
12

function Apply() {
    return (
        <div>
            <Menu />
            <div className="container">apply
13
14
            <Formik
                    initialValues={{
Choi Ga Young's avatar
Choi Ga Young committed
15
16
17
18
                        date: '',
                        time: '',
                        room: '',
                        name: '',
19
                        _id: "5f786720c45bbf6c68899c51",
Choi Ga Young's avatar
Choi Ga Young committed
20
21
                        reason: '',
                        member: '',
22
23
24
                        approve: false,
                        num: 5,
                    }}
Choi Ga Young's avatar
Choi Ga Young committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
                    validationSchema={Yup.object({
                        date: Yup.string()
                            .required('날짜를 입력해주세요.'),
                        time: Yup.string()
                            .required('시간을 입력해주세요.'),
                        room: Yup.string()
                            .required('강의실 번호를 입력해주세요.'),
                        reason: Yup.string()
                            .required('대관목적을 입력해주세요.'),
                        name: Yup.string()
                            .required('대표자 성함을 입력해주세요.'),
                        member: Yup.string()
                            .required('이용자 성함을 입력해주세요.'),
                    })}
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
                    onSubmit={(values, { setSubmitting }) => {
                        axios({
                            method: 'post',
                            url: '/reserves',
                            data: values,
                        }).then(res => {
                            if (res.status === 404) return alert(res.data.error)
                            alert("신청이 완료되었습니다!")

                        })
                            .catch(err => {
                                alert(err.error)
                            });

                        setTimeout(() => {
                            setSubmitting(false);
                        }, 400);  // finish the cycle in handler
                    }}
                >
                    {({
Choi Ga Young's avatar
Choi Ga Young committed
59
60
                        errors,
                        touched,
61
                        handleSubmit,
Choi Ga Young's avatar
Choi Ga Young committed
62
                        getFieldProps,
63
64
65
66
                        isSubmitting,
                    }) => (
                            <div className="row justify-content-center align-items-center">
                                <form onSubmit={handleSubmit} className="col-sm-3">
Choi Ga Young's avatar
Choi Ga Young committed
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
                                    <div className="form-group mb-4">
                                        <label>신청날짜</label>
                                        <input
                                            className={(touched.date && errors.date ? 'form-control is-invalid' : "form-control")}
                                            type="number"
                                            name="date"
                                            {...getFieldProps('date')}
                                            placeholder="2020mmdd"
                                        />
                                        {touched.date && errors.date ? (
                                            <div className="invalid-feedback text-left">{errors.date}</div>
                                        ) : null}
                                    </div>
                                    <div className="form-group mb-4">
                                        <label>이용시간</label>
                                        <input
                                            className={(touched.time && errors.time ? 'form-control is-invalid' : "form-control")}
                                            type="text"
                                            name="time"
                                            {...getFieldProps('time')}
                                            placeholder="ex) 11:00~14:00"
                                        />
                                        {touched.time && errors.time ? (
                                            <div className="invalid-feedback text-left">{errors.time}</div>
                                        ) : null}
                                    </div>
                                    <div className="form-group mb-4">
                                        <label>강의실</label>
                                        <input
                                            className={(touched.room && errors.room ? 'form-control is-invalid' : "form-control")}
                                            type="text"
                                            name="room"
                                            {...getFieldProps('room')}
                                            placeholder="bn-nnn"
                                        />
                                        {touched.room && errors.room ? (
                                            <div className="invalid-feedback text-left">{errors.room}</div>
                                        ) : null}
                                    </div>
                                    <div className="form-group mb-4">
                                        <label>대관목적</label>
                                        <input
                                            className={(touched.reason && errors.reason ? 'form-control is-invalid' : "form-control")}
                                            type="text"
                                            name="reason"
                                            {...getFieldProps('reason')}
                                            placeholder="대관목적을 입력해 주세요."
                                        />
                                        {touched.reason && errors.reason ? (
                                            <div className="invalid-feedback text-left">{errors.reason}</div>
                                        ) : null}
                                    </div>
                                    <div className="form-group mb-4">
                                        <label>대표자</label>
                                        <input
                                            className={(touched.name && errors.name ? 'form-control is-invalid' : "form-control")}
                                            type="text"
                                            name="name"
                                            {...getFieldProps('name')}
                                            placeholder="대표자 성함을 입력해 주세요"
                                        />
                                        {touched.name && errors.name ? (
                                            <div className="invalid-feedback text-left">{errors.name}</div>
                                        ) : null}
                                    </div>
                                    <div className="form-group mb-4">
                                        <label>이용자</label>
                                        <input
                                            className={(touched.member && errors.member ? 'form-control is-invalid' : "form-control")}
                                            type="text"
                                            name="member"
                                            {...getFieldProps('member')}
                                            placeholder="이용자 성함을 입력해 주세요. "
                                        />
                                        {touched.member && errors.member ? (
                                            <div className="invalid-feedback text-left">{errors.member}</div>
                                        ) : null}
                                    </div>
145
                                    <button type="submit" className="btn btn-dark" disabled={isSubmitting}>
Choi Ga Young's avatar
Choi Ga Young committed
146
147
                                        신청하기
                                    </button>
148
149
150
151
                                </form>
                            </div>
                        )}
                </Formik>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
152
153
154
155
156
157
            </div>
        </div>
    )
}

export default Apply