Created
March 8, 2016 23:21
-
-
Save marr/fdea49ec2472c79bd77f 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 { reduxForm } from 'redux-form' | |
const fields = ['email_marketing_opt_in'] | |
const submit = (values, dispatch) => { | |
dispatch() | |
} | |
class EmailMarketingForm extends Component { | |
render() { | |
const { | |
fields: { | |
email_marketing_opt_in | |
}, guest, handleSubmit | |
} = this.props | |
const { onBlur, onChange } = email_marketing_opt_in | |
function handleOptIn (e) { | |
onChange(true) | |
} | |
function handleOptOut (e) { | |
onChange(false) | |
} | |
const optInProps = { | |
defaultChecked: guest.email_marketing_opt_in, | |
onChange: handleOptIn, | |
value: true | |
} | |
const optOutProps = { | |
defaultChecked: !guest.email_marketing_opt_in, | |
onChange: handleOptOut, | |
value: false | |
} | |
return ( | |
<form className="marketing-form" onSubmit={handleSubmit(submit)}> | |
<p>Lorem ipsum dolor sit amet, ius ne detraxit gloriatur, ex quidam | |
vocibus verterem sit. Ea nec nostro possim persius, no porro congue qui. | |
Sea ad amet eripuit senserit, illum civibus in eos. Nostrud necessitatibus | |
an eos, lorem viderer complectitur eum te.</p> | |
<div> | |
<input type="radio" name="email_marketing_opt_in" {...optInProps} /> | |
<label>I want to receive email marketing from Westfield</label> | |
</div> | |
<div> | |
<input type="radio" name="email_marketing_opt_in" {...optOutProps} /> | |
<label>I do not want to receive email marketing from Westfield</label> | |
</div> | |
<button className="primary primary-large">Submit</button> | |
</form> | |
) | |
} | |
} | |
EmailMarketingForm = reduxForm({ | |
form: 'marketing', | |
fields | |
})(EmailMarketingForm) | |
export default EmailMarketingForm | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment