CheckPage.js 3.37 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';
Lee Jin Ju's avatar
Lee Jin Ju committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Table from 'react-bootstrap/Table'
import { Container } from 'react-bootstrap';
import styled from 'styled-components';

const Ta = styled(Table)`
margin-top: 0.5em;

  & th, & td {
    padding: 0;
    vertical-align: middle;
    font-size: 0.9rem;
    margin-left : auto; margin-right : auto;
    border-spacing: initial;
  };

  & tr {
    display: d-flex;
    width: 150px;
  };

  & td {
    align-items: center;
    margin: 10px;
  };

`
Ha YeaJin's avatar
pages    
Ha YeaJin committed
30

31
function Check(props) {
CHAERIN KIM's avatar
CHAERIN KIM committed
32
33
34
35
    const [reserve, setReserve] = useState([]);
    useEffect(() => {
        getReserve();
    }, [])
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    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
52
53
54
55
    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
56
                alert("삭제되었습니다!");
Choi Ga Young's avatar
Choi Ga Young committed
57
58
59
60
61
62
                getReserve();
            })
            .catch(err => {
                alert(err.error)
            });
    };
63

Ha YeaJin's avatar
pages    
Ha YeaJin committed
64
65
66
    return (
        <div>
            <Menu />
Lee Jin Ju's avatar
Lee Jin Ju committed
67
68
69
            <Container fluid>
                <Ta responsive="lg ml-2rem">
                    <thead className="thead-light">
Choi Ga Young's avatar
Choi Ga Young committed
70
                        <tr>
Lee Jin Ju's avatar
Lee Jin Ju committed
71
72
73
74
75
76
                            <th className="text-center">날짜</th>
                            <th className="text-center">시간</th>
                            <th className="text-center">강의실</th>
                            <th className="text-center">사용인원</th>
                            {/* <th>승인여부</th> */}
                            <th className="text-center">예약취소</th>
Choi Ga Young's avatar
Choi Ga Young committed
77
78
79
80
81
82
                        </tr>
                    </thead>
                    <tbody>
                        {reserve.map((reserve, index) => {
                            return (
                                <tr key={index}>
Lee Jin Ju's avatar
Lee Jin Ju committed
83
84
85
86
87
88
89
                                    <td className="text-center">{reserve.date}</td>
                                    <td className="text-center">{reserve.starttime}~{(Number(reserve.starttime) + reserve.usetime)}</td>
                                    <td className="text-center">{reserve.room}</td>
                                    <td className="text-center">{reserve.num}</td>
                                    {/* <td>{reserve.check ? (reserve.approve ? "사용가능" : "사용불가") : "승인대기중"}</td> */}
                                    <td className="text-center">
                                        <button onClick={() => remove(index)} className="btn btn-danger btn-sm">
Choi Ga Young's avatar
Choi Ga Young committed
90
91
92
93
94
95
96
                                            취소
                                        </button>
                                    </td>
                                </tr>
                            )
                        })}
                    </tbody>
Lee Jin Ju's avatar
Lee Jin Ju committed
97
98
                </Ta>
            </Container>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
99
100
101
102
        </div>
    )
}

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