Work Item and Activity screens mostly complete
This commit is contained in:
@@ -1,42 +1,6 @@
|
||||
import React, { Fragment, Component } from 'react'
|
||||
import { api } from '../API'
|
||||
import { Route, Redirect } from 'react-router-native'
|
||||
import { View } from 'react-native'
|
||||
import autobind from 'autobind-decorator'
|
||||
|
||||
export class DefaultRoute extends Component {
|
||||
@autobind
|
||||
updateComponent() {
|
||||
this.forceUpdate()
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.addListener('login', this.updateComponent)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
api.removeListener('login', this.updateComponent)
|
||||
}
|
||||
|
||||
render() {
|
||||
const user = api.loggedInUser
|
||||
let path = null
|
||||
|
||||
if (user) {
|
||||
if (!user.pending) {
|
||||
path = '/home'
|
||||
}
|
||||
} else {
|
||||
path = '/login'
|
||||
}
|
||||
|
||||
const { location } = this.props
|
||||
|
||||
// Render a redirect or nothing until we finished logging on
|
||||
return (
|
||||
<Route path='/' render={() => (
|
||||
path ? <Redirect to={path} /> : null
|
||||
)} />
|
||||
)
|
||||
}
|
||||
export const DefaultRoute = () => {
|
||||
return <Route render={() => (<Redirect to={'/home'} />)} />
|
||||
}
|
||||
|
||||
@@ -17,25 +17,25 @@ export class ProtectedRoute extends React.Component {
|
||||
|
||||
componentDidMount() {
|
||||
api.addListener('login', this.updateComponent)
|
||||
api.addListener('logout', this.updateComponent)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
api.removeListener('login', this.updateComponent)
|
||||
api.removeListener('logout', this.updateComponent)
|
||||
}
|
||||
|
||||
render(props) {
|
||||
const user = api.loggedInUser
|
||||
|
||||
if (user) {
|
||||
if (user.pending) {
|
||||
// The API might be in the middle of fetching the user information
|
||||
return null
|
||||
} else if (!this.props.admin || (this.props.admin && user.administrator)) {
|
||||
if (user.pending) {
|
||||
return null
|
||||
} else {
|
||||
if (!user._id || (this.props.admin && !user.administrator)) {
|
||||
return <Redirect to='/login' />
|
||||
} else {
|
||||
return <Route {...this.props} />
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Can add redirect back in here - see website
|
||||
return <Redirect to='/login' />
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user