Skip to content
Snippets Groups Projects
notes.js 1.03 KiB
Newer Older
  • Learn to ignore specific revisions
  • Rafael László's avatar
    Rafael László committed
      GET_NOTES_BY_EVENT,
      WRITE_NOTE,
    
    Rafael László's avatar
    Rafael László committed
    import axios from './session';
    
    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);
    
    Rafael László's avatar
    Rafael László committed
    };
    
    Rafael László's avatar
    Rafael László committed
    export const writeNote = (event) => (dispatch) =>
      dispatch({ type: WRITE_NOTE, payload: event.target.value });
    
    Rafael László's avatar
    Rafael László committed
    export const postEventNote = ({ eventid, userid, note }) => async (
      dispatch
    ) => {
      try {
        const response = await axios.post('/api/v1/notes/', {
          event: eventid || '',
          profile: userid || '',
          note,
        });
        if (response.data.id) {
          alert('Sikeres mentés!');
          dispatch({
            type: ADD_EVENT_NOTE,
            payload: response.data,
    
    Rafael László's avatar
    Rafael László committed
      } catch (e) {
        console.log(e);
    
    Rafael László's avatar
    Rafael László committed
    };
    
    export const clearWrite = () => (dispatch) => {
      dispatch({ type: CLEAR_WRITE });
    };