Commit 0af3e43b authored by Choi Ga Young's avatar Choi Ga Young
Browse files

checkPage기능

parent 82e694e8
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu'; import Menu from '../Components/Menu';
import List from '../Components/List';
import axios from 'axios'; import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.css';
function Check(props) { function Check(props) {
function getReserve() { function getReserve() {
axios.get(`/reserves/${props.match.params.id}`, { axios.get(`/reserves/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') }, headers: { authorization: localStorage.getItem('token') },
...@@ -19,21 +20,59 @@ function Check(props) { ...@@ -19,21 +20,59 @@ function Check(props) {
alert(err.error) alert(err.error)
}); });
} }
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)
});
};
const [reserve, setReserve] = useState([]); const [reserve, setReserve] = useState([]);
useEffect(() => { useEffect(() => {
getReserve(); getReserve();
}, []) }, [])
return ( return (
<div> <div>
<Menu /> <Menu />
<div className="container">check <div className="">check
{reserve.map((reserve, index) => <table className="table">
<List id={props.match.params.id} index={index} date={reserve.date} name={reserve.name} room={reserve.room} time={reserve.time} num={reserve.num} _id={reserve._id}/> <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>
</div> </div>
</div> </div>
) )
} }
export default Check export default Check
\ No newline at end of file
...@@ -34,6 +34,7 @@ ReactDOM.render( ...@@ -34,6 +34,7 @@ ReactDOM.render(
<Redirect path="/" to="/" /> <Redirect path="/" to="/" />
<Redirect path="/home" to="/" /> <Redirect path="/home" to="/" />
<Redirect path="/change/:id" to="/change"/> <Redirect path="/change/:id" to="/change"/>
<Redirect path="/check/:id" to="/check"/>
</Switch> </Switch>
</Router>, </Router>,
document.getElementById('root') document.getElementById('root')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment