From 330fa3b40f18228cde26d3973e1298bccd442dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chifgeri97@gmail.com> Date: Wed, 23 Jan 2019 11:30:03 +0100 Subject: [PATCH] Handle status change in trainee reducer --- src/actions/statistics.js | 7 ++++++- src/actions/types.js | 2 +- src/components/pages/Applications.js | 2 +- src/reducers/TraineeReducer.js | 9 ++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/actions/statistics.js b/src/actions/statistics.js index 719fad4..9fb205e 100644 --- a/src/actions/statistics.js +++ b/src/actions/statistics.js @@ -8,7 +8,8 @@ import { ADD_EVENT, DELETE_EVENT, GET_PROFILES, - GET_SELECTED_PROFILE + GET_SELECTED_PROFILE, + SET_STATUS, } from './types'; export const getEvents = () => ( @@ -143,6 +144,10 @@ export const setStatus = (id, status) => ( role: status, }); if (response.data.id) { + dispatch({ + type: SET_STATUS, + payload: response.data, + }); } } catch (e) { console.log(e); diff --git a/src/actions/types.js b/src/actions/types.js index 5da1013..70b3b99 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -27,5 +27,5 @@ export const CLEAR_NOTE = 'clear_note'; export const ADD_EVENT_NOTE = 'add_note'; export const GET_PROFILES = 'get_profiles'; -export const SET_STAFF = 'set_staff'; +export const SET_STATUS = 'set_status'; export const GET_SELECTED_PROFILE = 'get_selected_profile'; diff --git a/src/components/pages/Applications.js b/src/components/pages/Applications.js index ce66eb2..93761d8 100644 --- a/src/components/pages/Applications.js +++ b/src/components/pages/Applications.js @@ -72,7 +72,7 @@ class Applications extends Component { <Table.Header> <Table.Row> <Table.HeaderCell>Jelentkezettek</Table.HeaderCell> - <Table.HeaderCell>JelentkezĂŠs elfogadva:</Table.HeaderCell> + <Table.HeaderCell textAlign='center'>JelentkezĂŠs stĂĄtusza:</Table.HeaderCell> <Table.HeaderCell /> </Table.Row> </Table.Header> diff --git a/src/reducers/TraineeReducer.js b/src/reducers/TraineeReducer.js index e7696a2..06f01ec 100644 --- a/src/reducers/TraineeReducer.js +++ b/src/reducers/TraineeReducer.js @@ -1,4 +1,4 @@ -import { GET_TRAINEES, GET_PROFILES, GET_SELECTED_PROFILE } from '../actions/types'; +import { GET_TRAINEES, GET_PROFILES, GET_SELECTED_PROFILE, SET_STATUS } from '../actions/types'; const INITIAL_STATE = { profiles: [], selectedProfile: {} }; @@ -10,6 +10,13 @@ export default (state = INITIAL_STATE, action) => { return { ...state, profiles: [...action.payload] }; case GET_SELECTED_PROFILE: return { ...state, selectedProfile: action.payload }; + case SET_STATUS: + const index = state.profiles.findIndex(item => item.id === action.payload.id); + state.profiles.splice(index, 1, action.payload); + if (action.payload.id === state.selectedProfile.id) { + return { ...state, selectedProfile: action.payload }; + } + return { ...state, profiles: [...state.profiles] } default: return state; } -- GitLab