CheckPage.js 2.16 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
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function Check(props) {
    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)
            });
    }
CHAERIN KIM's avatar
CHAERIN KIM committed
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
55
56
57
58
59
    function remove(index) {
        axios.delete(`/reserves/${reserve[index]._id}`)
            .then(res => {
                if (res.status === 404) return alert(res.data.error)
                alert("삭제되었습니다!")
            })
            .catch(err => {
                alert(err.error)
            });
    };
    function renderTableBody() {
        return 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-dark">
                            취소
                        </button>
                    </td>
                </tr>
            )
        })
    }
    
    function renderTableHeader(props) {
        return (
            <tr>
                <th>아이디</th>
                <th>이름</th>
                <th>날짜</th>
                <th>강의실</th>
                <th>예약취소</th>
            </tr>
        )
    }
60
61
62
63
64

    const [reserve, setReserve] = useState([]);
    useEffect(() => {
        getReserve();
    }, [])
Ha YeaJin's avatar
pages    
Ha YeaJin committed
65
66
67
    return (
        <div>
            <Menu />
CHAERIN KIM's avatar
CHAERIN KIM committed
68
69
70
71
72
            <div className="">check
                    <tbody>
                        {renderTableHeader()}
                        {renderTableBody()}
                    </tbody>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
73
74
75
76
77
78
            </div>
        </div>
    )
}

export default Check