Menu.js 2.16 KB
Newer Older
Ha YeaJin's avatar
pages    
Ha YeaJin committed
1
import React, { useState, useEffect } from 'react';
CHAERIN KIM's avatar
CHAERIN KIM committed
2
import { Link, Redirect } from 'react-router-dom';
Ha YeaJin's avatar
pages    
Ha YeaJin committed
3
4
5
import styled from 'styled-components';

const Nav = styled.nav`
Ha YeaJin's avatar
Ha YeaJin committed
6
    background-color: #7B031D;
7
    height: 6vh;
Ha YeaJin's avatar
Ha YeaJin committed
8
9
10
11

    a {
        color: #ffffff;
    }
Ha YeaJin's avatar
pages    
Ha YeaJin committed
12
13
14
`

function Menu() {
CHAERIN KIM's avatar
CHAERIN KIM committed
15
    const [state, setState] = useState()
CHAERIN KIM's avatar
CHAERIN KIM committed
16
    const name = localStorage.getItem('name');
Ha YeaJin's avatar
Ha YeaJin committed
17

CHAERIN KIM's avatar
CHAERIN KIM committed
18
19
20
    if (state) return <Redirect to="/" />;

    function logout() {
CHAERIN KIM's avatar
CHAERIN KIM committed
21
        localStorage.clear();
CHAERIN KIM's avatar
CHAERIN KIM committed
22
        alert("로그아웃 되었습니다.");
CHAERIN KIM's avatar
CHAERIN KIM committed
23
24
25
        setState(true);
    }

Ha YeaJin's avatar
pages    
Ha YeaJin committed
26
27
    return (
        <Nav className="navbar sticky-top navbar-expand-md">
Ha YeaJin's avatar
Ha YeaJin committed
28
            <a class="navbar-brand" href="#">대관 서비스</a>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
29
30
31
            <button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar" aria-controls="collapsibleNavbar">
                <span className="navbar-toggler-icon"></span>
            </button>
CHAERIN KIM's avatar
CHAERIN KIM committed
32
            <div className="collapse navbar-collapse justify-content-between" id="collapsibleNavbar">
Ha YeaJin's avatar
pages    
Ha YeaJin committed
33
                <ul className="navbar-nav">
Ha YeaJin's avatar
Ha YeaJin committed
34
35
36
                    <li className="nav-item">
                        <Link to="/notice" className="nav-link">공지사항</Link>
                    </li>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
37
                    <li className="nav-item">
38
                        {console.log(name)}
Ha YeaJin's avatar
pages    
Ha YeaJin committed
39
40
41
42
43
44
                        <Link to="/home" className="nav-link">대관 현황</Link>
                    </li>
                    <li className="nav-item">
                        <Link to="/apply" className="nav-link">대관 신청</Link>
                    </li>
                    <li className="nav-item">
45
46
47
48
49
                        <Link to={{
                            pathname: `/check/${localStorage.getItem('_id')}`,
                            state: { id: localStorage.getItem('_id') },
                        }} className="nav-link">
                            대관 확인/취소</Link>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
50
51
                    </li>
                </ul>
CHAERIN KIM's avatar
CHAERIN KIM committed
52
                <div>
CHAERIN KIM's avatar
CHAERIN KIM committed
53
                    <div>{name} 안녕하세요.</div>
CHAERIN KIM's avatar
CHAERIN KIM committed
54
55
                    <button onClick={logout} type="button">로그아웃</button>
                </div>
Ha YeaJin's avatar
pages    
Ha YeaJin committed
56
57
58
59
60
61
            </div>
        </Nav>
    )
}

export default Menu