Skip to content
This repository was archived by the owner on Mar 23, 2019. It is now read-only.

Commit 8f0b754

Browse files
authored
Add profile page (#117)
1 parent f55ca31 commit 8f0b754

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed

src/App/routes.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ export default [
8585
),
8686
path: '/quickstart',
8787
},
88+
{
89+
component: loadable(() =>
90+
import(/* webpackChunkName: 'Profile' */ '../views/Profile')
91+
),
92+
path: '/profile',
93+
},
8894
{
8995
component: loadable(() =>
9096
import(/* webpackChunkName: 'HomeOrDashboard' */ '../views/HomeOrDashboard')

src/components/Dashboard/UserMenu.jsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, Fragment } from 'react';
2+
import { Link } from 'react-router-dom';
23
import { withStyles } from '@material-ui/core/styles';
34
import Avatar from '@material-ui/core/Avatar';
45
import Menu from '@material-ui/core/Menu';
@@ -8,6 +9,8 @@ import ListItem from '@material-ui/core/ListItem';
89
import ListItemText from '@material-ui/core/ListItemText';
910
import ListItemIcon from '@material-ui/core/ListItemIcon';
1011
import AccountCircleIcon from 'mdi-react/AccountCircleIcon';
12+
import AccountIcon from 'mdi-react/AccountIcon';
13+
import HandPeaceIcon from 'mdi-react/HandPeaceIcon';
1114
import { withAuth } from '../../utils/Auth';
1215
import SignInDialog from '../SignInDialog';
1316

@@ -27,6 +30,9 @@ import SignInDialog from '../SignInDialog';
2730
icon: {
2831
fill: theme.palette.text.primary,
2932
},
33+
leftIcon: {
34+
marginRight: theme.spacing.unit,
35+
},
3036
}))
3137
@withAuth
3238
export default class UserMenu extends Component {
@@ -114,8 +120,16 @@ export default class UserMenu extends Component {
114120
anchorEl={anchorEl}
115121
open={Boolean(anchorEl)}
116122
onClose={this.handleMenuClose}>
117-
<MenuItem onClick={this.handleMenuClose}>Manage Credentials</MenuItem>
118-
<MenuItem onClick={this.handleClickSignOut}>Sign Out</MenuItem>
123+
<MenuItem title="Your Profile" component={Link} to="/profile">
124+
<AccountIcon className={classes.leftIcon} />
125+
Account
126+
</MenuItem>
127+
<MenuItem
128+
title={`Sign Out of ${process.env.APPLICATION_NAME}`}
129+
onClick={this.handleClickSignOut}>
130+
<HandPeaceIcon className={classes.leftIcon} />
131+
Sign Out
132+
</MenuItem>
119133
</Menu>
120134
</Fragment>
121135
);

src/views/Profile/index.jsx

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { hot } from 'react-hot-loader';
2+
import { Component, Fragment } from 'react';
3+
import { graphql } from 'react-apollo';
4+
import ErrorPanel from '@mozilla-frontend-infra/components/ErrorPanel';
5+
import Spinner from '@mozilla-frontend-infra/components/Spinner';
6+
import Typography from '@material-ui/core/Typography';
7+
import List from '@material-ui/core/List';
8+
import ListItem from '@material-ui/core/ListItem';
9+
import ListItemText from '@material-ui/core/ListItemText';
10+
import Dashboard from '../../components/Dashboard';
11+
import DateDistance from '../../components/DateDistance';
12+
import { withAuth } from '../../utils/Auth';
13+
import profileQuery from './profile.graphql';
14+
15+
@hot(module)
16+
@withAuth
17+
@graphql(profileQuery)
18+
export default class Profile extends Component {
19+
render() {
20+
const {
21+
classes,
22+
user,
23+
data: { currentScopes, loading, error },
24+
} = this.props;
25+
26+
return (
27+
<Dashboard title="Profile" className={classes.root}>
28+
{!currentScopes && loading && <Spinner loading />}
29+
{error && error.graphQLErrors && <ErrorPanel error={error} />}
30+
{user &&
31+
currentScopes && (
32+
<Fragment>
33+
<Typography variant="subheading">
34+
Credential Information
35+
</Typography>
36+
<List>
37+
<ListItem>
38+
<ListItemText
39+
primary="Signed In As"
40+
secondary={user.profile.displayName}
41+
/>
42+
</ListItem>
43+
<ListItem>
44+
<ListItemText
45+
primary="Certificate"
46+
secondary={
47+
user.credentials.certificate ? (
48+
<code>{user.credentials.certificate}</code>
49+
) : (
50+
'n/a'
51+
)
52+
}
53+
/>
54+
</ListItem>
55+
<ListItem>
56+
<ListItemText
57+
primary="Client ID"
58+
secondary={<code>{user.credentials.clientId}</code>}
59+
/>
60+
</ListItem>
61+
<ListItem>
62+
<ListItemText
63+
primary="Expires"
64+
secondary={<DateDistance from={user.expires} />}
65+
/>
66+
</ListItem>
67+
<ListItem>
68+
<ListItemText
69+
primary="Scopes"
70+
secondaryTypographyProps={{ component: 'div' }}
71+
secondary={
72+
currentScopes.length ? (
73+
<List>
74+
{currentScopes.map(scope => (
75+
<ListItem key={scope}>
76+
<ListItemText secondary={<code>{scope}</code>} />
77+
</ListItem>
78+
))}
79+
</List>
80+
) : (
81+
'n/a'
82+
)
83+
}
84+
/>
85+
</ListItem>
86+
</List>
87+
</Fragment>
88+
)}
89+
</Dashboard>
90+
);
91+
}
92+
}

src/views/Profile/profile.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query Profile {
2+
currentScopes
3+
}

0 commit comments

Comments
 (0)