Commit 171d5080 authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

reload

parent 1e75d62c
...@@ -13,7 +13,7 @@ const Text = styled(Card.Body)` ...@@ -13,7 +13,7 @@ const Text = styled(Card.Body)`
} }
` `
function Notice({ card_id, card_index, title, date, content, admin }) { function Notice({ card_id, card_index, title, date, content, admin, remove }) {
function ContextAwareToggle({ children, eventKey, callback }) { function ContextAwareToggle({ children, eventKey, callback }) {
const currentEventKey = useContext(AccordionContext); const currentEventKey = useContext(AccordionContext);
...@@ -46,18 +46,6 @@ function Notice({ card_id, card_index, title, date, content, admin }) { ...@@ -46,18 +46,6 @@ function Notice({ card_id, card_index, title, date, content, admin }) {
return new_date return new_date
} }
function remove (card_id) {
axios.delete(`/api/notices/${card_id}`)
.then(res => {
if (res.status === 404) return alert(res.data.error)
alert("삭제되었습니다!");
window.location.reload();
})
.catch(err => {
alert(err.error)
});
}
return ( return (
<Card className="w-100"> <Card className="w-100">
<Card.Header className="row flex-row py-3"> <Card.Header className="row flex-row py-3">
......
...@@ -10,6 +10,7 @@ function Apply(props) { ...@@ -10,6 +10,7 @@ function Apply(props) {
const [state, setState] = useState({ok:""}); const [state, setState] = useState({ok:""});
const [user, setUser] = useState({ name: "" }); const [user, setUser] = useState({ name: "" });
const [room_Num, setRoom_Num] = useState({ "9-116": 5, "7-234": 7, "25-101": 10 }); const [room_Num, setRoom_Num] = useState({ "9-116": 5, "7-234": 7, "25-101": 10 });
const [values, setValues] = useState()
useEffect(() => { useEffect(() => {
getUser(); getUser();
...@@ -96,7 +97,7 @@ function Apply(props) { ...@@ -96,7 +97,7 @@ function Apply(props) {
reason: Yup.string() reason: Yup.string()
.required('대관목적을 입력해주세요.'), .required('대관목적을 입력해주세요.'),
})} })}
onSubmit={(values, { setSubmitting }) => { onSubmit={(values, { setSubmitting, resetForm }) => {
addRoomInfo(values); addRoomInfo(values);
axios({ axios({
method: 'post', method: 'post',
...@@ -105,7 +106,8 @@ function Apply(props) { ...@@ -105,7 +106,8 @@ function Apply(props) {
}).then(res => { }).then(res => {
if (res.status === 404) { if (res.status === 404) {
alert(res.data.error) alert(res.data.error)
return window.location.reload(); resetForm({})
return
} }
alert("신청이 완료되었습니다!"); alert("신청이 완료되었습니다!");
setState({ok:"ok"}); setState({ok:"ok"});
......
...@@ -35,6 +35,19 @@ function Notice() { ...@@ -35,6 +35,19 @@ function Notice() {
}); });
} }
function remove (card_id) {
axios.delete(`/api/notices/${card_id}`)
.then(res => {
if (res.status === 404) return alert(res.data.error)
alert("삭제되었습니다!");
getNotice();
})
.catch(err => {
alert(err.error)
});
}
function getNotice() { function getNotice() {
axios.get(`/api/notices`) axios.get(`/api/notices`)
.then(res => { .then(res => {
...@@ -58,7 +71,7 @@ function Notice() { ...@@ -58,7 +71,7 @@ function Notice() {
<h2 className="p-3 border-bottom d-flex justify-content-between">공지사항 {user.role === "admin" ? ( <h2 className="p-3 border-bottom d-flex justify-content-between">공지사항 {user.role === "admin" ? (
<Button as={Link} to="/write"> 작성</Button>) : null}</h2> <Button as={Link} to="/write"> 작성</Button>) : null}</h2>
<Accordion> <Accordion>
{notices.map((notice, index) => <CARD card_id={notice._id} card_index={index} title={notice.notice_title} date={notice.post_date} content={notice.notice_content} admin={user.role} /> {notices.map((notice, index) => <CARD card_id={notice._id} card_index={index} title={notice.notice_title} date={notice.post_date} content={notice.notice_content} admin={user.role} remove={remove} />
)} )}
</Accordion> </Accordion>
</Col> </Col>
......
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Redirect, Switch } from 'react-router-dom'; import { BrowserRouter as Router, HashRouter, Route, Redirect, Switch } from 'react-router-dom';
import * as serviceWorker from './serviceWorker'; import * as serviceWorker from './serviceWorker';
import 'bootstrap'; import 'bootstrap';
import 'bootstrap/dist/css/bootstrap.css'; import 'bootstrap/dist/css/bootstrap.css';
...@@ -24,7 +24,7 @@ axios.defaults.validateStatus = function (status) { ...@@ -24,7 +24,7 @@ axios.defaults.validateStatus = function (status) {
} }
ReactDOM.render( ReactDOM.render(
<Router> <HashRouter>
<Switch> <Switch>
<PrivateRoute exact path="/" component={Home} /> <PrivateRoute exact path="/" component={Home} />
<Route path="/login" component={Login} /> <Route path="/login" component={Login} />
...@@ -42,7 +42,7 @@ ReactDOM.render( ...@@ -42,7 +42,7 @@ ReactDOM.render(
<Redirect path="/change/:id" to="/change" /> <Redirect path="/change/:id" to="/change" />
<Redirect path="/notice" to="/notice" /> <Redirect path="/notice" to="/notice" />
</Switch> </Switch>
</Router>, </HashRouter>,
document.getElementById('root') document.getElementById('root')
); );
......
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