Skip to content

Commit c0d8e4a

Browse files
committed
OpenConceptLab/ocl_issues#1617 | user profile and edit styles | copy api token
1 parent 7633e30 commit c0d8e4a

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

src/components/users/UserEdit.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const UserEdit = () => {
88
const height = 'calc(100vh - 100px)'
99
return (
1010
<div className='col-xs-12 padding-0'>
11-
<div className='col-xs-3' style={{height: height, padding: '24px', maxWidth: '20%'}}>
11+
<div className='col-xs-3' style={{height: height, padding: '24px 24px 24px 8px', maxWidth: '20%'}}>
1212
<UserProfile user={user} />
1313
</div>
1414
<div className='col-xs-10 padding-0' style={{height: height, maxWidth: '80%'}}>

src/components/users/UserForm.jsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22
import { useTranslation } from 'react-i18next'
33
import { useHistory } from 'react-router-dom';
4-
import Button from '@mui/material/Button'
54
import Typography from '@mui/material/Typography'
65
import InputAdornment from '@mui/material/InputAdornment'
76
import TextField from '@mui/material/TextField'
@@ -11,6 +10,7 @@ import { OperationsContext } from '../app/LayoutContext';
1110
import { LANGUAGES } from '../../common/constants';
1211
import { refreshCurrentUserCache, getCurrentUser, getResetPasswordURL } from '../../common/utils'
1312
import Link from '../common/Link'
13+
import Button from '../common/Button'
1414

1515
const UserForm = ({ user }) => {
1616
const sessionUser = getCurrentUser()
@@ -179,9 +179,7 @@ const UserForm = ({ user }) => {
179179
</TextField>
180180
</div>
181181
</div>
182-
<Button onClick={onSubmit} variant='contained' color='primary' sx={{textTransform: 'none'}}>
183-
{t('common.save')}
184-
</Button>
182+
<Button onClick={onSubmit} label={t('common.save')} color='primary' sx={{margin: '16px 0 24px 0'}} />
185183
</form>
186184
</div>
187185
)

src/components/users/UserHome.jsx

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import React from 'react';
22
import { useParams } from 'react-router-dom'
3-
import { getCurrentUser, canEditUser } from '../../common/utils'
3+
import { getCurrentUser } from '../../common/utils'
44
import UserProfile from './UserProfile'
55
import UserRepositories from './UserRepositories';
66
import APIService from '../../services/APIService'
77

88

99
const UserHome = () => {
1010
const [user, setUser] = React.useState({})
11-
const [apiToken, setApiToken] = React.useState()
1211
const params = useParams()
1312
const height = 'calc(100vh - 100px)'
1413

1514
const fetchUser = () => {
1615
const currentUser = getCurrentUser()
1716
if(params.user === currentUser?.username) {
1817
setUser(currentUser)
19-
fetchAPIToken()
2018
} else {
2119
APIService.users(params.user).get(null, null, {includeSubscribedOrgs: true}).then(response => {
22-
if(response.status === 200) {
20+
if(response.status === 200)
2321
setUser(response.data)
24-
fetchAPIToken()
25-
}
2622
else if(response.status)
2723
window.location.hash = '#/' + response.status
2824
else if(response.detail === 'Not found.')
@@ -31,21 +27,15 @@ const UserHome = () => {
3127
}
3228
}
3329

34-
const fetchAPIToken = () => {
35-
if(canEditUser(params.user) && !apiToken)
36-
APIService.users().appendToUrl('api-token/').get().then(response => setApiToken(response?.data?.token))
37-
}
38-
3930
React.useEffect(() => {
40-
setApiToken(undefined)
4131
fetchUser()
4232
}, [params.user])
4333

4434

4535
return (
4636
<div className='col-xs-12 padding-0'>
4737
<div className='col-xs-3' style={{height: height, padding: '24px 24px 24px 8px', maxWidth: '20%'}}>
48-
<UserProfile user={user} apiToken={apiToken} />
38+
<UserProfile user={user} />
4939
</div>
5040
<div className='col-xs-10 padding-0' style={{backgroundColor: '#FFF', borderRadius: '10px', height: height, maxWidth: '80%'}}>
5141
{

src/components/users/UserProfile.jsx

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { useParams } from 'react-router-dom'
23
import { useTranslation } from 'react-i18next'
34
import Typography from '@mui/material/Typography'
45
import List from '@mui/material/List';
@@ -16,6 +17,7 @@ import UserIcon from './UserIcon';
1617
import OrgIcon from '../orgs/OrgIcon';
1718
import Link from '../common/Link'
1819
import { OperationsContext } from '../app/LayoutContext';
20+
import APIService from '../../services/APIService';
1921

2022

2123
const UserProperty = ({icon, value, label}) => {
@@ -38,15 +40,28 @@ const UserProperty = ({icon, value, label}) => {
3840
}
3941

4042

41-
const UserProfile = ({ user, apiToken }) => {
43+
const UserProfile = ({ user }) => {
4244
const { t } = useTranslation()
45+
const params = useParams()
46+
const [apiToken, setApiToken] = React.useState(undefined)
4347
const { setAlert } = React.useContext(OperationsContext);
4448
const iconStyle = {fontSize: '24px', color: 'secondary.main'}
4549
const userOrgs = getCurrentUserOrgs()
4650
const onCopyToken = () => {
4751
copyToClipboard(apiToken)
4852
setAlert({message: t('user.copy_token_success'), severity: 'success', duration: 2000})
4953
}
54+
const canEdit = canEditUser(params?.user)
55+
56+
const fetchAPIToken = () => {
57+
if(canEdit && !apiToken)
58+
APIService.users().appendToUrl('api-token/').get().then(response => setApiToken(response?.data?.token))
59+
}
60+
61+
React.useEffect(() => {
62+
fetchAPIToken()
63+
}, [])
64+
5065

5166
return (
5267
<React.Fragment>
@@ -85,7 +100,7 @@ const UserProfile = ({ user, apiToken }) => {
85100
Joined {formatDate(user?.date_joined)}
86101
</Typography>
87102
{
88-
user?.username && canEditUser(user.username) &&
103+
canEdit &&
89104
<div style={{paddingLeft: '12px'}}>
90105
<Link
91106
label={t('user.edit_my_profile')}

0 commit comments

Comments
 (0)