From d6f43684560b655fbfcfe3a93a13f6fbc7ffaa8d Mon Sep 17 00:00:00 2001 From: JaberHPranto Date: Thu, 28 Oct 2021 21:54:10 +0600 Subject: [PATCH] update base url for frontend --- client/src/redux/actions/blogActions.js | 7 ++++--- client/src/redux/actions/cartActions.js | 8 ++++---- client/src/redux/actions/orderActions.js | 19 ++++++++++--------- client/src/redux/actions/productActions.js | 10 ++++++---- client/src/redux/actions/userActions.js | 14 ++++++++------ 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/client/src/redux/actions/blogActions.js b/client/src/redux/actions/blogActions.js index 38231bc..ce0be2a 100644 --- a/client/src/redux/actions/blogActions.js +++ b/client/src/redux/actions/blogActions.js @@ -2,12 +2,13 @@ import axios from "axios" import { BLOG_DETAILS_REQUEST, BLOG_DETAILS_SUCCESS, BLOG_FETCH_FAIL, BLOG_FETCH_REQUEST, BLOG_FETCH_SUCCESS } from "../../constants/blogConstant" import { PRODUCT_DETAILS_FAIL } from "../../constants/productConstants" +const baseUrl = 'https://plantland.herokuapp.com' // @ GET blogs export const fetchBlogs = () => async (dispatch) => { try { dispatch({ type:BLOG_FETCH_REQUEST}) - const { data } = await axios.get(`/api/blogs`) + const { data } = await axios.get(`${baseUrl}/api/blogs`) dispatch({ type: BLOG_FETCH_SUCCESS, @@ -28,7 +29,7 @@ export const fetchBlogById = (id) => async (dispatch) => { try { dispatch({ type: BLOG_DETAILS_REQUEST }) - const { data } = await axios.get(`/api/blogs/${id}`) + const { data } = await axios.get(`${baseUrl}/api/blogs/${id}`) dispatch({ type: BLOG_DETAILS_SUCCESS, payload: data @@ -62,7 +63,7 @@ export const createBlog = (blogData) => async (dispatch,getState) => { } } - const { data } = await axios.post(`/api/blogs`,blogData,config) + const { data } = await axios.post(`${baseUrl}/api/blogs`,blogData,config) console.log(data); // dispatch({ diff --git a/client/src/redux/actions/cartActions.js b/client/src/redux/actions/cartActions.js index ce011ad..f5ef3fa 100644 --- a/client/src/redux/actions/cartActions.js +++ b/client/src/redux/actions/cartActions.js @@ -1,14 +1,14 @@ import axios from "axios"; import { CART_ADD_ITEM, - CART_REMOVE_ITEM, - CART_SAVE_SHIPPING_ADDRESS, - CART_SAVE_PAYMENT_METHOD, + CART_REMOVE_ITEM, CART_SAVE_PAYMENT_METHOD, CART_SAVE_SHIPPING_ADDRESS } from "../../constants/cartConstants"; +const baseUrl = 'https://plantland.herokuapp.com' + export const addToCart = (id, qty) => async (dispatch, getState) => { try { - const { data } = await axios.get(`/api/products/${id}`); + const { data } = await axios.get(`${baseUrl}/api/products/${id}`); dispatch({ type: CART_ADD_ITEM, diff --git a/client/src/redux/actions/orderActions.js b/client/src/redux/actions/orderActions.js index 60b9706..9e24e55 100644 --- a/client/src/redux/actions/orderActions.js +++ b/client/src/redux/actions/orderActions.js @@ -1,8 +1,9 @@ import axios from "axios"; import { - ORDER_CREATE_FAIL, ORDER_CREATE_REQUEST, ORDER_CREATE_SUCCESS, ORDER_DATA_FAIL, ORDER_DATA_REQUEST, ORDER_DATA_SUCCESS, ORDER_DELIVER_FAIL, ORDER_DELIVER_REQUEST, ORDER_DELIVER_SUCCESS, ORDER_DETAILS_FAIL, ORDER_DETAILS_REQUEST, ORDER_DETAILS_SUCCESS, ORDER_LIST_FAIL, ORDER_LIST_REQUEST, ORDER_LIST_SUCCESS, ORDER_MY_LIST_FAIL, ORDER_MY_LIST_REQUEST, ORDER_MY_LIST_SUCCESS, ORDER_PAY_FAIL, ORDER_PAY_REQUEST, ORDER_PAY_SUCCESS, ORDER_SALE_DATA_FAIL, ORDER_SALE_DATA_REQUEST, ORDER_SALE_DATA_SUCCESS + ORDER_CREATE_FAIL, ORDER_CREATE_REQUEST, ORDER_CREATE_SUCCESS, ORDER_DATA_FAIL, ORDER_DATA_REQUEST, ORDER_DATA_SUCCESS, ORDER_DELIVER_FAIL, ORDER_DELIVER_REQUEST, ORDER_DELIVER_SUCCESS, ORDER_DETAILS_FAIL, ORDER_DETAILS_REQUEST, ORDER_DETAILS_SUCCESS, ORDER_LIST_FAIL, ORDER_LIST_REQUEST, ORDER_LIST_SUCCESS, ORDER_MY_LIST_FAIL, ORDER_MY_LIST_REQUEST, ORDER_MY_LIST_SUCCESS, ORDER_PAY_FAIL, ORDER_PAY_REQUEST, ORDER_PAY_SUCCESS, ORDER_SALE_DATA_FAIL, ORDER_SALE_DATA_REQUEST, ORDER_SALE_DATA_SUCCESS } from "../../constants/orderConstants"; +const baseUrl = 'https://plantland.herokuapp.com' export const createOrder = (order) => async (dispatch, getState) => { try { @@ -21,7 +22,7 @@ export const createOrder = (order) => async (dispatch, getState) => { }, }; - const { data } = await axios.post(`/api/orders`, order, config); + const { data } = await axios.post(`${baseUrl}/api/orders`, order, config); dispatch({ type: ORDER_CREATE_SUCCESS, @@ -69,7 +70,7 @@ export const getOrderList = () => async (dispatch,getState) => { } } - const { data } = await axios.get(`/api/orders`,config) + const { data } = await axios.get(`${baseUrl}/api/orders`,config) dispatch({ type: ORDER_LIST_SUCCESS, @@ -105,7 +106,7 @@ export const getMyOrders = () => async (dispatch,getState) => { } } - const { data } = await axios.get(`/api/orders/my-orders`,config) + const { data } = await axios.get(`${baseUrl}/api/orders/my-orders`,config) dispatch({ type: ORDER_MY_LIST_SUCCESS, @@ -144,7 +145,7 @@ export const getOrderDetails = (id) => async (dispatch,getState) => { } - const { data } = await axios.get(`/api/orders/${id}`,config) + const { data } = await axios.get(`${baseUrl}/api/orders/${id}`,config) dispatch({ type: ORDER_DETAILS_SUCCESS, payload:data @@ -179,7 +180,7 @@ export const payOrder = (id,paymentResult) => async (dispatch,getState) => { } - const { data } = await axios.put(`/api/orders/${id}/pay`,paymentResult,config) + const { data } = await axios.put(`${baseUrl}/api/orders/${id}/pay`,paymentResult,config) console.log(data); dispatch({ @@ -217,7 +218,7 @@ export const deliverOrder = (order) => async (dispatch,getState) => { } - const { data } = await axios.put(`/api/orders/${order._id}/deliver`,{},config) + const { data } = await axios.put(`${baseUrl}/api/orders/${order._id}/deliver`,{},config) console.log(data); dispatch({ @@ -256,7 +257,7 @@ export const getOrderData = () => async (dispatch,getState) => { } } - const { data } = await axios.get(`/api/orders/order-data`, config) + const { data } = await axios.get(`${baseUrl}/api/orders/order-data`, config) dispatch({ type: ORDER_DATA_SUCCESS, @@ -293,7 +294,7 @@ export const getSaleData = () => async (dispatch,getState) => { } } - const { data } = await axios.get(`/api/orders/saleDataByYear`, config) + const { data } = await axios.get(`${baseUrl}/api/orders/saleDataByYear`, config) dispatch({ type: ORDER_SALE_DATA_SUCCESS, diff --git a/client/src/redux/actions/productActions.js b/client/src/redux/actions/productActions.js index 8f84153..09b0f58 100644 --- a/client/src/redux/actions/productActions.js +++ b/client/src/redux/actions/productActions.js @@ -1,12 +1,14 @@ import axios from 'axios'; import { PRODUCT_CREATE_FAIL, PRODUCT_CREATE_REQUEST, PRODUCT_CREATE_REVIEW_FAIL, PRODUCT_CREATE_REVIEW_REQUEST, PRODUCT_CREATE_REVIEW_SUCCESS, PRODUCT_CREATE_SUCCESS, PRODUCT_DELETE_FAIL, PRODUCT_DELETE_REQUEST, PRODUCT_DELETE_SUCCESS, PRODUCT_DETAILS_FAIL, PRODUCT_DETAILS_REQUEST, PRODUCT_DETAILS_SUCCESS, PRODUCT_LIST_FAIL, PRODUCT_LIST_REQUEST, PRODUCT_LIST_SUCCESS, PRODUCT_UPDATE_FAIL, PRODUCT_UPDATE_REQUEST, PRODUCT_UPDATE_SUCCESS } from '../../constants/productConstants'; +const baseUrl = 'https://plantland.herokuapp.com' + // @ GET products export const fetchProducts = (keyword='',pageNumber='',category='',sort='') => async (dispatch) => { try { dispatch({ type: PRODUCT_LIST_REQUEST }) - const { data } = await axios.get(`/api/products?category=${category}&keyword=${keyword}&pageNumber=${pageNumber}&sort=${sort}`) + const { data } = await axios.get(`${baseUrl}/api/products?category=${category}&keyword=${keyword}&pageNumber=${pageNumber}&sort=${sort}`) dispatch({ type: PRODUCT_LIST_SUCCESS, @@ -30,7 +32,7 @@ export const fetchProductById = (id) => async (dispatch) => { dispatch({ type: PRODUCT_DETAILS_REQUEST }) - const { data } = await axios.get(`/api/products/${id}`) + const { data } = await axios.get(`${baseUrl}/api/products/${id}`) dispatch({ type: PRODUCT_DETAILS_SUCCESS, payload: data @@ -60,7 +62,7 @@ export const createProductReview = (productId,review) => async (dispatch,getStat } } - await axios.post(`/api/products/${productId}/reviews`,review,config) + await axios.post(`${baseUrl}/api/products/${productId}/reviews`,review,config) dispatch({ type: PRODUCT_CREATE_REVIEW_SUCCESS, @@ -95,7 +97,7 @@ export const deleteProduct = (id) => async (dispatch,getState) => { } } - await axios.delete(`/api/products/${id}`,config) + await axios.delete(`${baseUrl}/api/products/${id}`,config) dispatch({ type: PRODUCT_DELETE_SUCCESS, diff --git a/client/src/redux/actions/userActions.js b/client/src/redux/actions/userActions.js index 0f75899..b0d3f97 100644 --- a/client/src/redux/actions/userActions.js +++ b/client/src/redux/actions/userActions.js @@ -1,6 +1,8 @@ import axios from 'axios' import { USER_DELETE_FAIL, USER_DELETE_REQUEST, USER_DELETE_SUCCESS, USER_DETAILS_FAIL, USER_DETAILS_REQUEST, USER_DETAILS_SUCCESS, USER_LIST_FAIL, USER_LIST_REQUEST, USER_LIST_RESET, USER_LIST_SUCCESS, USER_LOGIN_FAIL, USER_LOGIN_REQUEST, USER_LOGIN_SUCCESS, USER_LOGOUT, USER_PROFILE_UPDATE_FAIL, USER_PROFILE_UPDATE_REQUEST, USER_PROFILE_UPDATE_SUCCESS, USER_REGISTER_FAIL, USER_REGISTER_REQUEST, USER_REGISTER_SUCCESS } from '../../constants/userConstants' +const baseUrl = 'https://plantland.herokuapp.com' + export const login = (email,password) => async (dispatch) => { try { @@ -14,7 +16,7 @@ export const login = (email,password) => async (dispatch) => { } } - const { data } = await axios.post('/api/users/login', + const { data } = await axios.post(`${baseUrl}/api/users/login`, {email, password },config) dispatch({ @@ -85,7 +87,7 @@ export const register = (name,email,password,confirmPassword) => async (dispatch } } - const { data } = await axios.post('/api/users/register', + const { data } = await axios.post(`${baseUrl}/api/users/register`, {name,email,password,confirmPassword},config) dispatch({ @@ -123,7 +125,7 @@ export const getUserDetails = (id) => async (dispatch,getState) => { } } - const { data } = await axios.get(`api/users/${id}`, config) + const { data } = await axios.get(`${baseUrl}/api/users/${id}`, config) dispatch({ type: USER_DETAILS_SUCCESS, @@ -160,7 +162,7 @@ export const updateUserProfile = (user) => async (dispatch,getState) => { } } - const { data } = await axios.put(`api/users/profile`,user, config) + const { data } = await axios.put(`${baseUrl}/api/users/profile`,user, config) console.log(data); @@ -199,7 +201,7 @@ export const getUserList = () => async (dispatch,getState) => { } } - const { data } = await axios.get(`/api/users`,config) + const { data } = await axios.get(`${baseUrl}/api/users`,config) dispatch({ type: USER_LIST_SUCCESS, @@ -236,7 +238,7 @@ export const deleteUser = (id) => async (dispatch,getState) => { } } - await axios.delete(`/api/users/${id}`,config) + await axios.delete(`${baseUrl}/api/users/${id}`,config) dispatch({ type: USER_DELETE_SUCCESS,