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';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
4

5
function Check(props) {
CHAERIN KIM's avatar
CHAERIN KIM committed
6
7
8
9
    const [reserve, setReserve] = useState([]);
    useEffect(() => {
        getReserve();
    }, [])
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    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
26
27
28
29
    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
30
                alert("삭제되었습니다!");
Choi Ga Young's avatar
Choi Ga Young committed
31
32
33
34
35
36
                getReserve();
            })
            .catch(err => {
                alert(err.error)
            });
    };
37

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