update : loginPage

This commit is contained in:
enggar_ganteng 2019-01-28 21:07:31 +07:00
parent d7724bda5a
commit 8b2f3ac089

View File

@ -36,7 +36,8 @@ class BTNLoginPage extends React.Component{
password: "", password: "",
showPassword : false, showPassword : false,
isLoading: false, isLoading: false,
loginFailed: false loginFailed: false,
isNeedEmailVerification: false,
}; };
this.defaultState = Object.assign({}, this.state); this.defaultState = Object.assign({}, this.state);
this.authStore = props.appstate.auth; this.authStore = props.appstate.auth;
@ -63,10 +64,15 @@ class BTNLoginPage extends React.Component{
password: password, password: password,
} }
this.authStore.login(data).then(res => { this.authStore.login(data).then(res => {
setTimeout(()=>{ if(!res.need_email_verification){
this.props.history.push(LINKS.DASHBOARD); setTimeout(()=>{
this.setState({isLoading:false}); this.props.history.push(LINKS.DASHBOARD);
},1000); this.setState({isLoading:false});
},1000);
}
else{
this.setState({isNeedEmailVerification:true});
}
}).catch(err => { }).catch(err => {
this.setState({loginFailed:true,isLoading:false}); this.setState({loginFailed:true,isLoading:false});
setTimeout(()=>this.setState({loginFailed:false}),3000); setTimeout(()=>this.setState({loginFailed:false}),3000);
@ -122,50 +128,72 @@ class BTNLoginPage extends React.Component{
</Grid> </Grid>
</Hidden> </Hidden>
<Grid item xs={12} sm={12} md={6} style={{paddingLeft : 50,paddingRight : 50}}> <Grid item xs={12} sm={12} md={6} style={{paddingLeft : 50,paddingRight : 50}}>
<Paper className={classes.formRegister}> {
<Typography variant="h6" gutterBottom> this.state.isNeedEmailVerification &&
Login to BTN Point <Paper className={classes.formRegister}>
</Typography> <Typography variant="h6" gutterBottom>
<Typography variant="subtitle2" gutterBottom> Your account still need email verification
Doesn't have an account? <Link to={"/register"}>Register</Link> </Typography>
</Typography> <Typography variant="subtitle2" gutterBottom>
<TextField Still not received any email? <Link to={"/register"}>Resend email</Link>
id="email" </Typography>
label="Email"
value={this.state.email} <div style={{padding : 5,marginTop : 20}}>
onChange={this.handleChange('email')} <Button onClick={() => this.setState({isNeedEmailVerification : false})} fullWidth variant="contained" style={{background:'#ffeb3b'}}>
margin="normal" Back to Login
variant="outlined" </Button>
/> </div>
{/*<div style={{display : 'flex',alignItems : 'center'}}>*/} </Paper>
<TextField }
id="password"
label="Password" {
value={this.state.password} !this.state.isNeedEmailVerification &&
onChange={this.handleChange('password')} <Paper className={classes.formRegister}>
margin="normal" <Typography variant="h6" gutterBottom>
type={this.state.showPassword ? 'text' : 'password'} Login to BTN Point
fullWidth </Typography>
variant="outlined" <Typography variant="subtitle2" gutterBottom>
InputProps={{ Doesn't have an account? <Link to={"/register"}>Register</Link>
endAdornment: ( </Typography>
<InputAdornment position="end"> <TextField
<IconButton id="email"
aria-label="Toggle password visibility" label="Email"
onClick={this.viewPassword} value={this.state.email}
> onChange={this.handleChange('email')}
{this.state.showPassword ? <VisibilityOff /> : <Visibility />} margin="normal"
</IconButton> variant="outlined"
</InputAdornment> />
), {/*<div style={{display : 'flex',alignItems : 'center'}}>*/}
}} <TextField
/> id="password"
<div style={{padding : 5,marginTop : 20}}> label="Password"
<Button onClick={() => this.login()} fullWidth variant="contained" style={{background:'#ffeb3b'}} disabled={this.state.email == '' || this.state.password == ''}> value={this.state.password}
{this.state.isLoading ? <CircularProgress className={classes.progress} /> : "Sign In"} onChange={this.handleChange('password')}
</Button> margin="normal"
</div> type={this.state.showPassword ? 'text' : 'password'}
</Paper> fullWidth
variant="outlined"
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
aria-label="Toggle password visibility"
onClick={this.viewPassword}
>
{this.state.showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
),
}}
/>
<div style={{padding : 5,marginTop : 20}}>
<Button onClick={() => this.login()} fullWidth variant="contained" style={{background:'#ffeb3b'}} disabled={this.state.email == '' || this.state.password == ''}>
{this.state.isLoading ? <CircularProgress className={classes.progress} /> : "Sign In"}
</Button>
</div>
</Paper>
}
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>