From a894f3c840c2c9ee5648816ad59e51f712fe2145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chif=20Gerg=C5=91?= <chifgeri97@gmail.com> Date: Thu, 17 Jan 2019 14:23:00 +0100 Subject: [PATCH] Create actions to create notes for events, move note actions to notes.js --- src/actions/notes.js | 43 +++++++++++++++++++++++++++++++++++++++ src/actions/statistics.js | 14 ------------- src/actions/types.js | 4 ++++ 3 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 src/actions/notes.js diff --git a/src/actions/notes.js b/src/actions/notes.js new file mode 100644 index 0000000..79242e8 --- /dev/null +++ b/src/actions/notes.js @@ -0,0 +1,43 @@ +import axios from './session'; +import { + GET_NOTES_BY_EVENT, + WRITE_NOTE, + ADD_NOTE, +} from './types'; + +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 writeNote = (event) => { + return (dispatch => (dispatch({ type: WRITE_NOTE, payload: event.target.value }))); +}; + +export const postEventNote = ({ eventid, userid, note }) => ( + async (dispatch) => { + try { + const response = await axios.post('/api/v1/note/', { + event: eventid ? eventid : '', + user: userid ? eventid : '', + note, + }); + if (response.data.id) { + alert('Sikeres mentĂŠs!'); + dispatch({ + type: ADD_EVENT_NOTE, + payload: response.data, + }); + } catch (e) { + console.log(e); + } + }); diff --git a/src/actions/statistics.js b/src/actions/statistics.js index 17aab14..c23ee3a 100644 --- a/src/actions/statistics.js +++ b/src/actions/statistics.js @@ -71,20 +71,6 @@ export const visitorChange = ({ id }) => { return (dispatch => (dispatch({ type: VISITOR_CHANGE, payload: id }))); }; -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 { diff --git a/src/actions/types.js b/src/actions/types.js index f83ddba..d98b322 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -22,3 +22,7 @@ export const GET_NOTES_BY_EVENT = 'get_notes_by_event'; export const WRITE_EVENT = 'write_event'; export const ADD_EVENT = 'add_event'; 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'; -- GitLab