-
Notifications
You must be signed in to change notification settings - Fork 143
/
userCard.js
127 lines (115 loc) · 3.48 KB
/
userCard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import COLORS from '../utils/colors'
import { card as cardStyle } from '../utils/styles'
const Detail = ({ label, data }) => (
<div style={{ fontSize: '.8rem' }}>
<label style={{ color: COLORS.lightColor, paddingRight: '.25rem' }}>{label} :</label>
<span>{data}</span>
</div>
)
const AccessToken = ({ token }) => {
const codeStyle = {
fontFamily: 'monospace',
wordWrap: 'break-word',
margin: '.5em 0',
padding: '.5em',
fontSize: '85%',
backgroundColor: 'rgba(27,31,35,0.05)',
borderRadius: '3px'
}
return (
<div style={{ fontSize: '.8rem' }}>
<label style={{ color: COLORS.lightColor, paddingRight: '.25rem' }}>Access token :</label>
<div style={codeStyle}>{token}</div>
</div>
)
}
export default class UserCard extends Component {
static propTypes = {
user: PropTypes.shape({
_profile: PropTypes.object,
_token: PropTypes.object
}),
logout: PropTypes.func
}
render () {
const { user: { _profile, _token }, logout } = this.props
let expiration = 'unknown'
if (_token.expiresAt === Infinity) {
expiration = 'never/unknown (see provider doc)'
} else if (_token.expiresAt) {
const date = new Date(_token.expiresAt)
const year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
let hour = date.getHours()
let minute = date.getMinutes()
if (month < 10) month = `0${month}`
if (day < 10) day = `0${day}`
if (hour < 10) hour = `0${hour}`
if (minute < 10) minute = `0${minute}`
expiration = `${month}/${day}/${year} ${hour}:${minute}`
}
const styles = {
container: {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
textAlign: 'left'
},
avatar: {
background: COLORS.background,
boxShadow: '0 0 12px rgba(0,0,0,0.5)',
border: `5px solid ${COLORS.white}`,
borderRadius: '50%',
height: '7em',
width: '7em',
zIndex: '1'
},
content: {
...cardStyle,
marginTop: '-.75rem'
},
dataContainer: {
padding: '1.5rem 2rem'
},
id: {
fontSize: '.5rem',
margin: '-.2rem 0'
},
name: {
fontSize: '1.5rem',
marginBottom: '.5rem'
},
button: {
color: COLORS.red,
border: 'none',
width: '100%',
padding: '.5rem',
fontSize: '1em',
textTransform: 'uppercase'
}
}
const avatar = _profile.profilePicURL ||
'https://maxcdn.icons8.com/Share/icon/p1em/users//gender_neutral_user1600.png'
return (
<div style={styles.container}>
<img style={styles.avatar} src={avatar} />
<div style={styles.content}>
<div style={styles.dataContainer}>
<div style={styles.id}>ID {_profile.id}</div>
<div style={styles.name}>{_profile.name}</div>
<Detail label='Firstname' data={_profile.firstName} />
<Detail label='Lastname' data={_profile.lastName} />
<Detail label='Email' data={_profile.email} />
<Detail label='Gender' data={_profile.gender} />
<Detail label='Expiration' data={expiration} />
<AccessToken token={_token.accessToken} />
</div>
<button style={styles.button} onClick={logout}>Logout</button>
</div>
</div>
)
}
}