Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[new_profile] Pressing create multiple time creates multiple candidates "silently" #5808

Merged
merged 6 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jsx/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,7 @@ class ButtonElement extends Component {
type={this.props.type}
className={this.props.buttonClass}
onClick={this.handleClick}
disabled={this.props.disabled}
>
{this.props.label}
</button>
Expand All @@ -1572,12 +1573,14 @@ ButtonElement.propTypes = {
name: PropTypes.string,
label: PropTypes.string,
type: PropTypes.string,
disabled: PropTypes.bool,
maltheism marked this conversation as resolved.
Show resolved Hide resolved
onUserInput: PropTypes.func,
};

ButtonElement.defaultProps = {
label: 'Submit',
type: 'submit',
disabled: null,
buttonClass: 'btn btn-primary',
columnSize: 'col-sm-9 col-sm-offset-3',
onUserInput: function() {
Expand Down
7 changes: 7 additions & 0 deletions modules/new_profile/jsx/NewProfileIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class NewProfileIndex extends React.Component {
isLoaded: false,
isCreated: false,
error: false,
submitDisabled: false,
};
this.handleSubmit = this.handleSubmit.bind(this);
this.setFormData = this.setFormData.bind(this);
Expand Down Expand Up @@ -89,6 +90,9 @@ class NewProfileIndex extends React.Component {
}
formObject.append('fire_away', 'New Candidate');

// disable button to prevent form resubmission.
this.setState({submitDisabled: true});

fetch(this.props.submitURL, {
method: 'POST',
cache: 'no-cache',
Expand All @@ -103,6 +107,8 @@ class NewProfileIndex extends React.Component {
});
} else {
resp.json().then((message) => {
// enable button for form resubmission.
this.setState({submitDisabled: false});
swal('Error!', message, 'error');
});
}
Expand Down Expand Up @@ -240,6 +246,7 @@ class NewProfileIndex extends React.Component {
label = "Create"
id = "button"
type = "submit"
disabled={this.state.submitDisabled}
/>
</FormElement>
);
Expand Down