From 97027dc362e5756fa1e94aef1dc1c43664d6f4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chifgeri97@gmail.com> Date: Sat, 5 Jan 2019 21:19:00 +0100 Subject: [PATCH] Add actions to handle visitors of an event --- src/actions/statistics.js | 46 ++++++++++++++++++++++++++++++++++++++- src/actions/types.js | 6 +++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/actions/statistics.js b/src/actions/statistics.js index a694281..5e378a9 100644 --- a/src/actions/statistics.js +++ b/src/actions/statistics.js @@ -1,5 +1,5 @@ import { axios } from './auth'; -import { GET_EVENTS, GET_EVENT_BY_ID } from './types'; +import { GET_EVENTS, GET_EVENT_BY_ID, GET_TRAINEES, VISITOR_CHANGE, GET_NOTES_BY_EVENT } from './types'; export const getEvents = () => ( async (dispatch) => { @@ -28,3 +28,47 @@ export const getEventById = id => ( } } ); + +export const getTrainees = () => ( + async (dispatch) => { + try { + const response = await axios.get('/api/v1/profiles/'); + dispatch({ + type: GET_TRAINEES, + payload: response.data, + }); + } catch (e) { + console.log(e); + } + } +); + +export const visitorChange = visitors => ( + dispatch => (dispatch({ type: VISITOR_CHANGE, payload: visitors })) +); + +export const getNotesByEvent = id => ( + async (dispatch) => { + try { + const response = await axios.get('/api/v1/notes/', { params: { eventID: id } }); + dispatch({ + type: GET_NOTES_BY_EVENT, + payload: response.data, + }); + } catch (e) { + console.log(e); + } + } +); + +export const submitVisitors = ({ id, visitors }) => ( + async () => { + try { + const response = await axios.patch(`/api/v1/events/${id}/`, { + visitors + }); + } catch (e) { + console.log(e); + } + } +); diff --git a/src/actions/types.js b/src/actions/types.js index c551d29..3a3c635 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -13,3 +13,9 @@ export const SELECT_NEWS = 'select_news'; export const GET_EVENTS = 'get_events'; export const GET_EVENT_BY_ID = 'get_event_by_id'; + +export const GET_TRAINEES = 'get_trainees'; +export const GET_TRAINEE_BY_ID = 'get_trainee_by_id'; +export const VISITOR_CHANGE = 'visitor_change'; + +export const GET_NOTES_BY_EVENT = 'get_notes_by_event'; -- GitLab