add handleSubmit and FieldGroups

This commit is contained in:
Barry Gitarts 2018-05-31 13:29:42 -04:00
parent 9e010a79c2
commit 69a952d94a
1 changed files with 67 additions and 56 deletions

View File

@ -90,59 +90,44 @@ class InnerForm extends Component {
const { canSubmit } = this.state; const { canSubmit } = this.state;
return ( return (
<Fragment> <Fragment>
{canSubmit && {!canSubmit &&
<Alert bsStyle="warning"> <Alert bsStyle="warning">
Account not allowed to submit proposals Account not allowed to submit proposals <Button>Click to enable (Admin only)</Button>
</Alert> </Alert>
} }
<h2>Add proposal</h2> <h2>Add proposal</h2>
<p>Execute this on the console if proposal submit is not allowed</p> <p>Execute this on the console if proposal submit is not allowed</p>
<code>await ProposalCuration.methods.setSubmitPrice(web3.eth.defaultAccount, true, 1).send();</code> <code>await ProposalCuration.methods.setSubmitPrice(web3.eth.defaultAccount, true, 1).send();</code>
<h3>Price: {this.state.submitPrice}</h3> <h3>Price: {this.state.submitPrice}</h3>
<Form> <Form onSubmit={handleSubmit}>
<FormGroup>
<label>
Title:
<FormControl
type="text"
defaultValue={this.state.title}
onChange={(e) => this.setState({title: e.target.value }) } />
</label>
</FormGroup>
<FieldGroup <FieldGroup
id="title" id="title"
name="title" name="title"
type="test" type="text"
label="Title" label="Title"
onChange={handleChange} onChange={handleChange}
onBlur={handleBlur} onBlur={handleBlur}
value={values.title} value={values.title}
/> />
<FormGroup> <FieldGroup
<label> id="description"
Description: name="description"
<FormControl
type="text" type="text"
defaultValue={this.state.description} label="Description"
onChange={(e) => this.setState({description: e.target.value }) } /> onChange={handleChange}
</label> onBlur={handleBlur}
</FormGroup> value={values.description}
<FormGroup> />
<label> <FieldGroup
URL: id="url"
<FormControl name="url"
type="text" type="text"
defaultValue={this.state.url} label="URL"
onChange={(e) => this.setState({url: e.target.value }) } /> onChange={handleChange}
</label> onBlur={handleBlur}
</FormGroup> value={values.url}
{ />
this.state.canSubmit ? <Button type="submit" disabled={!canSubmit || isSubmitting}>{isSubmitting ? 'Submission in progress' : 'Submit'}</Button>
<FormGroup>
<Button onClick={(e) => this.handleClick(e)}>Submit</Button>
</FormGroup>
: ''
}
</Form> </Form>
</Fragment> </Fragment>
) )
@ -150,9 +135,35 @@ class InnerForm extends Component {
} }
const ProposalManager = withFormik({ const ProposalManager = withFormik({
mapPropsToValues: props => ({ title: '' }), mapPropsToValues: props => ({ title: '', description: '', url: '' }),
validate(values) {}, validate(values) {},
handleSubmit(values, { setSubmitting}){} handleSubmit(values, { setSubmitting}){
const { title, description, url } = values;
const { saveText } = EmbarkJS.Storage;
const { toHex } = web3.utils;
const { submitProposal } = ProposalCuration.methods;
saveText(JSON.stringify(description))
.then(hash => {
const hexHash = toHex(hash);
//TODO create toggle for address approval
submitProposal(
"0x00",
"0x0000000000000000000000000000000000000000",
0,
"0x00",
hexHash
)
.send({from: web3.eth.defaultAccount, gasLimit: 1000000})
.then(res => {
setSubmitting(false);
console.log(res);
})
.catch(err => {
setSubmitting(false);
console.log('Storage saveText Error: ', err.message)
});
})
}
})(InnerForm) })(InnerForm)
export default ProposalManager; export default ProposalManager;