NoticePage.js 1.85 KB
Newer Older
1
import React, { useState, useEffect } from 'react';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
2
import Menu from '../Components/Menu';
3
import axios from 'axios';
Ha YeaJin's avatar
Ha YeaJin committed
4
import { Link } from 'react-router-dom';
Ha YeaJin's avatar
Ha YeaJin committed
5
6
import { Container, Row, Col, Button, Accordion } from 'react-bootstrap';
import CARD from '../Components/Card';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
7
8

function Notice() {
Ha YeaJin's avatar
Ha YeaJin committed
9
    const [user, setUser] = useState({ role: "" })
10
11
12
    const [notices, setNotices] = useState([]);

    useEffect(() => {
Ha YeaJin's avatar
Ha YeaJin committed
13
        acheck();
14
15
16
        getNotice();
    }, []);

Ha YeaJin's avatar
Ha YeaJin committed
17
18
19
20
21
22
23
24
25
    function acheck() {
        axios.get(`/users/${localStorage.getItem('_id')}`)
            .then(res => {
                if (res.data.role == "admin") {
                    setUser(res.data)
                }
            }).catch(err => {
                alert(err.error)
            });
26
27
    }

28
29
30
31
    function getNotice() {
        axios.get(`/notices`)
            .then(res => {
                if (res.status !== 201) {
Ha YeaJin's avatar
Ha YeaJin committed
32
                    // alert(res.data.error);
33
34
35
36
37
38
39
                }
                setNotices(res.data);
            })
            .catch(err => {
                alert(err.error)
            });
    }
40

Ha YeaJin's avatar
pages    
Ha YeaJin committed
41
42
43
    return (
        <div>
            <Menu />
Ha YeaJin's avatar
Ha YeaJin committed
44
45
46
            <Container fluid>
                <Row className="justify-content-center vw-100 vh-90">
                    <Col md={7}>
Ha YeaJin's avatar
Ha YeaJin committed
47
48
                        <h2 className="p-3 border-bottom d-flex justify-content-between">공지사항 {user.role === "admin" ? (
                            <Button as={Link} to="/write"> 작성</Button>) : null}</h2>
Ha YeaJin's avatar
Ha YeaJin committed
49
                        <Accordion>
Ha YeaJin's avatar
Ha YeaJin committed
50
51
                            {notices.map((notice, index) => <CARD card_index={index} title={notice.notice_title} date={notice.post_date} content={notice.notice_content} />
                            )}
Ha YeaJin's avatar
Ha YeaJin committed
52
53
54
55
                        </Accordion>
                    </Col>
                </Row>
            </Container>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
56
57
58
59
        </div>
    )
}

Lee Jin Ju's avatar
Lee Jin Ju committed
60
export default Notice;