Skip to content

Commit

Permalink
Fix reservations lists
Browse files Browse the repository at this point in the history
  • Loading branch information
hmunish committed Nov 4, 2023
1 parent b000263 commit 8d89921
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/redux/reservations/reservationSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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`,
Expand All @@ -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({
Expand Down

0 comments on commit 8d89921

Please sign in to comment.