diff --git a/src/actions/statistics.js b/src/actions/statistics.js index 2d8023bd0879acece48dacebde9da809ea1dc58d..f52e6ff6d33173bda30f6a71af9107b663d30c03 100644 --- a/src/actions/statistics.js +++ b/src/actions/statistics.js @@ -2,7 +2,8 @@ import axios from './session'; import { GET_EVENTS, GET_EVENT_BY_ID, - GET_TRAINEES, VISITOR_CHANGE, + GET_TRAINEES, + VISITOR_CHANGE, GET_NOTES_BY_EVENT, WRITE_EVENT, ADD_EVENT, @@ -51,9 +52,9 @@ export const getTrainees = () => ( } ); -export const visitorChange = visitors => ( - dispatch => (dispatch({ type: VISITOR_CHANGE, payload: visitors })) -); +export const visitorChange = ({ id }) => { + return (dispatch => (dispatch({ type: VISITOR_CHANGE, payload: id }))); +}; export const getNotesByEvent = id => ( async (dispatch) => { diff --git a/src/reducers/EventReducer.js b/src/reducers/EventReducer.js index b082c05aa0630d181c171e11f52bab9eb670cbae..0766ddda7af07dc775f6b45087b8ccbd5b9b7ea8 100644 --- a/src/reducers/EventReducer.js +++ b/src/reducers/EventReducer.js @@ -16,7 +16,25 @@ export default (state = INITIAL_STATE, action) => { case GET_EVENT_BY_ID: return { ...state, selectedEvent: action.payload }; case VISITOR_CHANGE: - return { ...state, selectedEvent: { ...state.selectedEvent, visitors: action.payload } }; + const index = state.selectedEvent.visitors.indexOf(action.payload); + if (index !== -1) { + state.selectedEvent.visitors.splice(index, 1); + return { + ...state, + selectedEvent: { + ...state.selectedEvent, + visitors: state.selectedEvent.visitors, + }, + }; + } + state.selectedEvent.visitors.push(action.payload) + return { + ...state, + selectedEvent: { + ...state.selectedEvent, + visitors: state.selectedEvent.visitors, + }, + }; case WRITE_EVENT: return { ...state, newEvent: { ...state.newEvent, [action.target]: action.payload } }; case ADD_EVENT: