Commit 9cc867e8 authored by CHAERIN KIM's avatar CHAERIN KIM
Browse files

승인 미승인

parent f3752c81
......@@ -8,12 +8,12 @@ function ACheck(props) {
const [state, setState] = useState()
const [reserve, setReserve] = useState([]);
useEffect(() => {
getReserve();
getReserve();
}, [])
function getReserve() {
axios.get(`/users/admin/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') },
axios.get(`/users/admin/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status === 404) {
......@@ -30,10 +30,19 @@ function ACheck(props) {
if (state) return <Redirect to="/home" />;
function remove(index) {
axios.delete(`/reserves/${reserve[index]._id}`)
// axios.delete(`/reserves/${reserve[index]._id}`)
// .then(res => {
// if (res.status === 404) return alert(res.data.error)
// alert("삭제되었습니다!");
// getReserve();
// })
// .catch(err => {
// alert(err.error)
// });
axios.put(`/reserves/${reserve[index]._id}`)
.then(res => {
if (res.status === 404) return alert(res.data.error)
alert("삭제되었습니다!");
alert("승인을 거절했습니다!");
getReserve();
})
.catch(err => {
......@@ -42,7 +51,9 @@ function ACheck(props) {
};
function admit(index) {
axios.put(`/reserves/${reserve[index]._id}`)
axios.put(`/reserves/${reserve[index]._id}`, {
approve: true,
})
.then(res => {
if (res.status === 404) return alert(res.data.error)
alert("승인되었습니다!");
......@@ -69,25 +80,26 @@ function ACheck(props) {
</tr>
</thead>
<tbody>
{reserve.map((reserve, index) => {
return (
<tr key={index}>
<td>{reserve.user.name}</td>
<td>{reserve.date}</td>
<td>{reserve.time}</td>
<td>{reserve.room}</td>
<td>{reserve.num}</td>
<td>
<button onClick={() => admit(index)} className="btn btn-primary">
승인
{reserve != "" ? (
reserve.map((reserve, index) => {
return (
<tr key={index}>
<td>{reserve.user.name}</td>
<td>{reserve.date}</td>
<td>{reserve.starttime}~{(Number(reserve.starttime) + reserve.usetime)}</td>
<td>{reserve.room}</td>
<td>{reserve.num}</td>
<td>
<button onClick={() => admit(index)} className="btn btn-primary">
승인
</button>
<button onClick={() => remove(index)} className="btn btn-danger">
거절
<button onClick={() => remove(index)} className="btn btn-danger">
거절
</button>
</td>
</tr>
)
})}
</td>
</tr>
)
})) : <div>최근 대관 신청 내역이 없습니다.</div>}
</tbody>
</table>
......
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