Skip to content

Commit 4cc44b0

Browse files
authored
Merge pull request ECLK#74 from hevayo/master
Fix save election module
2 parents 564fe65 + 2d35b2b commit 4cc44b0

File tree

2 files changed

+99
-9
lines changed

2 files changed

+99
-9
lines changed

src/modules/election-model/CreateElection.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Redirect } from 'react-router-dom';
1414
import CandidateForm from './CandidateForm';
1515
import DivisionConfig from './DivisionConfig';
1616
import ElectionConfig from './ElectionConfig';
17-
import { createElection, updateElection } from './state/ElectionAction';
17+
import { createElection, updateElection, submitElection } from './state/ElectionAction';
1818
import { connect } from 'react-redux';
1919

2020

@@ -46,6 +46,7 @@ class CreateElection extends React.Component {
4646
state = {
4747
activeStep: 0,
4848
skipped: new Set(),
49+
goToHome: false,
4950
};
5051

5152
constructor() {
@@ -90,6 +91,13 @@ class CreateElection extends React.Component {
9091
handleNext = () => {
9192
const { activeStep } = this.state;
9293
let { skipped } = this.state;
94+
if(activeStep === 2){
95+
this.props.submitElection(this.props.new_election_module);
96+
this.setState({
97+
goToHome: true
98+
});
99+
return;
100+
}
93101
this.setState({
94102
activeStep: activeStep + 1,
95103
skipped,
@@ -120,7 +128,7 @@ class CreateElection extends React.Component {
120128
</Grid>
121129
<Grid item xs={12}>
122130
<div>
123-
{activeStep === steps.length ? (
131+
{this.state.goToHome ? (
124132
<Redirect to="/admin/home" />
125133
) : (
126134
<Paper className={classes.pageContent} elevation={1}>
@@ -193,7 +201,8 @@ const mapStateToProps = ({ ElectionModel }) => {
193201

194202
const mapActionsToProps = {
195203
createElection,
196-
updateElection
204+
updateElection,
205+
submitElection
197206
};
198207

199208
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(CreateElection));

src/modules/election-model/state/ElectionAction.js

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export const setPostModuleData = (val) => {
1414
}
1515
}
1616

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

2020
let allElectionModuleData = {
21-
"moduleId": electionData.module_id,
21+
"moduleId": "1268362183761283718236",
2222
"divisionCommonName":'Provintial',
2323
"createdBy":'admin',
2424
"createdAt":'',
@@ -85,7 +85,7 @@ export function postCallElectionData(CallElectionData, electionData) {
8585
return function (dispatch) {
8686
const response = axios
8787
.post(
88-
`${API_BASE_URL}/modules/moduleData`,
88+
`${API_BASE_URL}/modules`,
8989
{ ...allElectionModuleData }
9090
)
9191
.then(response => {
@@ -94,7 +94,6 @@ export function postCallElectionData(CallElectionData, electionData) {
9494
}).catch(err => {
9595
console.log(err)
9696
});
97-
// import store from '../store';
9897
}
9998
}
10099

@@ -118,15 +117,97 @@ export const updateElection = function updateElection(election) {
118117
};
119118
}
120119

121-
export const saveElection = function saveElection() {
120+
export const saveElection = function saveElection(election) {
122121

123122
return function (dispatch) {
123+
124124
dispatch({
125-
type: SAVE_ELECTION_MODULE,
125+
type: UPDATE_ELECTION_MODULE,
126126
payload: {}
127127
})
128128
};
129129
}
130130

131+
export const submitElection = function saveElection(election) {
132+
133+
let allElectionModuleData = {
134+
"name": election.name,
135+
"id": "1268362183761283718236",
136+
"divisionCommonName":'Provintial',
137+
"createdBy":'admin',
138+
"createdAt":'',
139+
"updatedAt":'',
140+
"candidateFormConfiguration": [
141+
{
142+
candidateConfigId: '1',
143+
},
144+
{
145+
candidateConfigId: '2',
146+
},
147+
{
148+
candidateConfigId: '3',
149+
},
150+
{
151+
candidateConfigId: '4',
152+
},
153+
],
154+
"supportingDocuments": [
155+
{
156+
supportDocConfigId: '15990459-2ea4-413f-b1f7-29a138fd7a97',
157+
},
158+
{
159+
supportDocConfigId: 'fe2c2d7e-66de-406a-b887-1143023f8e72',
160+
},
161+
{
162+
supportDocConfigId: 'ff4c6768-bdbe-4a16-b680-5fecb6b1f747',
163+
}
164+
],
165+
"divisionConfig":[
166+
{
167+
divisionName: 'Sample',
168+
divisionCode: 'code',
169+
noOfCandidates: '1',
170+
},
171+
{
172+
divisionName: 'Sample3',
173+
divisionCode: 'code',
174+
noOfCandidates: '2',
175+
},
176+
{
177+
divisionName: 'Sample5',
178+
divisionCode: 'code',
179+
noOfCandidates: '3',
180+
}
181+
],
182+
"electionConfig": [
183+
{
184+
electionModuleConfigId: '15990459-2ea4-413f-b1f7-29a138fd7a97',
185+
value:'allowed',
186+
}
187+
],
188+
}
189+
190+
return function (dispatch) {
191+
const response = axios
192+
.post(
193+
`${API_BASE_URL}/election-modules`,
194+
{ ...allElectionModuleData }
195+
)
196+
.then(response => {
197+
console.log("response.data", response.data);
198+
if(response.data){
199+
election.submited = true;
200+
dispatch({
201+
type: UPDATE_ELECTION_MODULE,
202+
payload: election
203+
});
204+
}
205+
}).catch(err => {
206+
console.log(err)
207+
});
208+
}
209+
}
210+
211+
131212

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

0 commit comments

Comments
 (0)