diff --git a/client/src/components/CandidateProfile/index.js b/client/src/components/CandidateProfile/index.js index e33b05e1..251fb6a4 100644 --- a/client/src/components/CandidateProfile/index.js +++ b/client/src/components/CandidateProfile/index.js @@ -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"; @@ -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":[] }; @@ -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); @@ -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); } }); }; @@ -172,7 +162,6 @@ class TextFields extends React.Component { return
Loading form...
; } else { return (
-
); } @@ -191,7 +180,8 @@ const mapStateToProps = ({Nomination, Election}) => { const mapActionsToProps = { getNominationCandidates, - getCandidateSupportingDocs + getCandidateSupportingDocs, + candidateMessage }; export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(TextFields)); diff --git a/client/src/modules/election/state/ElectionAction.js b/client/src/modules/election/state/ElectionAction.js index 847b36b7..3143a3c0 100644 --- a/client/src/modules/election/state/ElectionAction.js +++ b/client/src/modules/election/state/ElectionAction.js @@ -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,