From b94240e5b68ceb79dd4d53c336f16b7d39731873 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Fri, 24 Apr 2020 08:14:46 +0200 Subject: [PATCH] add urls constants file --- client/src/constants/urls.js | 2 ++ client/src/store/itemSlice.js | 8 ++++---- client/src/store/urls.js | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 client/src/constants/urls.js delete mode 100644 client/src/store/urls.js diff --git a/client/src/constants/urls.js b/client/src/constants/urls.js new file mode 100644 index 0000000..9594ee0 --- /dev/null +++ b/client/src/constants/urls.js @@ -0,0 +1,2 @@ +export const ITEMS = "/api/items"; +export const USERS = "/api/users"; diff --git a/client/src/store/itemSlice.js b/client/src/store/itemSlice.js index 8d95add..0a43f62 100644 --- a/client/src/store/itemSlice.js +++ b/client/src/store/itemSlice.js @@ -1,6 +1,6 @@ import { createSlice } from "@reduxjs/toolkit"; import axios from "axios"; -import { ITEMS_URL } from "./urls"; +import * as URL from "../constants/urls"; export const itemSlice = createSlice({ name: "item", @@ -31,7 +31,7 @@ export const itemSlice = createSlice({ */ export const getItemsAsync = () => async (dispatch) => { dispatch(setItemsLoading); - const { data } = await axios.get(ITEMS_URL); + const { data } = await axios.get(URL.ITEMS); dispatch(getItems(data)); }; @@ -39,7 +39,7 @@ export const getItemsAsync = () => async (dispatch) => { * Creates a new Item in the db. */ 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)); }; @@ -47,7 +47,7 @@ export const addItemAsync = (name) => async (dispatch) => { * Deletes Item _id from the db. */ export const deleteItemAsync = (id) => async (dispatch) => { - await axios.delete(`${ITEMS_URL}/${id}`); + await axios.delete(`${URL.ITEMS}/${id}`); dispatch(deleteItem(id)); }; diff --git a/client/src/store/urls.js b/client/src/store/urls.js deleted file mode 100644 index e76fda6..0000000 --- a/client/src/store/urls.js +++ /dev/null @@ -1 +0,0 @@ -export const ITEMS_URL = "/api/items";