Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Commit

Permalink
Display number of other applications
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrohee committed Jul 7, 2017
1 parent 532dfb6 commit 0b07040
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client/src/actions/applicationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ export function getPepiteApplication() {
}
}

export function getOtherApplication(id) {
return (dispatch, getState) => {
const {user} = getState()
return applicationApi.getOtherApplication(id, user.token)
}
}

export function getPepiteApplicationXls() {
return (dispatch, getState) => {
const {user} = getState()
Expand Down
15 changes: 15 additions & 0 deletions client/src/api/applicationApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ class applicationApi {
})
}

static getOtherApplication(id, userToken) {
return axios.get(`/application/${id}/other`,
{
'headers': {
'Authorization': `Bearer ${userToken}`
}
})
.then((res) => {
return res.data
})
.catch((err) => {
throw new Error('La candidature que vous cherchez n\'existe pas')
})
}

static saveApplication(application) {
return axios.post('/application', application)
.then((res) => {
Expand Down
45 changes: 45 additions & 0 deletions client/src/components/pepite/Applicant/OtherApplicationLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import * as applicationActions from '../../../actions/applicationActions'

class OtherApplicationLabel extends React.Component {
constructor(props, context) {
super(props, context)
this.state = {
otherApplications: []
}

this.props.actions.getOtherApplication(props.applicantId).then(otherApplications => {
this.setState({
otherApplications
})
})
}

render() {
return (
<div>
<span className="badge">{this.state.otherApplications.length}</span>
</div>
)
}
}

function mapStateToProps(state, ownProps) {
return {
}
}

function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(applicationActions, dispatch),
}
}

OtherApplicationLabel.propTypes = {
actions: PropTypes.object.isRequired,
applicantId: PropTypes.string.isRequired
}

export default connect(mapStateToProps, mapDispatchToProps)(OtherApplicationLabel)
2 changes: 2 additions & 0 deletions client/src/components/pepite/Applicant/PepiteApplicantRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Glyphicon } from 'react-bootstrap'
import GraduationLabel from './GraduationLabel'
import { Link } from 'react-router'
import TimeSinceControl from './TimeSinceControl'
import OtherApplicationLabel from './OtherApplicationLabel'

const PepiteApplicantRow = ({ application }) => {
return (
Expand All @@ -16,6 +17,7 @@ const PepiteApplicantRow = ({ application }) => {
<td><GraduationLabel application={application} /></td>
<td><a className="btn btn-info btn-xs" target="_blank" href={`/application/${application._id}/print`}><Glyphicon glyph="print" /></a></td>
<td><Link to={`/pepite/committeeAnswer/${application._id}`} className="btn btn-info btn-xs"><Glyphicon glyph="edit" /></Link></td>
<td><OtherApplicationLabel applicantId={application._id} /></td>
</tr>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class PepiteApplicantTable extends React.Component {
<th>Statut</th>
<th>Version imprimable</th>
<th>Comité d'engagement</th>
<th>Autres candidatures</th>
</tr>
</thead>
<tbody>
Expand Down

0 comments on commit 0b07040

Please sign in to comment.