-
Notifications
You must be signed in to change notification settings - Fork 12
/
UserHomeDetails.jsx
74 lines (68 loc) · 2.42 KB
/
UserHomeDetails.jsx
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
import React from 'react';
import { Divider, CircularProgress } from '@material-ui/core';
import { Person as PersonIcon } from '@material-ui/icons';
import { includes, startCase, get } from 'lodash';
import APIService from '../../services/APIService';
import { formatDate, currentUserToken} from '../../common/utils';
import HeaderLogo from '../common/HeaderLogo';
const UserHomeDetails = ({ user, isLoading }) => {
const [logoURL, setLogoURL] = React.useState(user.logo_url)
React.useEffect(() => {
if(user.logo_url)
setLogoURL(user.logo_url)
}, [user.logo_url])
let name = user.name || '';
if(includes(['none none', '- -'], name.trim()))
name = '';
const onLogoUpload = (base64, name) => {
APIService.new().overrideURL(user.url).appendToUrl('logo/')
.post({base64: base64, name: name})
.then(response => {
if(get(response, 'status') === 200)
setLogoURL(get(response, 'data.logo_url', logoURL))
})
}
const token = currentUserToken();
return (
<div className="col-md-12 no-side-padding">
{
isLoading ?
<CircularProgress color='primary' style={{marginTop: '50px', marginLeft: '50px'}} /> :
<div className="col-md-12 no-side-padding">
<div className='home-icon'>
<HeaderLogo
isCircle={true}
logoURL={logoURL}
onUpload={onLogoUpload}
defaultIcon={<PersonIcon style={{width: '120px', height: '120px'}} />}
/>
</div>
<h2>
{startCase(name)}
<br />
<small>{user.username}</small>
</h2>
<Divider style={{width: '100%'}} />
<p><strong>Company:</strong><br />{user.company || 'N/A'}</p>
<p><strong>Location:</strong><br />{user.location || 'N/A'}</p>
{
user.website &&
<p>
<strong>Website:</strong>
<br />
<a href={user.website} target="_blank" rel="noopener noreferrer">{user.website}</a>
</p>
}
<p><strong>Email:</strong><br />{user.email}</p>
<p><strong>Joined:</strong><br />{formatDate(user.created_on)}</p>
<Divider style={{width: '100%'}} />
{
token &&
<p><strong>API Token:</strong><br />{token}</p>
}
</div>
}
</div>
)
}
export default UserHomeDetails;