CheckPage.js 2.47 KB
Newer Older
Ha YeaJin's avatar
pages    
Ha YeaJin committed
1
2
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
3
import axios from 'axios';
Choi Ga Young's avatar
Choi Ga Young committed
4
import 'bootstrap/dist/css/bootstrap.css';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
5

6
function Check(props) {
Choi Ga Young's avatar
Choi Ga Young committed
7
    
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    function getReserve() {
        axios.get(`/reserves/${props.match.params.id}`, {
            headers: { authorization: localStorage.getItem('token') },
        })
            .then(res => {
                if (res.status !== 201) {
                    alert(res.data.error);
                }
                console.log(res.data);
                setReserve(res.data);
            })
            .catch(err => {
                alert(err.error)
            });
    }
Choi Ga Young's avatar
Choi Ga Young committed
23
24
25
26
27
28
29
30
31
32
33
    function remove(index) {
        axios.delete(`/reserves/${reserve[index]._id}`)
            .then(res => {
                if (res.status === 404) return alert(res.data.error)
                alert("삭제되었습니다!")
                getReserve();
            })
            .catch(err => {
                alert(err.error)
            });
    };
34
35
36
37
38

    const [reserve, setReserve] = useState([]);
    useEffect(() => {
        getReserve();
    }, [])
Choi Ga Young's avatar
Choi Ga Young committed
39

Ha YeaJin's avatar
pages    
Ha YeaJin committed
40
41
42
    return (
        <div>
            <Menu />
Choi Ga Young's avatar
Choi Ga Young committed
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
            <div className="">check
                <table className="table">
                    <thead>
                        <tr>
                            <th>아이디</th>
                            <th>이름</th>
                            <th>날짜</th>
                            <th>강의실</th>
                            <th>예약취소</th>
                        </tr>
                    </thead>
                    <tbody>
                        {reserve.map((reserve, index) => {
                            return (
                                <tr key={index}>
                                    <td>{props.match.params.id}</td>
                                    <td>{reserve.name}</td>
                                    <td>{reserve.date}</td>
                                    <td>{reserve.room}</td>
                                    <td>
                                        <button onClick={() => remove(index)} className="btn btn-danger">
                                            취소
                                        </button>
                                    </td>
                                </tr>
                            )
                        })}
                    </tbody>
                </table>

Ha YeaJin's avatar
pages    
Ha YeaJin committed
73
74
75
76
77
            </div>
        </div>
    )
}

Choi Ga Young's avatar
Choi Ga Young committed
78
export default Check