Iniital commit

This commit is contained in:
Alex Holliday committed 2024-06-21 11:08:31 -07:00
1 parent 30b2229e98
commit 2f1053bd05
5 files changed
+41 -49

No files matched your search

+11 -4
View File
@@ -1,5 +1,6 @@
import axios from "axios";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import { jwtDecode } from "jwt-decode";
const initialState = {
isLoading: false,
@@ -25,9 +26,17 @@ export const getMonitors = createAsyncThunk(
export const getMonitorsByUserId = createAsyncThunk(
"montiors/getMonitorsByUserId",
async (token, thunkApi) => {
const user = jwtDecode(token);
try {
// TODO get userId and make request
console.log(token);
const res = await axios.get(
import.meta.env.VITE_APP_API_BASE_URL + "/monitors/user/" + user._id,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
return res.data;
} catch (error) {
return thunkApi.rejectWithValue(error.response.data);
}
@@ -50,7 +59,6 @@ const monitorsSlice = createSlice({
state.isLoading = false;
state.success = action.payload.success;
state.msg = action.payload.msg;
console.log(action.payload);
state.monitors = action.payload.data;
})
.addCase(getMonitors.rejected, (state, action) => {
@@ -68,7 +76,6 @@ const monitorsSlice = createSlice({
.addCase(getMonitorsByUserId.fulfilled, (state, action) => {
state.isLoading = false;
state.success = action.payload.msg;
console.log(action.payload);
state.monitors = action.payload.data;
})
.addCase(getMonitorsByUserId.rejected, (state, action) => {