ApplyPage.js 2.14 KB
Newer Older
Ha YeaJin's avatar
pages    
Ha YeaJin committed
1
import React, { useState, useEffect } 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';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
5
6
7
8
9
10

function Apply() {
    return (
        <div>
            <Menu />
            <div className="container">apply
11
12
13
14
15
16
            <Formik
                    initialValues={{
                        date: "20201003",
                        time: "시간",
                        room: "9-116",
                        name: "종윤",
17
                        _id: "5f786720c45bbf6c68899c51",
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
                        reason: "study hard",
                        member: "jinju rkyoung",
                        approve: false,
                        num: 5,
                    }}
                    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
                    }}
                >
                    {({
                        handleSubmit,
                        isSubmitting,
                    }) => (
                            <div className="row justify-content-center align-items-center">
                                <form onSubmit={handleSubmit} className="col-sm-3">
                                    <button type="submit" className="btn btn-dark" disabled={isSubmitting}>
                                        Sign Up
                                </button>
                                </form>
                            </div>
                        )}
                </Formik>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
55
56
57
58
59
60
            </div>
        </div>
    )
}

export default Apply