Commit 1e99a1fc authored by Kim, Subin's avatar Kim, Subin
Browse files

내꺼

parent 3ef60774
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 } from 'react-router-dom';
import { Container, Row, Col, Card, Navbar, 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 [a ,setA ] = useState([]);
useEffect(() => { useEffect(() => {
acheck();
getNotice(); getNotice();
}, []); }, []);
function acheck() {
axios.get(`/users/${localStorage.getItem('_id')}`)
.then(res => {
if (res.data.role == "admin") {
setUser(res.data)
}
}).catch(err => {
alert(err.error)
});
}
function dateForm(day) { function dateForm(day) {
const post_day = new Date(day); const post_day = new Date(day);
let year = post_day.getFullYear(); let year = post_day.getFullYear();
...@@ -36,27 +51,27 @@ function Notice() { ...@@ -36,27 +51,27 @@ function Notice() {
alert(err.error) alert(err.error)
}); });
} }
return ( return (
<div> <div>
{(localStorage.getItem("token") !== null) ? ( <Menu />
<Menu />
) : (
<Menu expand="md" variant="dark">
<Navbar.Brand>회원가입</Navbar.Brand>
</Menu>
)}
<Container fluid> <Container fluid>
<Row className="justify-content-center vw-100 vh-90"> <Row className="justify-content-center vw-100 vh-90">
<Col md={7}> <Col md={7}>
<h2 className="p-3 border-bottom">공지사항 <Link to="/write"> 작성</Link></h2> <div className="px-3 pt-3 mb-3 border-bottom d-flex justify-content-between align-items-end">
<h2>공지사항</h2>
{user.role === "admin" ? (
<Link to="/write"> 작성</Link>) : null}
</div>
<Accordion> <Accordion>
{notices.map((notice, index) => {notices.map((notice, index) =>
<Card> <Card>
<Card.Header> <Card.Header className="d-flex justify-content-space-between">
<Accordion.Toggle as={Button} variant="link" 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>
......
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