add urls constants file

This commit is contained in:
Ruidy Nemausat 2020-04-24 08:14:46 +02:00
parent 4c2ca94013
commit b94240e5b6
3 changed files with 6 additions and 5 deletions

View file

@ -0,0 +1,2 @@
export const ITEMS = "/api/items";
export const USERS = "/api/users";

View file

@ -1,6 +1,6 @@
import { createSlice } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit";
import axios from "axios"; import axios from "axios";
import { ITEMS_URL } from "./urls"; import * as URL from "../constants/urls";
export const itemSlice = createSlice({ export const itemSlice = createSlice({
name: "item", name: "item",
@ -31,7 +31,7 @@ export const itemSlice = createSlice({
*/ */
export const getItemsAsync = () => async (dispatch) => { export const getItemsAsync = () => async (dispatch) => {
dispatch(setItemsLoading); dispatch(setItemsLoading);
const { data } = await axios.get(ITEMS_URL); const { data } = await axios.get(URL.ITEMS);
dispatch(getItems(data)); dispatch(getItems(data));
}; };
@ -39,7 +39,7 @@ export const getItemsAsync = () => async (dispatch) => {
* Creates a new Item in the db. * Creates a new Item in the db.
*/ */
export const addItemAsync = (name) => async (dispatch) => { export const addItemAsync = (name) => async (dispatch) => {
const { data } = await axios.post(ITEMS_URL, { name }); const { data } = await axios.post(URL.ITEMS, { name });
dispatch(addItem(data)); dispatch(addItem(data));
}; };
@ -47,7 +47,7 @@ export const addItemAsync = (name) => async (dispatch) => {
* Deletes Item _id from the db. * Deletes Item _id from the db.
*/ */
export const deleteItemAsync = (id) => async (dispatch) => { export const deleteItemAsync = (id) => async (dispatch) => {
await axios.delete(`${ITEMS_URL}/${id}`); await axios.delete(`${URL.ITEMS}/${id}`);
dispatch(deleteItem(id)); dispatch(deleteItem(id));
}; };

View file

@ -1 +0,0 @@
export const ITEMS_URL = "/api/items";