Skip to content

Instantly share code, notes, and snippets.

@yuklia
Created June 12, 2017 12:36
Show Gist options
  • Save yuklia/320ffcd16880a5420df5daa5fa9a6a23 to your computer and use it in GitHub Desktop.
Save yuklia/320ffcd16880a5420df5daa5fa9a6a23 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
import generateRandomString from '../../../helpers/generateRandomString';
import WrappedComponent from './Component';
import {connect} from 'react-redux';
import { change } from 'redux-form';
import {CHANGE_PASSWORD_FORM} from '../FormWrapper';
function FormFooterHOC(WrappedComponent) {
return class extends React.Component {
constructor(props) {
super(props);
this.state = {
isSubmitEnabled: false
};
}
render() {
return <WrappedComponent
isSubmitEnabled={this.state.isSubmitEnabled}/>;
}
};
}
const mapDispatchToProps = (dispatch, ownProps) => {
return {
passwordHandler: ()=> {
console.log('password handler');
const pass = generateRandomString(6);
ownProps.onClickGeneratePassword(pass);
dispatch(change(CHANGE_PASSWORD_FORM, 'new-password', pass));
dispatch(change(CHANGE_PASSWORD_FORM, 'repeat-new-password', pass));
},
onSubmitHandler: () => {
console.log('submit handler');
//send data to server
//if not empty
}
}
};
export default connect(null, mapDispatchToProps)(FormFooterHOC(WrappedComponent));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment