MainLayer.js 4.25 KB
Newer Older
Spark's avatar
Spark committed
1
2
import React, { useEffect, useState } from 'react'
import { Button, Image, Row, ButtonGroup, Form, Col } from 'react-bootstrap';
Spark's avatar
Spark committed
3
import { Link } from 'react-router-dom';
Spark's avatar
layout    
Spark committed
4
import '../App.css'
Spark's avatar
Spark committed
5
import UserInfo from './UserInfo';
Spark's avatar
client    
Spark committed
6
import { kakaoLogout } from '../utils/Oauth';
Spark's avatar
Spark committed
7
import axios from 'axios';
Spark's avatar
Spark committed
8
import { Swal } from 'sweetalert2';
9

Spark's avatar
layout    
Spark committed
10
11
12
13
14
15
16

function MainLayer() {

    const boxstyled = {
        border: 'solid',
        color: 'rgba(195, 195, 195, 0.753)',
        borderRadius: '20px',
17
        borderWidth: '3px',
Spark's avatar
layout    
Spark committed
18
19
        width: '100%',
        backgroundSize: 'contain',
20
        textDecorationColor: 'none'
Spark's avatar
layout    
Spark committed
21
22
23
24
    }

    const btnstyled = {
        background: 'rgb(110, 189, 142)',
Spark's avatar
Spark committed
25
26
        margin: 'auto',
        marginBottom: '0.5em',
Spark's avatar
layout    
Spark committed
27
28
        display: 'flex',
        justifyContent: 'center',
Spark's avatar
Spark committed
29
        width: '100%',
Spark's avatar
layout    
Spark committed
30
31
32
        borderWidth: '2px',
        borderColor: 'rgba(195, 195, 195, 0.753)',
        borderRadius: '20px',
33
34
        textDecorationColor: 'none',
        color: 'white'
Spark's avatar
layout    
Spark committed
35
36
    }

Spark's avatar
Spark committed
37
38
39
    const acctoken_cookies = document.cookie.split('=')[1];
    // console.log(acctoken_cookies)

Spark's avatar
Spark committed
40
    const logined = localStorage.getItem('nickname')
Spark's avatar
Spark committed
41
42
43
44
45
46
47
    const [airUsing, setAirUsing] = useState(false)

    function aircondiCheck() {
        setAirUsing(!airUsing)
        localStorage.setItem('using-aircondition', !airUsing);
    }

Spark's avatar
Spark committed
48
49
50
51
52
53
54
55
56
57
    useEffect(() => {
        const airUsingLocal = localStorage.getItem('using-aircondition')
        if (airUsingLocal === 'true') {
            return setAirUsing(true)
        }
        else {
            return setAirUsing(false)
        }
    });

Spark's avatar
Spark committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    var deleteCookie = function (name) {
        document.cookie = name + '=; expires=Thu, 01 Jan 1999 00:00:10 GMT;';
        Swal.fire({
            title: '로그아웃 성공!',
            text: '🙏 안녕히 가세요 🙏',
            icon: 'warning',
            customClass: 'swal-wide',
            confirmButtonText: '확인',
        }).then((res) => {
            if (res.isConfirmed) {
                window.location.replace('/')
            }
            else {
                window.location.replace('/')
            }
        })
    }


Spark's avatar
layout    
Spark committed
77
    return (
Spark's avatar
Spark committed
78
        <Col>
Spark's avatar
Spark committed
79
80
            <Row className='d-flex align-items-center m-auto w-100 p-0'>
                <Link to='/' className='p-0 m-auto'>
81
82
                    <Image src='/images/EUE11.jpg' alt='EUE' style={boxstyled} />
                </Link>
Spark's avatar
layout    
Spark committed
83
84
            </Row>

85
            <Row className='m-auto d-flex justify-content-center w-100'>
Spark's avatar
Spark committed
86
                <UserInfo />
87
            </Row>
Spark's avatar
Spark committed
88

Spark's avatar
Spark committed
89
            {acctoken_cookies &&
Spark's avatar
Spark committed
90
91
92
93
                <Form
                    key='checkbox' className="d-flex  justify-content-center w-100" style={{ flexDirection: 'row-reverse' }}>
                    <Form.Check
                        type='switch'
Spark's avatar
Spark committed
94
                        id='airconditioner'
Spark's avatar
Spark committed
95
96
97
98
99
100
                        label='에어컨 사용중'
                        onChange={aircondiCheck}
                        checked={airUsing}
                    />
                </Form>
            }
Spark's avatar
Spark committed
101

102
103
            <Row className='d-flex justify-content-center align-items-center my-2 mx-auto w-100'>
                <ButtonGroup vertical className='m-auto' style={{ width: '100%', flexDirection: 'column' }}>
Spark's avatar
Spark committed
104
                    {acctoken_cookies ?
Spark's avatar
Spark committed
105
                        //true
Spark's avatar
Spark committed
106
                        <Button variant='light' style={btnstyled} onClick={kakaoLogout || deleteCookie('acs_token')}>
107
108
109
                            로그아웃
                        </Button>
                        :
Spark's avatar
Spark committed
110
                        //false
Spark's avatar
Spark committed
111
112
113
114
                        <Button variant='light' style={btnstyled}>
                            <Link to='/login' id='btnlink'>
                                로그인
                            </Link>
115
116
                        </Button>
                    }
Spark's avatar
Spark committed
117
                    {!acctoken_cookies &&
Spark's avatar
Spark committed
118
119
120
121
122
123
                        <Button variant='light' style={btnstyled}>
                            <Link to='/signup' id='btnlink'>
                                회원가입
                            </Link>
                        </Button>
                    }
Spark's avatar
Spark committed
124

Spark's avatar
layout    
Spark committed
125
126
                </ButtonGroup>
            </Row>
127
128
129
            <Row className='m-auto justify-content-center w-100' id='contour'>
                |
            </Row>
Spark's avatar
Spark committed
130
        </Col>
Spark's avatar
layout    
Spark committed
131
132
133
134
    );
}

export default MainLayer