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