Skip to content

Instantly share code, notes, and snippets.

@lc3t35
Created May 23, 2018 09:20
Show Gist options
  • Save lc3t35/65cfa18c2cd8ade7adc305901171ea27 to your computer and use it in GitHub Desktop.
Save lc3t35/65cfa18c2cd8ade7adc305901171ea27 to your computer and use it in GitHub Desktop.
FormUserPass component
class FormUserPass extends PureComponent {
constructor(props) {
super(props);
this.state = {
username: '',
password: '',
passwordVerify: '',
stage: props.currentUser.stage || 0,
}
}
handleChange(name, value) {
console.log("data: ", name, value);
this.setState({ [name]: value }, () => {
console.log(this.state);
if ((this.state.password.length !== 0) && (this.state.password !== this.state.passwordVerify)) {
console.log("password not match");
return;
}
if ((this.state.stage === 0) && (this.state.password.length === 0)) {
console.log("must change password");
return;
}
console.log("ok");
this.props.inputProperties.onChange(
this.props.inputProperties.name,
{ username: this.state.username,
password: this.state.password }
);
});
}
render() {
// const { errorMessage } = this.props.context.getErrorMessage();
return (
<div className="row section-content form-group row form-funnel">
<div className="col-md-6 col-sm-6">
<label htmlFor="">Nom actuel d'utilisateur</label>
<input type="text" className="form-control" id="" disabled placeholder={this.props.currentUser.displayName}/>
</div>
<div className="col-md-6 col-sm-6">
<label htmlFor="">Nouveau nom d'utilisateur</label>
<Input name="username" onChange={this.handleChange.bind(this)} value="" layout="elementOnly" placeholder="Changer le nom"/>
</div>
<div className="col-md-6 col-sm-6">
<label htmlFor="">Nouveau mot de passe</label>
<Input name="password" onChange={this.handleChange.bind(this)} value="" layout="elementOnly" placeholder="Changer de mot de passe"/>
</div>
<div className="col-md-6 col-sm-6">
<label htmlFor="">Confirmer le mot de passe</label>
<Input name="passwordVerify" onChange={this.handleChange.bind(this)} value="" validations="equalsField:password" validationErrors={{ equalsField : "Saisissez le même mot de passe"}} layout="elementOnly" placeholder="Confirmer le nouveau mot de passe"/>
</div>
</div>
);
}
}
FormUserPass.contextTypes = {
updateCurrentValues: PropTypes.func,
};
registerComponent('FormUserPass', FormUserPass);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment