MainLayer.js 4.1 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';
8
9
import { callUserInfo, deleteCookie } from '../utils/CheckDB';
import { checkCookies } from '../utils/CheckDB';
10

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

function MainLayer() {

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

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

Spark's avatar
Spark committed
38

Spark's avatar
Spark committed
39
40
    const [airUsing, setAirUsing] = useState(false)

Spark's avatar
Spark committed
41
    useEffect(() => {
42
43
44
45
46
47
48
49
50
        callUserInfo().then((res) => {
            if (res !== []) {
                console.log(res[0])
            }
            else {
                console.log(res)
            }
        })
    }, [])
Spark's avatar
Spark committed
51

52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

    async function airChange() {
        setAirUsing(!airUsing)

        await axios.post('/api/edit-profile', { using_aircon: !airUsing })
            .then(function (response) {
                console.log('res', response);
                callUserInfo().then((res) => {
                    if (res !== []) {
                        console.log(res[0])
                    }
                    else {
                        console.log(res)
                    }
                })
            })
            .catch(function (error) {
                console.log('err', error);
            });
    }
Spark's avatar
Spark committed
72
73


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

82
            <Row className='m-auto d-flex justify-content-center w-100'>
Spark's avatar
Spark committed
83
                <UserInfo />
84
            </Row>
Spark's avatar
Spark committed
85

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

99
100
            <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' }}>
101

Spark's avatar
Spark committed
102
                    {checkCookies() ?
Spark's avatar
Spark committed
103
                        //true
104
105
                        <Button variant='light' style={btnstyled} onClick={kakaoLogout}>
                            {/*  || deleteCookie('acs_token') */}
106
107
108
                            로그아웃
                        </Button>
                        :
Spark's avatar
Spark committed
109
                        //false
Spark's avatar
Spark committed
110
111
112
113
                        <Button variant='light' style={btnstyled}>
                            <Link to='/login' id='btnlink'>
                                로그인
                            </Link>
114
115
                        </Button>
                    }
116

Spark's avatar
Spark committed
117
                    {!checkCookies() &&
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