Added delete pagespeed thunk
This commit is contained in:
1 parent
8ac9e19238
commit
0addb128bf
2 files changed
+51
-6
No files matched your search
@@ -68,6 +68,27 @@ export const getPageSpeedByUserId = createAsyncThunk(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const deletePageSpeedMonitor = createAsyncThunk(
|
||||||
|
"monitors/deleteMonitor",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, monitor } = data;
|
||||||
|
const res = await axiosInstance.delete(`/monitors/${monitor._id}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${authToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return res.data;
|
||||||
|
} catch (error) {
|
||||||
|
if (error.response && error.response.data) {
|
||||||
|
return thunkApi.rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
return thunkApi.rejectWithValue(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const pageSpeedMonitorSlice = createSlice({
|
const pageSpeedMonitorSlice = createSlice({
|
||||||
name: "pageSpeedMonitor",
|
name: "pageSpeedMonitor",
|
||||||
initialState,
|
initialState,
|
||||||
@@ -137,6 +158,25 @@ const pageSpeedMonitorSlice = createSlice({
|
|||||||
state.msg = action.payload
|
state.msg = action.payload
|
||||||
? action.payload.msg
|
? action.payload.msg
|
||||||
: "Failed to create page speed monitor";
|
: "Failed to create page speed monitor";
|
||||||
|
})
|
||||||
|
|
||||||
|
// *****************************************************
|
||||||
|
// Delete Monitor
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(deletePageSpeedMonitor.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(deletePageSpeedMonitor.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(deletePageSpeedMonitor.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to delete page speed monitor";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { useTheme } from "@emotion/react";
|
|||||||
import { Box, Modal, Stack, Typography } from "@mui/material";
|
import { Box, Modal, Stack, Typography } from "@mui/material";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { useNavigate, useParams } from "react-router";
|
import { useNavigate, useParams } from "react-router";
|
||||||
|
import { deletePageSpeedMonitor } from "../../../Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
||||||
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import Button from "../../../Components/Button";
|
import Button from "../../../Components/Button";
|
||||||
import Field from "../../../Components/Inputs/Field";
|
import Field from "../../../Components/Inputs/Field";
|
||||||
import Select from "../../../Components/Inputs/Select";
|
import Select from "../../../Components/Inputs/Select";
|
||||||
@@ -11,6 +13,7 @@ import PauseCircleOutlineIcon from "@mui/icons-material/PauseCircleOutline";
|
|||||||
import WestRoundedIcon from "@mui/icons-material/WestRounded";
|
import WestRoundedIcon from "@mui/icons-material/WestRounded";
|
||||||
import GreenCheck from "../../../assets/icons/checkbox-green.svg?react";
|
import GreenCheck from "../../../assets/icons/checkbox-green.svg?react";
|
||||||
import RedCheck from "../../../assets/icons/checkbox-red.svg?react";
|
import RedCheck from "../../../assets/icons/checkbox-red.svg?react";
|
||||||
|
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
const PageSpeedConfigure = () => {
|
const PageSpeedConfigure = () => {
|
||||||
@@ -65,12 +68,14 @@ const PageSpeedConfigure = () => {
|
|||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// const action = await dispatch(deletePageSpeedMonitor({ authToken, monitor }));
|
const action = await dispatch(
|
||||||
// if (action.meta.requestStatus === "fulfilled") {
|
deletePageSpeedMonitor({ authToken, monitor })
|
||||||
// navigate("/monitors");
|
);
|
||||||
// } else {
|
if (action.meta.requestStatus === "fulfilled") {
|
||||||
// createToast({ body: "Failed to delete monitor." });
|
navigate("/pagespeed");
|
||||||
// }
|
} else {
|
||||||
|
createToast({ body: "Failed to delete monitor." });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in new issue
Block a user