diff --git a/src/actions/statistics.js b/src/actions/statistics.js index 591057d0af5189e5f734fbc87a04a6dbfc5b8c9e..5f715ae0e0ce683a571b00b3c36f69aa43f76009 100644 --- a/src/actions/statistics.js +++ b/src/actions/statistics.js @@ -8,6 +8,7 @@ import { ADD_EVENT, DELETE_EVENT, GET_TRAINEE_BY_ID, + GET_PROFILES, } from './types'; export const getEvents = () => ( @@ -134,3 +135,17 @@ export const deleteEvent = event => ( console.log(e); } }); + +export const getProfiles = () => ( + async (dispatch) => { + try { + const response = await axios.get('/api/v1/profiles/'); + dispatch({ + type: GET_PROFILES, + payload: response.data, + }); + } catch (e) { + console.log(e); + } + } +); diff --git a/src/actions/types.js b/src/actions/types.js index d98b3229726dabb3b7c5c7963d0306224437ee61..e3986ff5c7a373828f64f91050f7622453a7dc50 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -26,3 +26,5 @@ export const DELETE_EVENT = 'delete_event'; export const WRITE_NOTE = 'write_note'; export const CLEAR_NOTE = 'clear_note'; export const ADD_EVENT_NOTE = 'add_note'; + +export const GET_PROFILES = 'get_profiles'; diff --git a/src/components/pages/Applications.js b/src/components/pages/Applications.js index 563d3ae2ad9ba9c2cf699b523e7f2e85c4f0c336..b6ae6007d20eda175d0ac6b322034fcf50332bf4 100644 --- a/src/components/pages/Applications.js +++ b/src/components/pages/Applications.js @@ -1,25 +1,33 @@ import React, { Component } from 'react'; import moment from 'moment'; import { Link } from 'react-router-dom'; -import { Container, Table, Button } from 'semantic-ui-react'; +import { Container, Table, Icon } from 'semantic-ui-react'; import { connect } from 'react-redux'; -import { getTrainees } from '../../actions/statistics'; +import { getProfiles } from '../../actions/statistics'; class Applications extends Component { componentWillMount() { - this.props.getTrainees(); + this.props.getProfiles(); } renderApplicants() { - return this.props.trainees.map((trainee) => + return this.props.profiles.map((profile) => { return ( <Table.Row> <Table.Cell> - <Link to={`trainee/${trainee.id}`}> - {trainee.full_name} + <Link to={`profile/${profile.id}`}> + {profile.full_name} </Link> </Table.Cell> - <Table.Cell> + <Table.Cell textAlign='center'> + { profile.role === 'Student' ? + <Icon color='green' name='checkmark' /> + : + profile.role === 'Staff' ? + <strong>Staff</strong> + : + <Icon color='red' name='cancel' /> + } </Table.Cell> </Table.Row> ); @@ -43,7 +51,7 @@ class Applications extends Component { </Table.Header> <Table.Body> - {this.props.trainees ? this.renderApplicants() : 'Nincs mĂŠg alaklom beĂrva'} + {this.renderApplicants()} </Table.Body> </Table> </Container> @@ -51,6 +59,6 @@ class Applications extends Component { } } -const mapStateToProps = ({ trainees: { trainees }, user }) => ({ trainees, user }); +const mapStateToProps = ({ trainees: { profiles }, user }) => ({ profiles, user }); -export default connect(mapStateToProps, { getTrainees })(Applications); +export default connect(mapStateToProps, { getProfiles })(Applications); diff --git a/src/reducers/TraineeReducer.js b/src/reducers/TraineeReducer.js index f7fa38e0d7e2645d76da834af90dc272cee159ef..0a3654ed65726a8f2f89cc0918c71d5db6d49008 100644 --- a/src/reducers/TraineeReducer.js +++ b/src/reducers/TraineeReducer.js @@ -1,6 +1,6 @@ -import { GET_TRAINEES, GET_TRAINEE_BY_ID } from '../actions/types'; +import { GET_TRAINEES, GET_TRAINEE_BY_ID, GET_PROFILES } from '../actions/types'; -const INITIAL_STATE = {}; +const INITIAL_STATE = { profiles: [] }; export default (state = INITIAL_STATE, action) => { switch (action.type) { @@ -8,6 +8,8 @@ export default (state = INITIAL_STATE, action) => { return { ...state, trainees: [...action.payload] }; case GET_TRAINEE_BY_ID: return { ...state, selectedTrainee: action.payload }; + case GET_PROFILES: + return { ...state, profiles: [...action.payload] }; default: return state; }