From 8d8992118d8590dc433f4164db9fff0626e58041 Mon Sep 17 00:00:00 2001 From: Munish Date: Sat, 4 Nov 2023 16:01:41 +0200 Subject: [PATCH] Fix reservations lists --- src/redux/reservations/reservationSlice.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/redux/reservations/reservationSlice.js b/src/redux/reservations/reservationSlice.js index c9f0ffd..5efb024 100644 --- a/src/redux/reservations/reservationSlice.js +++ b/src/redux/reservations/reservationSlice.js @@ -3,8 +3,6 @@ import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; import { API_URL } from "../../utility/globalVariable"; import { getLocalStorageAuth } from "../../utility/helper"; -axios.defaults.headers.common.Authorization = getLocalStorageAuth(); - const initialState = { isError: false, isLoading: false, @@ -18,20 +16,19 @@ export const getReservations = createAsyncThunk( try { const response = await axios.get( `${API_URL}/users/${userId}/reservations`, + { headers: { Authorization: getLocalStorageAuth() } } ); if (response.status !== 200) throw new Error("Error"); return response.data; } catch (err) { return thunkAPI.rejectWithValue("Error fetching reservations"); } - }, + } ); export const addReservation = createAsyncThunk( "reservation/addReservation", - async ({ - userId, bookingDate: date, location, carId, - }, thunkAPI) => { + async ({ userId, bookingDate: date, location, carId }, thunkAPI) => { try { const res = await axios.post( `${API_URL}/users/${userId}/reservations`, @@ -43,15 +40,16 @@ export const addReservation = createAsyncThunk( { headers: { "Content-Type": "multipart/form-data", + Authorization: getLocalStorageAuth(), }, - }, + } ); if (res.status !== 201) throw new Error("Error"); return res; } catch (err) { return thunkAPI.rejectWithValue("Error adding reservation"); } - }, + } ); export const reservationSlice = createSlice({