Commit 0ed56f80 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed some warnings

parent 38ae0956
......@@ -13,7 +13,9 @@ class LoginLogout extends React.Component {
api: PropTypes.object.isRequired,
user: PropTypes.object,
login: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired
logout: PropTypes.func.isRequired,
variant: PropTypes.string,
color: PropTypes.string
}
static styles = theme => ({
......@@ -24,6 +26,7 @@ class LoginLogout extends React.Component {
marginRight: theme.spacing.unit * 2
}
},
button: {}, // to allow overrides
errorText: {
marginTop: theme.spacing.unit,
marginBottom: theme.spacing.unit
......@@ -44,21 +47,35 @@ class LoginLogout extends React.Component {
failure: false
}
componentDidMount() {
this._ismounted = true
}
componentWillUnmount() {
this._ismounted = false
}
handleLoginDialogClosed(withLogin) {
this.setState({loginDialogOpen: false})
if (withLogin) {
if (this._ismounted) {
this.setState({loggingIn: true})
}
this.props.login(this.state.userName, this.state.password, (success) => {
if (this._ismounted) {
if (success) {
this.setState({loggingIn: false, loginDialogOpen: false, failure: false})
} else {
this.setState({loggingIn: false, failure: true, loginDialogOpen: true})
}
}
})
} else {
if (this._ismounted) {
this.setState({loggingIn: false, failure: false, userName: '', password: '', loginDialogOpen: false})
}
}
}
handleChange = name => event => {
this.setState({
......@@ -71,7 +88,7 @@ class LoginLogout extends React.Component {
}
render() {
const { classes, user, ...otherProps } = this.props
const { classes, user, variant, color } = this.props
const { loggingIn, failure } = this.state
if (user) {
return (
......@@ -79,13 +96,20 @@ class LoginLogout extends React.Component {
<Typography color="inherit" variant="body1">
Welcome, {user.first_name} {user.last_name}
</Typography>
<Button className={classes.button} {...otherProps} onClick={this.handleLogout}>Logout</Button>
<Button
className={classes.button}
variant={variant} color={color}
onClick={this.handleLogout}
>Logout</Button>
</div>
)
} else {
return (
<div className={classes.root}>
<Button className={classes.button} {...otherProps} onClick={() => this.setState({loginDialogOpen: true})}>Login</Button>
<Button
className={classes.button} variant={variant} color={color}
onClick={() => this.setState({loginDialogOpen: true})}
>Login</Button>
<Dialog
open={this.state.loginDialogOpen}
onClose={() => this.handleLoginDialogClosed(false)}
......
......@@ -4,7 +4,7 @@ import { withErrors } from './errors'
import { UploadRequest } from '@navjobs/upload'
import Swagger from 'swagger-client'
import { apiBase } from '../config'
import { Typography, FormGroup, FormLabel, Button, withStyles } from '@material-ui/core'
import { Typography, withStyles } from '@material-ui/core'
import LoginLogout from './LoginLogout'
const ApiContext = React.createContext()
......@@ -290,7 +290,7 @@ export class ApiProvider extends React.Component {
state = {
api: new Api(),
user: null,
login: (userName, password, callback) => {
login: (userName, password, successCallback) => {
Api.createSwaggerClient(userName, password)
.catch(this.state.api.handleApiError)
.then(client => {
......@@ -304,9 +304,9 @@ export class ApiProvider extends React.Component {
if (response) {
const user = response.body
this.setState({api: new Api(user), user: user})
callback(true)
successCallback(true)
} else {
callback(false)
successCallback(false)
}
})
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment