import React from 'react'; import withStyles from "@material-ui/core/styles/withStyles"; import {styles} from '../Register/registerStyle'; import {notification} from 'antd'; import Grid from '@material-ui/core/Grid'; import Paper from '@material-ui/core/Paper'; import Typography from '@material-ui/core/Typography'; import TextField from '@material-ui/core/TextField'; import Visibility from '@material-ui/icons/Visibility'; import VisibilityOff from '@material-ui/icons/VisibilityOff'; import Button from '@material-ui/core/Button'; import Hidden from '@material-ui/core/Hidden'; import Dialog from '@material-ui/core/Dialog'; import DialogActions from '@material-ui/core/DialogActions'; import DialogContent from '@material-ui/core/DialogContent'; import DialogContentText from '@material-ui/core/DialogContentText'; import DialogTitle from '@material-ui/core/DialogTitle'; import InputAdornment from '@material-ui/core/InputAdornment'; import IconButton from '@material-ui/core/IconButton'; import CircularProgress from '@material-ui/core/CircularProgress'; import Snackbar from '@material-ui/core/Snackbar'; import { Link } from 'react-router-dom'; import {inject, observer} from 'mobx-react'; import {LINKS} from "../../routes"; @inject('appstate') @observer class BTNLoginPage extends React.Component{ constructor(props) { super(props); this.props = props; this.state = { email: "", password: "", showPassword : false, isLoading: false, loginFailed: false, isNeedEmailVerification: false, }; this.defaultState = Object.assign({}, this.state); this.authStore = props.appstate.auth; } componentDidMount() { const urlParams = new URLSearchParams(window.location.search); if(urlParams.has('key')) { this.setState({ isLoading: true }); this.authStore.verifyEmail(urlParams.get('key')).then((res) => { if(res.login_request_id) { notification.open({ message: 'Email Verification', description: 'Email verification success' }); this.setState({ isLoading: false }); //redirect to otp page } else { notification.open({ message: 'Email Verification', description: res.message }); this.setState({ isLoading: false }); // res.message } }) } } handleChange = name => event => { this.setState({ [name]: event.target.value, }); }; viewPassword = ()=>{ this.setState({ showPassword : !this.state.showPassword }) }; login = () => { this.setState({isLoading:true}); const email = this.state.email; const password = this.state.password; const data = { username: email, password: password, } this.authStore.login(data).then(res => { console.log("res login",res); if(res.state == "verified"){ setTimeout(()=>{ this.props.history.push(LINKS.DASHBOARD); this.setState({isLoading:false}); },1000); } else if(res.state == "email_verification"){ this.setState({isNeedEmailVerification:true,isLoading:false}); } }).catch(err => { console.log("err login",err); this.setState({loginFailed:true,isLoading:false}); setTimeout(()=>this.setState({loginFailed:false}),3000); }); }; render(){ const { classes } = this.props; return (