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

승인 미승인

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