Skip to content

Commit

Permalink
Added user page link to dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
gsidebo committed Jun 29, 2016
1 parent 080fdeb commit 42e285f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions static/js/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import React from 'react';
import LoginButton from '../containers/LoginButton';
import UserMenu from '../containers/UserMenu';
import { Navbar } from 'react-bootstrap';

class Header extends React.Component {
Expand All @@ -13,7 +13,7 @@ class Header extends React.Component {
let content;
if (!empty) {
content = <div className="nav-utility pull-right">
<LoginButton />
<UserMenu />
</div>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import MenuItem from 'react-bootstrap/lib/MenuItem';

import { getPreferredName } from '../util/util';

class LoginButton extends React.Component {
class UserMenu extends React.Component {
static propTypes = {
dispatch: React.PropTypes.func.isRequired,
profile: React.PropTypes.object.isRequired,
Expand All @@ -30,7 +30,12 @@ class LoginButton extends React.Component {
<SplitButton
title={title}
bsStyle="danger"
id="logout-button">
id="user-menu">
<LinkContainer to={{ pathname: `/users/${profile.username}` }} active={false}>
<MenuItem>
Profile
</MenuItem>
</LinkContainer>
<LinkContainer to={{ pathname: '/settings' }} active={false}>
<MenuItem>
Settings
Expand Down Expand Up @@ -63,4 +68,4 @@ const mapStateToProps = (state) => {
};
};

export default connect(mapStateToProps)(LoginButton);
export default connect(mapStateToProps)(UserMenu);
6 changes: 4 additions & 2 deletions ui/templates/base_error.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
{% if authenticated %}
<div class="dropdown btn-group">
<a class="btn btn-danger" href="/dashboard"><span>{{ name }}</span></a>
<button aria-label="logout_label" id="logout-button" role="button" class="dropdown-toggle btn btn-danger"
<button aria-label="logout_label" id="user-menu" role="button" class="dropdown-toggle btn btn-danger"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" type="button">
<span><span class="caret"></span></span>
</button>
<ul class="dropdown-menu" aria-labelledby="logout-button">
<ul class="dropdown-menu" aria-labelledby="user-menu">
<li role="presentation" class=""><a role="menuitem" href="/users/{{ username }}" tabindex="-1">Profile</a></li>
<li role="presentation" class=""><a role="menuitem" href="/settings" tabindex="-1">Settings</a></li>
<li role="presentation" class=""><a role="menuitem" href="/logout" tabindex="-1">Logout</a></li>
</ul>
</div>
Expand Down
36 changes: 13 additions & 23 deletions ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,43 +103,33 @@ def get(self, request, *args, **kwargs):
return super(UsersView, self).get(request, *args, **kwargs)


def page_404(request):
"""
Overridden handler for the 404 error pages.
"""
def standard_error_page(request, status_code, template_url):
name = request.user.profile.preferred_name if not request.user.is_anonymous() else ""

response = render(
request,
"404.html",
template_url,
context={
"style_src": get_bundle_url(request, "style.js"),
"dashboard_src": get_bundle_url(request, "dashboard.js"),
"js_settings_json": "{}",
"authenticated": not request.user.is_anonymous(),
"name": name,
"username": request.user.social_auth.get(provider=EdxOrgOAuth2.name).uid
}
)
response.status_code = 404
response.status_code = status_code
return response


def page_500(request):
def page_404(request):
"""
Overridden handler for the 500 error pages.
Overridden handler for the 404 error pages.
"""
name = request.user.profile.preferred_name if not request.user.is_anonymous() else ""
return standard_error_page(request, 404, "404.html")

response = render(
request,
"500.html",
context={
"style_src": get_bundle_url(request, "style.js"),
"dashboard_src": get_bundle_url(request, "dashboard.js"),
"js_settings_json": "{}",
"authenticated": not request.user.is_anonymous(),
"name": name,
}
)
response.status_code = 500
return response

def page_500(request):
"""
Overridden handler for the 404 error pages.
"""
return standard_error_page(request, 500, "500.html")

0 comments on commit 42e285f

Please sign in to comment.