Skip to content
Snippets Groups Projects
Select Git revision
  • a1cc904ca77827a5a311b533897024b74433cc60
  • master default protected
  • 2023-ujoncdelutan
  • 2023-update
  • 1.4.7 protected
  • 1.4.6 protected
  • 1.4.5 protected
  • 1.4.4 protected
  • 1.4.3 protected
  • 1.4.2 protected
  • 1.4.1 protected
  • 1.4.0 protected
  • 1.3.19 protected
  • 1.3.18 protected
  • 1.3.17 protected
  • 1.3.16 protected
  • 1.3.15 protected
  • 1.3.14 protected
  • 1.3.13 protected
  • 1.3.12 protected
  • 1.3.10 protected
  • 1.3.11 protected
  • 1.3.9 protected
  • 1.3.8 protected
24 results

EditTaskReducer.js

Blame
  • news.js 2.11 KiB
    import axios from './session';
    import { GET_NEWS, WRITE_NEWS, ADD_NEWS, DELETE_NEWS,
      CLEAR_WRITE, SELECT_NEWS, EDIT_NEWS } from './types';
    
    export const getNews = () => (
      async (dispatch) => {
        try {
          const response = await axios.get('/api/v1/news');
          dispatch({
            type: GET_NEWS,
            payload: response.data,
          });
        } catch (e) {
          console.log(e);
        }
      }
    );
    
    export const postNews = ({ title, author, text }) => (
      async (dispatch) => {
        try {
          const response = await axios.post('/api/v1/news/', {
            author,
            title,
            text,
          });
          if (response.data.id) {
            alert('Sikeres mentés!');
            dispatch({
              type: ADD_NEWS,
              payload: response.data,
            });
          } else {
            alert('Mentés nem sikerült!');
          }
        } catch (e) {
          console.log(e);
        }
      }
    );
    
    export const editNews = ({ id, title, editedBy, text }) => (
      async (dispatch) => {
        try {
          const response = await axios.patch(`/api/v1/news/${id}/`, {
            author: editedBy,
            title,
            text,
          });
          if (response.data.id) {
            alert('Sikeres mentés!');
            dispatch({
              type: EDIT_NEWS,
              payload: response.data,
    
            });
          } else {
            alert('Mentés nem sikerült!');
          }
        } catch (e) {
          console.log(e);
        }
      }
    );
    
    export const deleteNews = news => (
      async (dispatch) => {
        try {
          const response = await axios.delete(`/api/v1/news/${news.id}/`);
          if (!response.data.id) {
            alert('Sikeres törlés!');
            dispatch({
              type: DELETE_NEWS,
              payload: news,
            });
          } else {
            alert('A törlés nem sikerült!');
          }
        } catch (e) {
          console.log(e);
        }
      });
    
    export const writeNews = ({ target: { name, value } }) => (
      (dispatch) => {
        dispatch({ type: WRITE_NEWS, payload: value, target: name });
      }
    );
    
    export const clearWrite = () => (
      (dispatch) => {
        dispatch({ type: CLEAR_WRITE });
      }
    );
    
    export const setSelectedNews = item => (
      (dispatch) => {
        dispatch({ type: SELECT_NEWS, payload: item });
      }
    );