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

reload

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