-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from AnnaDodson/update-admin-auth-flow
New Admin Auth flow to make the page better
- Loading branch information
Showing
13 changed files
with
265 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { Component } from 'react'; | ||
import { Route } from 'react-router'; | ||
import { AdminLayout } from './components/AdminLayout'; | ||
import Auth from './components/Auth'; | ||
import { EditParticipant } from './components/admin/editParticipant'; | ||
import { EditTeams } from './components/admin/editTeams'; | ||
import { EditChallengeSettings } from './components/admin/editChallengeSettings'; | ||
import { AdminScoreBoard } from './components/admin/adminScoreBoard'; | ||
|
||
export class Admin extends Component { | ||
static displayName = Admin.name; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
loading: true, | ||
editParticipant : false, | ||
editTeams : false, | ||
editChallengeSettings : false, | ||
showLeaderBoard : false, | ||
} | ||
this.auth = new Auth() | ||
this.auth.isAdminRequest() | ||
.then(isAdmin => { | ||
if(!isAdmin){ | ||
console.log("not an admin") | ||
// redirect to home if not an admin | ||
window.location.href = "/"; | ||
}else{ | ||
this.setState({ | ||
loading: false, | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
render () { | ||
return ( | ||
<div> | ||
{this.state.loading && | ||
<p><em>Loading...</em></p> | ||
} | ||
{!this.state.loading && | ||
<AdminLayout > | ||
<Route path='/admin/participants' component={EditParticipant} /> | ||
<Route path='/admin/teams' component={EditTeams} /> | ||
<Route path='/admin/settings' component={EditChallengeSettings} /> | ||
<Route path='/admin/leaderboard' component={AdminScoreBoard} /> | ||
</AdminLayout> | ||
} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React, { Component } from 'react'; | ||
import { Container } from 'reactstrap'; | ||
import { AdminNavMenu } from './AdminNavMenu'; | ||
|
||
export class AdminLayout extends Component { | ||
static displayName = AdminLayout.name; | ||
|
||
render () { | ||
return ( | ||
<div> | ||
<AdminNavMenu /> | ||
<Container> | ||
{this.props.children} | ||
</Container> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { Component } from 'react'; | ||
import { Collapse, Container, Navbar, NavbarBrand, NavbarToggler, NavItem, NavLink } from 'reactstrap'; | ||
import { Link } from 'react-router-dom'; | ||
import Auth from './Auth'; | ||
import './NavMenu.css'; | ||
|
||
export class AdminNavMenu extends Component { | ||
static displayName = AdminNavMenu.name; | ||
|
||
constructor (props) { | ||
super(props); | ||
this.auth = new Auth(); | ||
this.toggleNavbar = this.toggleNavbar.bind(this); | ||
this.state = { | ||
collapsed: true, | ||
isLoggedIn : this.auth.isLoggedIn() | ||
}; | ||
} | ||
|
||
toggleNavbar () { | ||
this.setState({ | ||
collapsed: !this.state.collapsed | ||
}); | ||
} | ||
|
||
render () { | ||
return ( | ||
<header> | ||
<Navbar className="admin-container navbar-expand-sm navbar-toggleable-sm ng-white border-bottom box-shadow mb-3" light> | ||
<Container> | ||
<NavbarBrand tag={Link} to="/admin">Admin</NavbarBrand> | ||
<NavbarToggler onClick={this.toggleNavbar} className="mr-2" /> | ||
{this.state.isLoggedIn && | ||
<Collapse className="d-sm-inline-flex flex-sm-row-reverse" isOpen={!this.state.collapsed} navbar> | ||
<ul className="navbar-nav flex-grow"> | ||
<NavItem> | ||
<NavLink tag={Link} className="text-dark" to="/admin/participants">Participants</NavLink> | ||
</NavItem> | ||
<NavItem> | ||
<NavLink tag={Link} className="text-dark" to="/admin/teams">Teams</NavLink> | ||
</NavItem> | ||
<NavItem> | ||
<NavLink tag={Link} className="text-dark" to="/admin/settings">Settings</NavLink> | ||
</NavItem> | ||
<NavItem> | ||
<NavLink tag={Link} className="text-dark" to="/admin/leaderboard">Leader Board</NavLink> | ||
</NavItem> | ||
</ul> | ||
</Collapse> | ||
} | ||
</Container> | ||
</Navbar> | ||
</header> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.