Skip to content

Commit 155b8e0

Browse files
authored
Merge pull request #287 from YujithIsura/master
backend validation added for party delete
2 parents 71a5540 + 225f5d4 commit 155b8e0

File tree

7 files changed

+120
-16
lines changed

7 files changed

+120
-16
lines changed

client/src/components/AddParty/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const styles = theme => ({
5454
marginBottom: 20,
5555
marginTop: 50
5656
},
57+
logocontainer: {
58+
height: '100%',
59+
marginTop:-55
60+
},
5761
});
5862

5963
class PartyRegistration extends React.Component {
@@ -540,8 +544,10 @@ class PartyRegistration extends React.Component {
540544
<span ><FileUpload value={this.state.paySlip} doneElement={doneElement} onSelectFiles={this.onSelectFiles} /></span>
541545
</span>
542546
</Grid>
543-
<Grid style={{marginTop:30,marginLeft:-10}}container item lg={4}>
544-
<img src={this.state.file}/>
547+
<Grid style={{marginTop:30,marginLeft:-10}} container item lg={4}>
548+
<div className={classes.logocontainer} >
549+
<img style={{maxWidth: 60,margin:25}} src={this.state.file}/>
550+
</div>
545551
</Grid>
546552
</Grid>
547553

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { withStyles } from '@material-ui/core/styles';
4+
import AppBar from '@material-ui/core/AppBar';
5+
import Tabs from '@material-ui/core/Tabs';
6+
import Tab from '@material-ui/core/Tab';
7+
import Typography from '@material-ui/core/Typography';
8+
9+
10+
function TabContainer(props) {
11+
return (
12+
<Typography component="div" style={{ padding: 8 * 3 }}>
13+
{props.children}
14+
</Typography>
15+
);
16+
}
17+
18+
TabContainer.propTypes = {
19+
children: PropTypes.node.isRequired,
20+
};
21+
22+
const styles = theme => ({
23+
root: {
24+
flexGrow: 1,
25+
width: '100%',
26+
backgroundColor: theme.palette.background.paper,
27+
},
28+
tabs: {
29+
backgroundColor: '#dcdfe5',
30+
}
31+
});
32+
33+
class ScrollableTabsButtonAuto extends React.Component {
34+
state = {
35+
value: 0,
36+
};
37+
38+
handleChange = (event, value) => {
39+
this.setState({ value });
40+
};
41+
42+
render() {
43+
const { classes , customProps ,onCloseModal,callElectionPendingElements,callElectionRejectedElements,callElectionApproveElements } = this.props;
44+
const { value } = this.state;
45+
46+
return (
47+
<div className={classes.root}>
48+
<AppBar style={{color:'black'}} position="static" >
49+
<Tabs
50+
classes={{flexContainer: classes.tabs}}
51+
value={value}
52+
onChange={this.handleChange}
53+
// indicatorColor="primary"
54+
// textColor="primary"
55+
scrollable
56+
scrollButtons="auto"
57+
>
58+
<Tab label="Pending Templates" />
59+
<Tab label="Approved Templates" />
60+
<Tab label="Rejected Templates" />
61+
62+
63+
</Tabs>
64+
</AppBar>
65+
{value === 0 && <TabContainer>{callElectionPendingElements}</TabContainer>}
66+
{value === 1 && <TabContainer>{callElectionApproveElements}</TabContainer>}
67+
{value === 2 && <TabContainer>{callElectionRejectedElements}</TabContainer>}
68+
69+
70+
</div>
71+
);
72+
73+
}
74+
}
75+
76+
ScrollableTabsButtonAuto.propTypes = {
77+
classes: PropTypes.object.isRequired,
78+
};
79+
80+
export default withStyles(styles)(ScrollableTabsButtonAuto);

client/src/components/UpdateParty/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ class PartyRegistration extends React.Component {
105105

106106

107107
handleChange = (name) => event => {
108-
debugger;
109108
if (name === 'phone') {
110109
this.setState({ errorTextPhone: '' });
111110
}
@@ -178,7 +177,6 @@ class PartyRegistration extends React.Component {
178177
this.setState({ errorTextSecretaryName: 'emptyField' });
179178
goNext = false;
180179
}
181-
debugger;
182180

183181
if (this.state.phoneList.length === 0 || this.state.phoneList.length === null) {
184182
this.setState({ errorTextPhone: 'emptyField' });
@@ -189,7 +187,6 @@ class PartyRegistration extends React.Component {
189187
this.setState({ errorTextFax: 'emptyField' });
190188
goNext = false;
191189
}
192-
debugger;
193190
if (goNext) {
194191
updateParty(this.state.partyId,this.state);
195192
onCloseModal();
@@ -305,7 +302,6 @@ debugger;
305302
}else{
306303
var faxList = [];
307304
}
308-
debugger;
309305
getPartyLogo(PartyDetails.fileName);
310306
this.setState({partyName:PartyDetails.partyName});
311307
this.setState({partyType:PartyDetails.partyType});

client/src/modules/election-model/Template_review.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import { withStyles } from '@material-ui/core/styles';
44
import AdminMenu from '../../components/AdminMenu/AdminMenu';
5-
import CallElectionList from '../../components/CallElectionList';
5+
import ElectionTemplateList from '../../components/ElectionTemplateList';
66
import CallElection from '../../modules/election/CallElection';
77
import Typography from '@material-ui/core/Typography';
88
import Grid from '@material-ui/core/Grid';
@@ -266,7 +266,7 @@ class Home extends React.Component {
266266

267267
<Grid item xs={8} >
268268
<div style={{ width: '100%' }}>
269-
<CallElectionList callElectionApproveElements={callElectionApproveElements} callElectionPendingElements={callElectionPendingElements} callElectionRejectedElements={callElectionRejectedElements}></CallElectionList>
269+
<ElectionTemplateList callElectionApproveElements={callElectionApproveElements} callElectionPendingElements={callElectionPendingElements} callElectionRejectedElements={callElectionRejectedElements}></ElectionTemplateList>
270270
</div>
271271
</Grid>
272272
<Grid item xs={5} >

client/src/modules/party/state/PartyAction.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function saveParty(partyDetails) {
7979
dispatch(setData(newPartyData));
8080
dispatch(openSnackbar({ message:`New party has been registered successfully!`}));
8181
}).catch(err => {
82+
dispatch(openSnackbar({ message: err.response.data.message }));
8283
console.log(err)
8384
});
8485
};
@@ -125,6 +126,7 @@ export function updateParty(teamId,partyDetails) {
125126
dispatch(setUpdateData(newPartyData));
126127
dispatch(openSnackbar({ message:`The party has been updated successfully!`}));
127128
}).catch(err => {
129+
dispatch(openSnackbar({ message: err.response.data.message }));
128130
console.log(err)
129131
});
130132
};
@@ -173,7 +175,7 @@ export function deleteParty(teamId) {
173175
dispatch(
174176
setDeleteParty(getDeletedParty)
175177
);
176-
dispatch(openSnackbar({ message: "Candidate was deleted successfully!"}));
178+
dispatch(openSnackbar({ message: "Party was deleted successfully!"}));
177179
}).catch(err => {
178180
const getDeletedParty = [];
179181
dispatch(

server/src/repository/team.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ const updateTeamStatus = (partyId) => {
144144
});
145145
};
146146

147+
const TEAM_SELECT_QUERY_FROM_NOMINATION = `SELECT * FROM NOMINATION WHERE TEAM_ID=:team_id`;
148+
149+
const teamValidation = (team_id) => {
150+
const params = { team_id: team_id };
151+
return DbConnection()
152+
.query(TEAM_SELECT_QUERY_FROM_NOMINATION,
153+
{
154+
replacements: params,
155+
type: DbConnection().QueryTypes.SELECT,
156+
}).catch((error) => {
157+
throw new DBError(error);
158+
});
159+
};
147160

148161

149162

@@ -153,5 +166,6 @@ export default {
153166
fetchAllTeamsByTeamType,
154167
insertTeam,
155168
updateTeam,
156-
updateTeamStatus
169+
updateTeamStatus,
170+
teamValidation
157171
}

server/src/service/teamService.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ServerError , ApiError } from 'Errors';
22
import TeamRepo from '../repository/team';
33
import {TeamManager} from 'Managers';
44
import _ from 'lodash';
5-
import {HTTP_CODE_404} from '../routes/constants/HttpCodes';
5+
import {HTTP_CODE_404,HTTP_CODE_403} from '../routes/constants/HttpCodes';
66
const uuidv4 = require('uuid/v4');
77

88

@@ -99,7 +99,7 @@ const createTeam = async (req) => {
9999
await TeamRepo.insertTeam(teamData);
100100
return teamData;
101101
} catch (e) {
102-
throw new ServerError("server error");
102+
throw e;
103103
}
104104
};
105105

@@ -148,18 +148,24 @@ const updateTeamById = async (req) => {
148148
await TeamRepo.updateTeam(teamData);
149149
return teamData;
150150
} catch (e) {
151-
throw new ServerError("server error");
151+
throw e;
152152
}
153153
};
154154

155155
//Delete party details for a particular party
156156
const deletePartyById = async (req) => {
157157
try {
158158
const partyId = req.params.teamId;
159-
await TeamRepo.updateTeamStatus(partyId);
160-
return partyId;
159+
const partyExist = await TeamRepo.teamValidation(partyId);
160+
if(_.isEmpty(partyExist)){
161+
await TeamRepo.updateTeamStatus(partyId);
162+
return partyId;
163+
}else{
164+
throw new ApiError("Sorry, This party already been used!",HTTP_CODE_403);
165+
}
166+
161167
} catch (e) {
162-
throw new ServerError("server error");
168+
throw e;
163169
}
164170
};
165171

0 commit comments

Comments
 (0)