NoticePage.js 2.59 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';
4
import styled from 'styled-components';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
5
6

function Notice() {
7
8
9
10
11
12
    const [notices, setNotices] = useState([]);

    useEffect(() => {
        getNotice();
    }, []);

13
14
15
16
17
18
19
20
21
22
23
24
25
    function dateForm(day) {
        const post_day = new Date(day);
        let year = post_day.getFullYear();
        let month = post_day.getMonth() + 1;
        let date = post_day.getDate();

        month = month < 10 ? '0' + month : month;
        date = date < 10 ? '0' + date : date;

        const new_date = year + "-" + month + "-" + date;
        return new_date
    }

26
27
28
29
30
31
32
33
34
35
36
37
38
    function getNotice() {
        axios.get(`/notices`)
            .then(res => {
                if (res.status !== 201) {
                    alert(res.data.error);
                }
                console.log(res.data);
                setNotices(res.data);
            })
            .catch(err => {
                alert(err.error)
            });
    }
Ha YeaJin's avatar
pages    
Ha YeaJin committed
39
40
41
    return (
        <div>
            <Menu />
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
            <div className="container-fluid">
                <div className="row justify-content-center vw-100 vh-90">
                    <div className="col-md-7 col-12">

                        <h2 className="p-3 border-bottom">공지사항</h2>

                        <div id="accordion w-90 pt-1">
                            {notices.map((notice, index) =>
                                <div className="card">
                                    <div className="card-header collapsed card-link w-100 row m-0 p-1" id={"Hnotice_" + index} data-toggle="collapse" href={"#notice_" + index}>
                                        <div>
                                            <div className="col-6 p-0">{notice.notice_title}</div>
                                            <div className="col-3 p-0 text-center">{notice.notice_author}</div>
                                            <div className="col-3 p-0 text-right">{dateForm(notice.post_date)}</div>
                                        </div>
                                    </div>
                                    <div id={"notice_" + index} aria-labelledby={"Hnotice_" + index} className="collapse" data-parent="#accordion">
                                        <div className="card-body">{notice.notice_content}</div>
                                    </div>
                                </div>
                            )}
                        </div>

65
                    </div>
66
67
                </div >
            </div >
Ha YeaJin's avatar
pages    
Ha YeaJin committed
68
69
70
71
        </div>
    )
}

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