NoticePage.js 2.75 KB
Newer Older
1
import React, { useState, useEffect, useRef } 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
    const [notices, setNotices] = useState([]);

Ha YeaJin's avatar
Ha YeaJin committed
12
13
    // const [show, setShow] = useState(false);

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

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

30
31
32
33
    function getNotice() {
        axios.get(`/notices`)
            .then(res => {
                if (res.status !== 201) {
Ha YeaJin's avatar
Ha YeaJin committed
34
                    // alert(res.data.error);
35
36
37
38
39
40
41
                }
                setNotices(res.data);
            })
            .catch(err => {
                alert(err.error)
            });
    }
Ha YeaJin's avatar
pages    
Ha YeaJin committed
42
43
44
    return (
        <div>
            <Menu />
Ha YeaJin's avatar
Ha YeaJin committed
45
46
47
            <Container fluid>
                <Row className="justify-content-center vw-100 vh-90">
                    <Col md={7}>
Ha YeaJin's avatar
Ha YeaJin committed
48
49
                        <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
50
                        <Accordion>
Ha YeaJin's avatar
Ha YeaJin committed
51
52
53
54
55
56
                            {notices.map((notice, index) => <CARD card_index={index} title={notice.notice_title} date={notice.post_date} content={notice.notice_content} />
                            )}
                            {/* <Card>
                                    <Card.Header className="d-flex justify-content-space-between">
                                        <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>
Ha YeaJin's avatar
Ha YeaJin committed
57
58
                                    </Card.Header>
                                    <Accordion.Collapse eventKey={index + 1}>
Ha YeaJin's avatar
Ha YeaJin committed
59
                                        <Card.Body><pre>{notice.notice_content}</pre></Card.Body>
Ha YeaJin's avatar
Ha YeaJin committed
60
                                    </Accordion.Collapse>
Ha YeaJin's avatar
Ha YeaJin committed
61
62
                                </Card> */}

Ha YeaJin's avatar
Ha YeaJin committed
63
64
65
66
                        </Accordion>
                    </Col>
                </Row>
            </Container>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
67
68
69
70
        </div>
    )
}

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