Created
June 12, 2017 12:36
-
-
Save yuklia/320ffcd16880a5420df5daa5fa9a6a23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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