I am working on a forgot password form. When the user fills in the form - I want to replace the form with a thank you message, then redirect the user to the login page after 5 seconds. I also want to empty the forgotData state - so that a user can return back to the form - or refresh etc.. to fill it in again..
my current code looks like this - I've tried to null the state on componentWillUnmount - but its not working.
<Redirect refresh='5' to='/login' >
^ is something like that possible?
the forgot page looks like this.
import React, { Component } from 'react'
import { withRouter, Redirect } from 'react-router-dom';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { fetchForget } from '../../actions/forgotAction';
import { Row, Col } from 'antd';
// components
import ForgotPasswordSyncValidationForm from './ForgotPasswordSyncValidationForm'
// this is a class because it needs state
class ForgotPassword extends Component {
constructor(props, context) {
super(props, context);
this.submit = this.submit.bind(this);
}
componentDidMount() {
// console.log('this', this)
}
componentWillMount () {
document.body.classList.add('screenbackground');
}
componentWillUnmount() {
document.body.classList.remove('screenbackground');
this.state = {
forgotData: null
}
}
submit(data) {
this.props.fetchForget(data);
}
render() {
// when the user has applied for a new password
/*
if(this.props.forgotData.isForgot){
setTimeout(function() {
return <Redirect to='/login'/>;
}.bind(this), 5000);
}
console.log(this.props.forgotData)
*/
return (
<div className="Page form-components dark">
<h2>Forgot Password?</h2>
<Row>
<Col xs={24} sm={24} md={10}>
<p>A message here about what this forgot form is about</p>
</Col>
<Col xs={24} sm={24} md={24}>
<Row>
<Col xs={24} sm={24} md={6}>
{!this.props.forgotData.isForgot ? (
<ForgotPasswordSyncValidationForm onSubmit={this.submit} />
) : (
<div>
<p>Thank you for filling in the forgot password form. We have generated a new password for you, please check your email.</p>
<Redirect to='/login'/>
</div>
)}
</Col>
</Row>
</Col>
</Row>
<div className="shell" />
<div className="screen-background forgot" />
</div>
)
}
}
function mapStateToProps(state) {
return {
forgotData: state.forgot
};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators({ fetchForget }, dispatch);
}
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(ForgotPassword))