From 683001d8fbe27e9bfbcdf7117e7b86be2f25b6ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chifgeri97@gmail.com>
Date: Mon, 21 Jan 2019 20:56:42 +0100
Subject: [PATCH] Add action to get all profile, display who was accepted

---
 src/actions/statistics.js            | 15 +++++++++++++++
 src/actions/types.js                 |  2 ++
 src/components/pages/Applications.js | 28 ++++++++++++++++++----------
 src/reducers/TraineeReducer.js       |  6 ++++--
 4 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/src/actions/statistics.js b/src/actions/statistics.js
index 591057d..5f715ae 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 d98b322..e3986ff 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 563d3ae..b6ae600 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 f7fa38e..0a3654e 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;
   }
-- 
GitLab