diff options
| author | Jules Laplace <jules@okfoc.us> | 2017-03-20 01:59:47 +0100 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2017-03-20 01:59:47 +0100 |
| commit | d9d81925299aa787cbdb815cb4b06e17a412b40c (patch) | |
| tree | 601ea37cc6f7e5c6aa3ac1e886d056c2df107779 /client/components/Menu.jsx | |
| parent | bf7ac6af587f68553b83a54fcb724dfc9d684644 (diff) | |
filter by date
Diffstat (limited to 'client/components/Menu.jsx')
| -rw-r--r-- | client/components/Menu.jsx | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/client/components/Menu.jsx b/client/components/Menu.jsx new file mode 100644 index 0000000..d53803d --- /dev/null +++ b/client/components/Menu.jsx @@ -0,0 +1,57 @@ + +import React from 'react' + +import client from '../client' + +export default class Menu extends React.Component { + constructor() { + super() + this.setGoal = this.setGoal.bind(this) + this.logout = this.logout.bind(this) + } + setGoal() { + const goal = Math.abs(parseInt(prompt('Please enter your calorie goal', this.props.user.goal))) + if (goal) { + client.service('users').patch(this.props.user.id, { + goal: goal, + token: client.get('token'), + }).then((user) => { + this.props.updateUser(user) + }) + } + } + logout() { + client.logout().then(() => { + window.location.reload() + }) + } + render() { + const user = this.props.user + const items = [] + items.push( <li key='hello'>Hello {user.email}</li> ) + items.push( <li key='goal' onClick={this.setGoal}><a href='#'>Goal</a>: {user.goal}</li> ) + switch (user.role) { + case 'admin': + if (this.props.user.id !== this.props.currentUser.id) { + items.push( <li key='resetUser'><a href='#' onClick={this.resetUser}>Reset User</a></li> ) + } + items.push( <li key='userlist'><a href='#' onClick={this.props.toggleMode}>Users</a></li> ) + items.push( <li key='meallist'><a href='#' onClick={this.props.toggleMode}>Meals</a></li> ) + break + case 'manager': + items.push( <li key='userlist'><a href='#' onClick={this.props.toggleMode}>Users</a></li> ) + items.push( <li key='meallist'><a href='#' onClick={this.props.toggleMode}>Meals</a></li> ) + case 'user': + break + } + items.push( <li key='logout'><a href='#' onClick={this.logout}>Logout</a></li> ) + + return ( + <div> + <ul className='menu'> + {items} + </ul> + </div> + ) + } +} |
