Skip to content

Commit

Permalink
Merge pull request ECLK#74 from hevayo/master
Browse files Browse the repository at this point in the history
Fix save election module
  • Loading branch information
hevayo authored Mar 21, 2019
2 parents 564fe65 + 2d35b2b commit 4cc44b0
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/modules/election-model/CreateElection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Redirect } from 'react-router-dom';
import CandidateForm from './CandidateForm';
import DivisionConfig from './DivisionConfig';
import ElectionConfig from './ElectionConfig';
import { createElection, updateElection } from './state/ElectionAction';
import { createElection, updateElection, submitElection } from './state/ElectionAction';
import { connect } from 'react-redux';


Expand Down Expand Up @@ -46,6 +46,7 @@ class CreateElection extends React.Component {
state = {
activeStep: 0,
skipped: new Set(),
goToHome: false,
};

constructor() {
Expand Down Expand Up @@ -90,6 +91,13 @@ class CreateElection extends React.Component {
handleNext = () => {
const { activeStep } = this.state;
let { skipped } = this.state;
if(activeStep === 2){
this.props.submitElection(this.props.new_election_module);
this.setState({
goToHome: true
});
return;
}
this.setState({
activeStep: activeStep + 1,
skipped,
Expand Down Expand Up @@ -120,7 +128,7 @@ class CreateElection extends React.Component {
</Grid>
<Grid item xs={12}>
<div>
{activeStep === steps.length ? (
{this.state.goToHome ? (
<Redirect to="/admin/home" />
) : (
<Paper className={classes.pageContent} elevation={1}>
Expand Down Expand Up @@ -193,7 +201,8 @@ const mapStateToProps = ({ ElectionModel }) => {

const mapActionsToProps = {
createElection,
updateElection
updateElection,
submitElection
};

export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(CreateElection));
93 changes: 87 additions & 6 deletions src/modules/election-model/state/ElectionAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export const setPostModuleData = (val) => {
}
}

export function postCallElectionData(CallElectionData, electionData) {
export function postCallElectionData(electionData) {
//TODO: config ids should get from the front end and the array should be dynamic

let allElectionModuleData = {
"moduleId": electionData.module_id,
"moduleId": "1268362183761283718236",
"divisionCommonName":'Provintial',
"createdBy":'admin',
"createdAt":'',
Expand Down Expand Up @@ -85,7 +85,7 @@ export function postCallElectionData(CallElectionData, electionData) {
return function (dispatch) {
const response = axios
.post(
`${API_BASE_URL}/modules/moduleData`,
`${API_BASE_URL}/modules`,
{ ...allElectionModuleData }
)
.then(response => {
Expand All @@ -94,7 +94,6 @@ export function postCallElectionData(CallElectionData, electionData) {
}).catch(err => {
console.log(err)
});
// import store from '../store';
}
}

Expand All @@ -118,15 +117,97 @@ export const updateElection = function updateElection(election) {
};
}

export const saveElection = function saveElection() {
export const saveElection = function saveElection(election) {

return function (dispatch) {

dispatch({
type: SAVE_ELECTION_MODULE,
type: UPDATE_ELECTION_MODULE,
payload: {}
})
};
}

export const submitElection = function saveElection(election) {

let allElectionModuleData = {
"name": election.name,
"id": "1268362183761283718236",
"divisionCommonName":'Provintial',
"createdBy":'admin',
"createdAt":'',
"updatedAt":'',
"candidateFormConfiguration": [
{
candidateConfigId: '1',
},
{
candidateConfigId: '2',
},
{
candidateConfigId: '3',
},
{
candidateConfigId: '4',
},
],
"supportingDocuments": [
{
supportDocConfigId: '15990459-2ea4-413f-b1f7-29a138fd7a97',
},
{
supportDocConfigId: 'fe2c2d7e-66de-406a-b887-1143023f8e72',
},
{
supportDocConfigId: 'ff4c6768-bdbe-4a16-b680-5fecb6b1f747',
}
],
"divisionConfig":[
{
divisionName: 'Sample',
divisionCode: 'code',
noOfCandidates: '1',
},
{
divisionName: 'Sample3',
divisionCode: 'code',
noOfCandidates: '2',
},
{
divisionName: 'Sample5',
divisionCode: 'code',
noOfCandidates: '3',
}
],
"electionConfig": [
{
electionModuleConfigId: '15990459-2ea4-413f-b1f7-29a138fd7a97',
value:'allowed',
}
],
}

return function (dispatch) {
const response = axios
.post(
`${API_BASE_URL}/election-modules`,
{ ...allElectionModuleData }
)
.then(response => {
console.log("response.data", response.data);
if(response.data){
election.submited = true;
dispatch({
type: UPDATE_ELECTION_MODULE,
payload: election
});
}
}).catch(err => {
console.log(err)
});
}
}



//----------- End of save Create Election Data ----------------

0 comments on commit 4cc44b0

Please sign in to comment.