Skip to content

Commit

Permalink
Merge pull request #223 from YujithIsura/master
Browse files Browse the repository at this point in the history
Fixed snack bar loading issue on candidate modal
  • Loading branch information
YujithIsura authored Feb 26, 2020
2 parents 1a346b5 + bccee31 commit 9bd7204
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
24 changes: 7 additions & 17 deletions client/src/components/CandidateProfile/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import {withStyles} from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
import axios from 'axios';
import Hidden from '@material-ui/core/Hidden';
import Notifier, { openSnackbar } from '../Notifier';
import { candidateMessage } from '../../modules/election/state/ElectionAction';
import { getNominationCandidates,getCandidateSupportingDocs } from '../../modules/nomination/state/NominationAction';
import { connect } from 'react-redux';
import DynamicForm from "../DynamicForm";
Expand Down Expand Up @@ -100,7 +96,7 @@ class TextFields extends React.Component {

handleSubmit = (data, callback) => {
// this.refs.btn.setAttribute("disabled", "disabled");
const { index, customProps,getNominationCandidates } = this.props;
const { index, customProps,getNominationCandidates,candidateMessage } = this.props;
let {jsonSchemaProperties} = this.state;
let candidateKeyValues = { "nominationId" : customProps,
"candidateData":[] };
Expand Down Expand Up @@ -130,13 +126,9 @@ class TextFields extends React.Component {
.then(function (response) {
callback({success:response.status == 201});
if(index){
setTimeout(() => {
openSnackbar({ message: 'Candidate Updated Sccessfully...' });
}, 10);
candidateMessage('Candidate Updated Sccessfully...');
}else{
setTimeout(() => {
openSnackbar({ message: 'Candidate Added Sccessfully...' });
}, 10);
candidateMessage('Candidate Added Sccessfully...');
}

getNominationCandidates(customProps);
Expand All @@ -148,9 +140,7 @@ class TextFields extends React.Component {
callback({success:false})
const message = _.get(e, 'response.data.message');
if(message) {
setTimeout(() => {
openSnackbar({ message });
}, 10);
candidateMessage(message);
}
});
};
Expand All @@ -172,7 +162,6 @@ class TextFields extends React.Component {
return <div>Loading form...</div>;
} else {
return (<div>
<Notifier/>
<DynamicForm index={this.props.index} defaultFormData={formData} jsonSchema={jsonSchema} onSubmit={this.handleSubmit}/>
</div>);
}
Expand All @@ -191,7 +180,8 @@ const mapStateToProps = ({Nomination, Election}) => {

const mapActionsToProps = {
getNominationCandidates,
getCandidateSupportingDocs
getCandidateSupportingDocs,
candidateMessage
};

export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(TextFields));
6 changes: 5 additions & 1 deletion client/src/modules/election/state/ElectionAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,11 @@ export const onChangeApprovalData = (electionApprovals) => {
};
}


export function candidateMessage (message) {
return function (dispatch) {
dispatch(openSnackbar({ message: message }));
}
}
export const openSnackbar = ({ message }) => {
const data = {
open: true,
Expand Down

0 comments on commit 9bd7204

Please sign in to comment.