Commit 9e22fd14 authored by Ha YeaJin's avatar Ha YeaJin
Browse files

행복...하자....

parent 6031e83e
import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom';
import styled from 'styled-components';
import { Navbar, Nav, NavDropdown, NavLink } from 'react-bootstrap';
import { Navbar, Nav, NavLink } from 'react-bootstrap';
import axios from 'axios';
const MENU = styled(Navbar)`
background-color: #7B031D;
......@@ -13,6 +14,7 @@ const MENU = styled(Navbar)`
function Menu() {
const [state, setState] = useState()
const [user, setUser] = useState({ role: "" })
const name = localStorage.getItem('name');
function logout() {
......@@ -21,6 +23,21 @@ function Menu() {
setState(true);
}
useEffect(() => {
acheck();
}, [])
function acheck() {
axios.get(`/users/${localStorage.getItem('_id')}`)
.then(res => {
if (res.data.role == "admin") {
setUser(res.data)
}
}).catch(err => {
alert(err.error)
});
}
if (state) return <Redirect to="/" />
return (
<MENU expand="md" variant="dark">
......@@ -42,11 +59,12 @@ function Menu() {
}} className="nav-link">
대관 확인/취소</NavLink>
{user.role === "admin" ? (
<NavLink as={Link} to={{
pathname: `/acheck/${localStorage.getItem('_id')}`,
state: { id: localStorage.getItem('_id') },
}} className="nav-link">
대관 확인/취소(관리자)</NavLink>
대관 확인/취소(관리자)</NavLink>) : null}
</Nav>
<Nav >
<NavLink>
......
......@@ -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,12 +80,13 @@ function ACheck(props) {
</tr>
</thead>
<tbody>
{reserve.map((reserve, index) => {
{reserve != "" ? (
reserve.map((reserve, index) => {
return (
<tr key={index}>
<td>{reserve.user.name}</td>
<td>{reserve.date}</td>
<td>{reserve.time}</td>
<td>{reserve.starttime}~{(Number(reserve.starttime) + reserve.usetime)}</td>
<td>{reserve.room}</td>
<td>{reserve.num}</td>
<td>
......@@ -87,7 +99,7 @@ function ACheck(props) {
</td>
</tr>
)
})}
})) : <div>최근 대관 신청 내역이 없습니다.</div>}
</tbody>
</table>
......
......@@ -22,7 +22,6 @@ function Apply(props) {
}
function time(starttime) {
console.log(starttime)
if (starttime == 21) {
return (<Field as="select" name="usetime">
<option value="">이용시간을 선택하세요</option>
......@@ -93,17 +92,21 @@ function Apply(props) {
url: '/reserves',
data: values
}).then(res => {
if (res.status === 404) return alert(res.data.error)
if (res.status === 404) {
alert(res.data.error)
return window.location.reload();
}
alert("신청이 완료되었습니다!");
setState(true);
console.log("res.data", res.data)
})
.catch(err => {
alert(err.error)
});
// setTimeout(() => {
// setSubmitting(false);
// }, 400); // finish the cycle in handler
setTimeout(() => {
setSubmitting(false);
}, 400); // finish the cycle in handler
}}
>
{({
......@@ -208,7 +211,6 @@ function Apply(props) {
>
X
</button>
</div>
</div>
))}
......
......@@ -59,7 +59,7 @@ function Check(props) {
<td>{reserve.starttime}~{(Number(reserve.starttime) + reserve.usetime)}</td>
<td>{reserve.room}</td>
<td>{reserve.num}</td>
<td>{reserve.approve ? "승인" : "미승인"}</td>
<td>{reserve.check ? (reserve.approve ? "사용가능" : "사용불가") : "승인대기중"}</td>
<td>
<button onClick={() => remove(index)} className="btn btn-danger">
취소
......
......@@ -4,7 +4,7 @@ import * as Yup from 'yup';
import axios from 'axios';
import { Link, Redirect } from 'react-router-dom';
import styled from 'styled-components';
import { Col, Container, Navbar } from 'react-bootstrap';
import { Col, Container, Navbar, Button } from 'react-bootstrap';
const Menu = styled(Navbar)`
background-color: #7B031D;
......@@ -46,7 +46,7 @@ function Signup() {
</Menu>
<Container fluid>
<Wow className="row justify-content-center">
<Col md={4} className="d-flex align-items-center h-100">
<Col md={3} xs={11} className="p-0">
<Formik
initialValues={{ name: '', id: '', password: '', password2: '', question: '', answer: '' }}
validationSchema={Yup.object({
......@@ -154,8 +154,8 @@ function Signup() {
{...getFieldProps('answer')}
placeholder="Input answer" />
</div>
<button type="submit" className="btn btn-dark" disabled={isSubmitting}>회원가입</button>
<button class="btn btn-light"><Link to="/login">로그인하러 가기</Link></button>
<Button type="submit" variant="secondary" disabled={isSubmitting}>회원가입</Button>
<Button variant="outline-secondary" as={Link} to="/login">로그인하러 가기</Button>
</form>
)}
</Formik>
......
......@@ -7,14 +7,13 @@ const router = express.Router();
router.post('/', function (req, res, next) {
console.log('/reserve post req.body', req.body)
const reserve = new Reserve({
user: req.body._id,
date: req.body.date,
starttime: Number(req.body.starttime),
usetime: Number(req.body.usetime),
start: `${req.body.date}T`+`${req.body.starttime}:00:00`,
end: `${req.body.date}T`+`${Number(req.body.starttime)+Number(req.body.usetime)}:00:00`,
start: `${req.body.date}T` + `${req.body.starttime}:00:00`,
end: `${req.body.date}T` + `${Number(req.body.starttime) + Number(req.body.usetime)}:00:00`,
room: req.body.room,
reason: req.body.reason,
students: req.body.students,
......@@ -22,6 +21,10 @@ router.post('/', function (req, res, next) {
num: req.body.students.length + 1,
});
Reserve.find({ room: req.body.room, approve: true }, function (err, reserves) {
if (err) return res.status(500).json({ error: err });
if (!reserves) {
reserve.save()
.then((result) => {
console.log(result);
......@@ -31,17 +34,47 @@ router.post('/', function (req, res, next) {
console.error(err);
next(err);
});
}
const strt = new Date(reserve.start)
const endt = new Date(reserve.end)
const reserveArr = reserves.map(item => (
(strt >= new Date(item.start) && strt <= new Date(item.end)) ||
(endt >= new Date(item.start) && endt <= new Date(item.end)) ?
"item" :
null
))
console.log("array", reserveArr)
if (!reserveArr.includes("item")) {
reserve.save()
.then((result) => {
console.log(result);
res.status(201).json(reserves);
})
.catch((err) => {
console.error(err);
next(err);
});
}
else return res.status(404).json({ error: "다른 시간을 선택해주세요." })
})
});
router.get('/room/:room', function (req, res, next) {
console.log('reserves get room req.params', req.params)
Reserve.find({ room: req.params.room, approve: true }, function (err, reserve) {
if (err) return res.status(500).json({ error: err });
console.log('reserve room list', reserve);
res.status(201).json(reserve);
})
})
// router.get('/:_id', verifyToken, function (req, res, next) {
router.get('/:_id', function (req, res, next) {
console.log('/reserves get req.params', req.params)
Reserve.find({ user: req.params._id }, function (err, reserve) {
console.log('id.name',reserve)
if (err) return res.status(500).json({ error: err });
console.log('reserve list', reserve)
res.status(201).json(reserve);
})
});
......@@ -73,9 +106,10 @@ router.delete('/:_id', function (req, res, next) {
router.put('/:id', function (req, res, next) {
console.log('/reserves put req.body', req.params)
Reserve.findOne({ _id: req.params.id }, 'approve', function (err, reserve) {
Reserve.findOne({ _id: req.params.id }, 'check approve', function (err, reserve) {
if (err) return res.status(500).json({ error: err });
reserve.approve = true;
reserve.check = true;
reserve.approve = req.body.approve;
reserve.save()
.then((result) => {
console.log(result);
......
......@@ -39,7 +39,10 @@ const reserveSchema = new Schema({
approve: {
type: Boolean,
default: false,
},
check: {
type: Boolean,
default: false,
},
num: {
type: Number,
......
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