Commit 5d0a841d authored by Lee Jin Ju's avatar Lee Jin Ju
Browse files

Merge remote-tracking branch 'origin/rkyoung7' into hijinju

parents fc35fa9d 5eda65e7
......@@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
debug.log
\ No newline at end of file
import axios from 'axios';
import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom';
import styled from 'styled-components';
import axios from 'axios';
import { Navbar, Nav, NavLink } from 'react-bootstrap';
const MENU = styled(Navbar)`
......@@ -28,8 +28,10 @@ function Menu() {
}, [])
function acheck() {
axios.get(`/users/${localStorage.getItem('_id')}`)
.then(res => {
axios.get(`/users/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') },
}).then(res => {
console.log(res.data)
if (res.data.role == "admin") {
setUser(res.data)
}
......@@ -59,12 +61,12 @@ function Menu() {
}} className="nav-link">
대관 확인/취소</NavLink>
{user.role === "admin" ? (
{/* {user.role === "admin" ? (
<NavLink as={Link} to={{
pathname: `/acheck/${localStorage.getItem('_id')}`,
state: { id: localStorage.getItem('_id') },
}} className="nav-link">
대관 확인/취소(관리자)</NavLink>) : null}
대관 확인/취소(관리자)</NavLink>) : null} */}
</Nav>
<Nav >
<NavLink>
......
......@@ -3,53 +3,20 @@ import Calendar from '@toast-ui/react-calendar';
import "tui-calendar/dist/tui-calendar.css";
import "tui-date-picker/dist/tui-date-picker.css";
import "tui-time-picker/dist/tui-time-picker.css";
import moment from 'moment';
import axios from 'axios';
function Cal(props) {
const calendarRef = useRef();
const calendarRef = useRef(null);
const [reserve, setReserve] = useState([]);
// const [day, setDay] = useState(props.calledday);
const [day, setDay] = useState(props.day);
const [period, setPeriod] = useState();
const [myTheme, setMyTheme] = useState({
'common.dayname.color': '#333',
'common.today.color': '#333',
// 'common.creationGuide.color': 'white',
'common.creationGuide.backgroundColor': 'gray',
// Theme object to extends default dark theme.
});
const yj = [
{
id: 'a',
calendarId: 'Subject',
category: 'time',
start: '2020-10-27T11:00:00',
end: '2020-10-27T12:00:00',
},
{
id: 'b',
calendarId: 'Subject',
category: 'time',
start: '2020-10-28T10:00:00',
end: '2020-10-28T11:00:00',
},
{
id: '3',
calendarId: 'Subject',
category: 'time',
start: '2020-10-29T11:00:00',
end: '2020-10-29T15:00:00',
}
]
function getReserve(room) {
console.log("room", room)
// setReserve({
// id: room,
// calendarId: 'Subject',
// category: 'time',
// })
axios.get(`/reserves/room/${room}`, {
headers: { authorization: localStorage.getItem('token') },
})
......@@ -61,56 +28,68 @@ function Cal(props) {
calendarId: 'Subject',
category: 'time',
}))
console.log("room list", res.data);
setReserve(reserves);
// console.log("room list",res.data);
})
.catch(err => {
alert(err.error)
});
}
useEffect(() => {
// const cal = calendarRef.current.getInstance();
// cal.setDate(new Date(day));
// cal.changeView('week', false);
// cal.today(new Date(day));
function getDataAction(target) {
return target.dataset ? target.dataset.action : target.getAttribute('data-action');
}
// calendar.on('clickSchedule', function (event) {
// const schedule = event.schedule;
function onClickNavi(e) {
const cal = calendarRef.current.getInstance();
const action = getDataAction(e.target);
// if (lastClickSchedule) {
// calendar.updateSchedule(lastClickSchedule.id, lastClickSchedule.calendarId, {
// isFocused: false,
// });
// }
// calendar.updateSchedule(schedule.id, schedule.calendarId, {
// isFocused: true,
// });
switch (action) {
case 'move-prev':
cal.prev();
break;
case 'move-next':
cal.next();
break;
case 'move-today':
cal.today();
break;
default:
return;
}
// lastClickSchedule = schedule;
// // open detail view
setRenderRangeText();
}
// return (console.log(isFocused))
// });
function setRenderRangeText() {
const cal = calendarRef.current.getInstance();
let html = [];
html.push(moment(cal.getDateRangeStart().getTime()).format('YYYY.MM.DD'));
html.push(' ~ ');
html.push(moment(cal.getDateRangeEnd().getTime()).format(' MM.DD'));
setPeriod(html.join(''))
}
// setReserve([
// {
// id: '3',
// calendarId: 'Subject',
// category: 'time',
// start: '2020-10-29T11:00:00',
// end: '2020-10-29T15:00:00',
// }
// ])
useEffect(() => {
setRenderRangeText();
getReserve(props.room);
}, [day])
}, [props.room])
return (
<div>{
console.log("reserve", reserve)}
<div>
<div id="menu">
<span id="menu-navi" onClick={(e) => onClickNavi(e)}>
<button type="button" className="btn btn-default btn-sm move-today" data-action="move-today">Today</button>
<button type="button" className="btn btn-default btn-sm move-day" data-action="move-prev">
<i class="calendar-icon ic-arrow-line-left" data-action="move-prev"></i>
</button>
<button type="button" className="btn btn-default btn-sm move-day" data-action="move-next">
<i className="calendar-icon ic-arrow-line-right" data-action="move-next"></i>
</button>
</span>
<span id="renderRange" className="render-range" style={{ height: "5em" }}>{period}</span>
</div>
<Calendar
ref={calendarRef}
height="100%"
calendars={[
{
......@@ -120,46 +99,11 @@ function Cal(props) {
isReadOnly: 'true'
}
]}
view="week"
disableDblClick={false}
disableClick={true}
isReadOnly={false}
// template={
// popupIsAllDay=function {
// return display: "none"
// }
// }
schedules={ reserve
// reserve.map(item=>({id: item._id,
// start: item.start,
// end: item.end,
// calendarId: 'Subject',
// category: 'time',}))
// [
// {
// id: 'a',
// calendarId: 'Subject',
// category: 'time',
// start: '2020-10-27T11:00:00',
// end: '2020-10-27T12:00:00',
// },
// {
// id: 'b',
// calendarId: 'Subject',
// category: 'time',
// start: '2020-10-28T10:00:00',
// end: '2020-10-28T11:00:00',
// },
// {
// id: '3',
// calendarId: 'Subject',
// category: 'time',
// start: '2020-10-29T11:00:00',
// end: '2020-10-29T15:00:00',
// }
// ]
}
isReadOnly={true}
schedules={reserve}
scheduleView={['time']}
taskView={false}
theme={myTheme}
......
......@@ -47,18 +47,9 @@ function ACheck(props) {
alert(err.error)
});
}
if (state) return <Redirect to="/home" />;
if (state) return <Redirect to="/" />;
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)
// });
axios.put(`/reserves/${reserve[index]._id}`)
.then(res => {
if (res.status === 404) return alert(res.data.error)
......
......@@ -4,16 +4,17 @@ import Menu from '../Components/Menu';
import axios from 'axios';
import * as Yup from 'yup';
import { Redirect } from 'react-router-dom';
import { Col, Container, Row } from 'react-bootstrap';
function Apply(props) {
const [state, setState] = useState();
const [state, setState] = useState({ok:""});
const [user, setUser] = useState({ name: "" });
useEffect(() => {
getUser();
}, [])
if (state) {
if (state.ok==="no") return <Redirect to="/" />;
if (state.ok==="ok") {
return <Redirect to={{
pathname: `/check/${props.match.params.id}`,
state: { id: props.match.params.id },
......@@ -40,7 +41,6 @@ function Apply(props) {
<option value="2">2시간</option>
<option value="3">3시간</option>
</Field>)
}
function getUser() {
......@@ -50,6 +50,8 @@ function Apply(props) {
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
localStorage.clear();
setState({ok:"no"});
}
console.log(res.data);
setUser(res.data);
......@@ -62,6 +64,9 @@ function Apply(props) {
return (
<div>
<Menu />
<Container fluid>
<Row className="justify-content-center">
<Col md={5}>
<Formik
initialValues={{
_id: `${props.match.params.id}`,
......@@ -79,8 +84,6 @@ function Apply(props) {
validationSchema={Yup.object({
date: Yup.string()
.required('날짜를 입력해주세요.'),
room: Yup.string()
.required('강의실 번호를 입력해주세요.'),
reason: Yup.string()
.required('대관목적을 입력해주세요.'),
})}
......@@ -96,7 +99,7 @@ function Apply(props) {
return window.location.reload();
}
alert("신청이 완료되었습니다!");
setState(true);
setState({ok:"ok"});
console.log("res.data", res.data)
})
.catch(err => {
......@@ -116,14 +119,13 @@ function Apply(props) {
getFieldProps,
isSubmitting,
}) => (
<div className="row justify-content-center align-items-center">
<form onSubmit={handleSubmit} className="col-sm-3">
<div className="form-group mb-4">
<label>대표자</label>
<div>{user.name}</div>
</div>
<div className="form-group mb-4">
<label>신청날짜</label>
<form onSubmit={handleSubmit} className="d-flex flex-column">
<h3 className="form-group font-weight-bold">
<label className="pr-2 ">대표자 :</label>{user.name}
</h3>
<div className="form-group">
<div className={touched.date && errors.date ? "text-danger" : ""}>신청날짜</div>
<input
className={(touched.date && errors.date ? 'form-control is-invalid' : "form-control")}
type="text"
......@@ -131,12 +133,11 @@ function Apply(props) {
{...getFieldProps('date')}
placeholder="yyyy-mm-dd"
/>
{touched.date && errors.date ? (
<div className="invalid-feedback text-left">{errors.date}</div>
) : null}
</div>
<div className="form-group mb-4">
<label>이용시작시간</label>
<div>
<Field as="select" name="starttime">
<option value="">이용시작시간</option>
<option value="9">9</option>
......@@ -154,25 +155,27 @@ function Apply(props) {
<option value="21">21</option>
</Field>
</div>
</div>
<div className="form-group mb-4">
<label>이용시간</label>
<div>
{time(values.starttime)}
</div>
</div>
<div className="form-group mb-4">
<label>강의실</label>
<input
className={(touched.room && errors.room ? 'form-control is-invalid' : "form-control")}
type="text"
name="room"
{...getFieldProps('room')}
placeholder="bn-nnn"
/>
{touched.room && errors.room ? (
<div className="invalid-feedback text-left">{errors.room}</div>
) : null}
<div className={touched.room && errors.room ? "text-danger" : ""}>강의실</div>
<Field as="select" name="room">
<option value="">강의실을 선택하세요</option>
<option value="9-116">9-116</option>
<option value="7-234">7-234</option>
<option value="25-101">25-101</option>
</Field>
</div>
<div className="form-group mb-4">
<label>대관목적</label>
<div className={touched.reason && errors.reason ? "text-danger" : ""}>대관 목적</div>
<input
className={(touched.reason && errors.reason ? 'form-control is-invalid' : "form-control")}
type="text"
......@@ -180,19 +183,15 @@ function Apply(props) {
{...getFieldProps('reason')}
placeholder="대관목적을 입력해 주세요."
/>
{touched.reason && errors.reason ? (
<div className="invalid-feedback text-left">{errors.reason}</div>
) : null}
</div>
<div className="form-group mb-4">
<FieldArray name="students">
{({ insert, remove, push }) => (
<div>
<label>이용자</label>
{
values.students.map((student, index) => (
<div className="row" key={index}>
<div className="col">
<div className={touched.date && errors.date ? "text-danger" : ""}>이용자</div>
{values.students.map((student, index) => (
<Row key={index}>
<Field
name={`students.${index}.member`}
placeholder="이용자 성함을 입력하세요."
......@@ -207,19 +206,14 @@ function Apply(props) {
type="button"
className="secondary"
onClick={() => remove(index)}
>
X
</button>
</div>
</div>
>X</button>
</Row>
))}
<button
type="button"
className="btn btn-primary"
onClick={() => push({ member: '' })}
>
추가
</button>
>추가</button>
</div>
)}
</FieldArray>
......@@ -228,9 +222,11 @@ function Apply(props) {
신청하기
</button>
</form>
</div>
)}
</Formik>
</Col>
</Row>
</Container>
</div>
)
}
......
......@@ -4,7 +4,7 @@ import * as Yup from 'yup';
import axios from 'axios';
import Menu from '../Components/Menu';
import { Link, Redirect } from 'react-router-dom';
import { Container, Button, Col } from 'react-bootstrap';
import { Container, Button, Navbar, Col } from 'react-bootstrap';
import styled from 'styled-components';
const Check = styled.div`
......@@ -30,7 +30,13 @@ function Change(props) {
// console.log(props)
return (
<div className="">
{(localStorage.getItem("token") !== null) ? (
<Menu />
) : (
<Menu expand="md" variant="dark">
<Navbar.Brand>회원가입</Navbar.Brand>
</Menu>
)}
<Container fluid className="p-0 vh-90">
<Check className="row justify-content-center m-0">
<Col md={4} className="pt-5">
......
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import { Redirect } from 'react-router-dom';
import axios from 'axios';
import Table from 'react-bootstrap/Table'
import { Container } from 'react-bootstrap';
......@@ -30,20 +31,31 @@ margin-top: 0.5em;
function Check(props) {
const [reserve, setReserve] = useState([]);
const [state, setState] = useState()
useEffect(() => {
getReserve();
}, [])
if (state) return <Redirect to="/" />;
function getReserve() {
axios.get(`/reserves/${props.match.params.id}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
if (res.status === 404) {
alert(res.data.error);
}
if (res.status === 419) {
alert(res.data.error);
localStorage.clear();
setState(true);
}
console.log(res.data);
setReserve(res.data);
const reserves=res.data.filter(function(item) {
return item !== '';
});
setReserve(reserves);
})
.catch(err => {
alert(err.error)
......
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import Schedule from '../Components/Schedule';
import styled from 'styled-components';
import moment from 'moment';
import "moment/locale/ko";
moment.locale("ko", {
week: {
dow: 1
}
});
const Drop = styled.div`
& button {
border solid 1px;
}
`
const Tab = styled.ul`
& a, a:hover, a:active {
color: black;
}
`
import { Redirect } from 'react-router-dom';
import Tabs from 'react-bootstrap/Tabs';
import axios from 'axios';
import Tab from 'react-bootstrap/Tab';
function Home() {
const [show, setShow] = useState(false);
const [weeks, setWeeks] = useState([]);
const [days, setDays] = useState([]);
const [sendDate, setSendDate] = useState(null);
const [key, setKey] = useState('9-116');
const [state, setState] = useState()
useEffect(() => {
Dateform();
tcheck();
}, []);
function Dateform() {
let today = moment();
let weeks = [];
let dates = [];
let sendDates = [];
if (state) return <Redirect to="/" />;
for (let i = 0; i < 6; i++) {
if (i !== 0) {
today.add(7, 'd');
function tcheck() {
axios.get(`/users/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
localStorage.clear();
setState(true);
}
let date = { start: null, end: null };
date.start = today.startOf('week').format("MMM Do");
date.end = today.endOf('week').weekday(4).format("MMM Do");
dates.push(date);
const week = date.start + " ~ " + date.end;
weeks.push(week);
let sendDate = today.startOf('week').format("YYYY-MM-DD");
sendDates.push(sendDate);
};
setWeeks([...weeks])
setDays([...sendDates])
};
function choose(e, index) {
setShow(true)
setSendDate(days[index])
}).catch(err => {
alert(err.error)
});
}
return (
......@@ -75,39 +43,17 @@ function Home() {
<li>주말: 이용 불가</li>
</ul>
</p>
<Drop className="row dropdown mt-1 mb-2">
<button className="btn btn-lg dropdown-toggle mx-auto col-5" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
기간을 선택해주십시오.
</button>
<div className="dropdown-menu col-5" aria-labelledby="dropdownMenuButton">
{weeks.map((week, index) => (
<a className="dropdown-item" id={index} onClick={(e) => choose(e, index)}>{week}</a>
))}
</div>
</Drop>
<Tab className="nav nav-tabs nav-justified mt-4" id="myTab" role="tablist" style={show ? {} : { display: "none" }}>
<li className="nav-item">
<a className="nav-link active" id="7-tab" data-toggle="tab" href="#tab-7" role="tab" aria-controls="7" aria-selected="true"> 7-223 </a>
</li>
<li className="nav-item">
<a className="nav-link" id="9-tab" data-toggle="tab" href="#tab-9" role="tab" aria-controls="9" aria-selected="false"> 9-116 </a>
</li>
<li className="nav-item">
<a className="nav-link" id="25-tab" data-toggle="tab" href="#tab-25" role="tab" aria-controls="25" aria-selected="false"> 25-307 </a>
</li>
<Tabs defaultActiveKey="9-116" id="uncontrolled-tab-example" onSelect={(k) => setKey(k)}>
<Tab eventKey="9-116" title="9-116">
<Schedule room={key} />
</Tab>
<div className="tab-content row justify-content-center" id="myTabContent" style={show ? {} : { display: "none" }}>
<div className="tab-pane fade show active col-md-11 col-12" id="tab-7" role="tabpanel" aria-labelledby="7-tab">
<Schedule day={sendDate} />
</div>
<div className="tab-pane fade col-md-11 col-12" id="tab-9" role="tabpanel" aria-labelledby="9-tab">
<Schedule day={sendDate} />
</div>
<div className="tab-pane fade col-md-11 col-12" id="tab-25" role="tabpanel" aria-labelledby="25-tab">
<Schedule day={sendDate} />
</div>
</div>
<Tab eventKey="7-234" title="7-234">
<Schedule room={key} />
</Tab>
<Tab eventKey="25-101" title="25-101">
<Schedule room={key} />
</Tab>
</Tabs>
<h3>유의사항</h3>
<p>
<ul>
......
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect } from 'react';
import Menu from '../Components/Menu';
import axios from 'axios';
import { Link } from 'react-router-dom';
import { Link, Redirect } from 'react-router-dom';
import { Container, Row, Col, Card, Accordion, Button } from 'react-bootstrap';
function Notice() {
const [show, setShow] = useState(false);
const [notices, setNotices] = useState([]);
const [user, setUser] = useState({ role: "" })
const [state, setState] = useState()
useEffect(() => {
acheck();
getNotice();
}, []);
if (state) return <Redirect to="/" />;
function acheck() {
axios.get(`/users/${localStorage.getItem('_id')}`)
axios.get(`/users/${localStorage.getItem('_id')}`, {
headers: { authorization: localStorage.getItem('token') },
})
.then(res => {
if (res.status !== 201) {
alert(res.data.error);
localStorage.clear();
setState(true);
}
if (res.data.role == "admin") {
setUser(res.data)
}
......@@ -49,6 +60,7 @@ function Notice() {
alert(err.error)
});
}
return (
<div>
<style type="text/css">
......@@ -73,11 +85,12 @@ function Notice() {
<Accordion>
{notices.map((notice, index) =>
<Card>
<Card.Header>
<Accordion.Toggle as={Button} variant="link hidden" eventKey={index + 1}>{notice.notice_title} <span className="text-right">{dateForm(notice.post_date)}</span></Accordion.Toggle>
<Card.Header className="d-flex justify-content-between">
<Accordion.Toggle as={Button} variant="link" eventKey={index + 1} className={"d-inline-block " + (show ? "text-wrap" : "text-truncate")} onClick={() => setShow(!show)}>{notice.notice_title}</Accordion.Toggle>
<span className="d-flex align-items-center" style={{ width: "50%" }}>{dateForm(notice.post_date)}</span>
</Card.Header>
<Accordion.Collapse eventKey={index + 1}>
<Card.Body>{notice.notice_content}</Card.Body>
<Card.Body><pre>{notice.notice_content}</pre></Card.Body>
</Accordion.Collapse>
</Card>)}
</Accordion>
......
......@@ -67,11 +67,8 @@ function Write() {
<div className="form-group ">
{/* mb-4 */}
<div className={touched.name && errors.name ? "text-danger" : ""}>내용</div>
<input className={(touched.name && errors.name ? 'form-control is-invalid' : "form-control")}
type="text"
content="content"
{...getFieldProps('content')}
placeholder="내용" />
<Field as="textarea" rows={8} cols={175}
{...getFieldProps('content')} />
</div>
<button type="submit" className="btn btn-dark" disabled={isSubmitting}>공지 등록</button>
</form>
......
......@@ -37,7 +37,7 @@ router.post('/', function (req, res, next) {
const token = jwt.sign({
id: users.id,
}, process.env.JWT_SECRET, {
expiresIn: '1m',
expiresIn: '1h',
});
return res.status(201).json({
token,
......
......@@ -17,7 +17,8 @@ router.post('/', function (req, res, next) {
room: req.body.room,
reason: req.body.reason,
students: req.body.students,
approve: req.body.approve,
approve: true,
check: true,
num: req.body.students.length + 1,
});
......@@ -38,8 +39,8 @@ router.post('/', function (req, res, next) {
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)) ?
(strt >= new Date(item.start) && strt < new Date(item.end)) ||
(endt > new Date(item.start) && endt <= new Date(item.end)) ?
"item" :
null
))
......@@ -70,15 +71,25 @@ router.get('/room/:room', function (req, res, next) {
})
// router.get('/:_id', verifyToken, function (req, res, next) {
router.get('/:_id', function (req, res, next) {
router.get('/:_id', verifyToken, function (req, res, next) {
console.log('/reserves get req.params', req.params)
Reserve.find({ user: req.params._id }, function (err, reserve) {
if (err) return res.status(500).json({ error: err });
res.status(201).json(reserve);
// console.log(reserve, Date.now())
const reserves = reserve.map(item => (
new Date(item.end) >= Date.now() ? item : ""
));
if (!reserves) {
console.log("no신청")
res.status(404).json({error: "신청내역이 없습니다."})
}
console.log("reserves",reserves)
res.status(201).json(reserves);
})
});
router.get('/admin/:_id', function (req, res, next) {
router.get('/admin/:_id', verifyToken, function (req, res, next) {
console.log('/reserves/admin get req.params', req.params)
Reserve.find({ approve: false }).populate('user').exec(function (err, reserve) {
if (err) return res.status(500).json({ error: err });
......
......@@ -34,7 +34,7 @@ router.post('/', function (req, res, next) {
})
});
router.get('/:_id', function (req, res, next) {
router.get('/:_id', verifyToken, function (req, res, next) {
console.log('/users get req.params', req.params)
User.findOne({ _id: req.params._id }, function (err, user) {
if (err) return res.status(500).json({ error: err });
......
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