UserInfo.js 4.76 KB
Newer Older
1
2
import React, { useState, useEffect } from 'react'
import { Row, Card, Button, Col } from 'react-bootstrap';
3
import '../App.css'
Spark's avatar
Spark committed
4
import { Link } from 'react-router-dom';
5
6
import { callUserInfo, checkCookies } from '../utils/CheckDB';
import axios from 'axios';
7
8


Spark's avatar
Spark committed
9
function UserInfo() {
Spark's avatar
Spark committed
10

11
12
    const cardstyled = {
        margin: 'auto',
Spark's avatar
Spark committed
13
        padding: '1em 0.5em 1em 0.5em',
14
15
16
17
18
19
        display: 'flex',
        justifyContent: 'center',
        width: '100%',
        borderWidth: '3px',
        borderRadius: '20px',
        borderColor: 'rgba(195, 195, 195, 0.753)',
20

Spark's avatar
Spark committed
21
22
23
        color: 'rgb(110, 189, 142)',


24
25
26
27
28
    }
    const btnstyled2 = {
        background: 'white',
        margin: 'auto',
        borderWidth: '2px',
Spark's avatar
Spark committed
29
30
        // padding: '0',
        fontSize: '0.7em',
31
32
        color: 'rgb(110, 189, 142)',
        borderColor: 'rgba(195, 195, 195, 0.753)',
Spark's avatar
Spark committed
33
34
        // borderRadius: '20px',
        width: '50%'
35
    }
Spark's avatar
Spark committed
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    const localname_doe = localStorage.getItem('name_doe')
    const localname_sgg = localStorage.getItem('name_sgg')
    const localname_emd = localStorage.getItem('name_emd')
    const localcode_emd = localStorage.getItem('code_emd')

    const [userNick, setUserNick] = useState('')
    const [createdTime, setCreatedTime] = useState('')



    useEffect(() => {
        callUserInfo().then((res) => {
            if (res !== []) {
                setUserNick(res[0]['nick_name'])
                const dateStr = res[0]['created_at'].split('T')[0].split('-')
                console.log(dateStr)
                const now = new Date();

                const year = now.getFullYear(); // 년
                const month = now.getMonth() + 1; // 월 0부터 시작
                const day = now.getDate(); // 일

                const stDate = new Date(dateStr[0], dateStr[1], dateStr[2])
                console.log(stDate)

                const endDate = new Date(year, month, day)
                console.log(endDate)

                const btMs = endDate.getTime() - stDate.getTime() // 주어진 날짜 사이의 경과 시간 (밀리 초)
                console.log(btMs / 1000)

                const btDay = btMs / (1000 * 60 * 60 * 24)
                console.log(btDay)

                setCreatedTime(btDay)
            }
            else {
                console.log('Not Logined')
            }
        })
    }, [])

79
    return (
80
81
82
83
84
85
86
87
88
89
90
91
        <Col className='text-center pt-3 pb-2 px-0'>
            <Card style={cardstyled} id='localName'>
                <Card.Title>
                    <strong>
                        {checkCookies() ?
                            <h3>
                                {`${userNick}`}
                            </h3>
                            :
                            <h3>
                                GUEST
                            </h3>
Spark's avatar
Spark committed
92
                        }
93
94
95
96
97
98
99
100
101
102
                    </strong>
                    <p style={{ fontWeight: '300', margin: '0' }}>
                        환영합니다
                    </p>
                </Card.Title>
                <hr />
                <Row style={{ alignItems: 'center', margin: 'auto', justifyContent: 'center' }}>
                    <Card.Subtitle>
                        {localname_emd ?
                            <p className='mb-2'>
103

104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
                                {`${localname_doe}`}
                                <br />
                                {`${localname_sgg}`}
                                <br />
                                {`${localname_emd}`}
                            </p>
                            :
                            <p className='mb-2'>
                                로그인  이용 가능합니다
                            </p>
                        }
                    </Card.Subtitle>
                    {checkCookies() &&
                        <Button variant='light' className='m-auto d-flex' style={btnstyled2}>
                            <Link to='/edit' className='w-100' style={{ textDecoration: 'none', color: 'rgb(110, 189, 142)' }}>
                                변경
                            </Link>
                        </Button>
Spark's avatar
Spark committed
122
                    }
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
                </Row>
                {checkCookies() &&

                    <Card.Text>
                        <hr />
                        <Row style={{ color: 'black' }}>
                            <p style={{ fontWeight: '300', margin: '0' }}>
                                환경을 향한 노력
                            </p>
                            <h3 style={{ fontWeight: '300', color: '#2b90d9',  margin: '0' }}>
                                {createdTime}일차
                            </h3>

                        </Row>

                    </Card.Text>
                }
            </Card>
        </Col>
142
143
    )
}
Spark's avatar
Spark committed
144
export default UserInfo;