I need to make a redirect from inside an onSubmit call.
Currently the full code is as below, and I need to keep CampaignNew as a class-based component. How can I do it?
import React, { Component } from 'react';
import Layout from '../../components/layoyt';
import { Form, Button, Input, Message } from 'semantic-ui-react';
import factory from '../../components/factory';
import web3 from '../../components/web3';
class CampaignNew extends Component {
state = {
minimumContribution: '0',
errorMessage: '',
loading: false
};
onSubmit = async (event) => {
event.preventDefault(); // Prevent the browser to attemp submission at initialization
this.setState({ loading: true, errorMessage: '' });
try {
await window.ethereum.enable();
const accounts = await web3.eth.getAccounts();
console.log('Account :' + accounts[0]);
await factory.methods
.createCampaign(this.state.minimumContribution)
.send({
from: accounts[0]
});
//// !!PUSH_TO_('/')
this.setState({ loading: false });
}
catch (err) {
this.setState({ errorMessage: err.message });
this.setState({ loading: false });
}
};
render() {
return (
<Layout>
<h3>
Create a Campaign
</h3>
<Form onSubmit={this.onSubmit} error={!!this.state.errorMessage}>
<Form.Field>
<label>Minimum Contribution</label>
<Input label='wei'
labelPosition='right'
value={this.state.minimumContribution}
onChange={event => this.setState({ minimumContribution: event.target.value })}
/>
</Form.Field>
<Message error header='There was some errors with your submission' content={this.state.errorMessage} />
<Button loading={this.state.loading} primary>Create</Button>
</Form>
</Layout>
);
}
}
export default CampaignNew;