CheckPage.js 2.65 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) {
CHAERIN KIM's avatar
CHAERIN KIM committed
7
8
9
10
    const [reserve, setReserve] = useState([]);
    useEffect(() => {
        getReserve();
    }, [])
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    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
27
28
29
30
    function remove(index) {
        axios.delete(`/reserves/${reserve[index]._id}`)
            .then(res => {
                if (res.status === 404) return alert(res.data.error)
CHAERIN KIM's avatar
CHAERIN KIM committed
31
                alert("삭제되었습니다!");
Choi Ga Young's avatar
Choi Ga Young committed
32
33
34
35
36
37
                getReserve();
            })
            .catch(err => {
                alert(err.error)
            });
    };
38

Ha YeaJin's avatar
pages    
Ha YeaJin committed
39
40
41
    return (
        <div>
            <Menu />
CHAERIN KIM's avatar
CHAERIN KIM committed
42
            <div className="">
Choi Ga Young's avatar
Choi Ga Young committed
43
44
45
46
                <table className="table">
                    <thead>
                        <tr>
                            <th>날짜</th>
CHAERIN KIM's avatar
CHAERIN KIM committed
47
                            <th>시간</th>
Choi Ga Young's avatar
Choi Ga Young committed
48
                            <th>강의실</th>
CHAERIN KIM's avatar
CHAERIN KIM committed
49
50
                            <th>사용인원</th>
                            <th>승인여부</th>
Choi Ga Young's avatar
Choi Ga Young committed
51
52
53
54
55
56
57
58
                            <th>예약취소</th>
                        </tr>
                    </thead>
                    <tbody>
                        {reserve.map((reserve, index) => {
                            return (
                                <tr key={index}>
                                    <td>{reserve.date}</td>
59
                                    <td>{reserve.starttime}~{(Number(reserve.starttime) + reserve.usetime)}</td>
Choi Ga Young's avatar
Choi Ga Young committed
60
                                    <td>{reserve.room}</td>
CHAERIN KIM's avatar
CHAERIN KIM committed
61
                                    <td>{reserve.num}</td>
62
                                    <td>{reserve.approve ? "사용허가" : "글쎄..."}</td>
Choi Ga Young's avatar
Choi Ga Young committed
63
64
65
66
67
68
69
70
71
72
73
                                    <td>
                                        <button onClick={() => remove(index)} className="btn btn-danger">
                                            취소
                                        </button>
                                    </td>
                                </tr>
                            )
                        })}
                    </tbody>
                </table>

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

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