remove authToken reading and passing in UI component and hooks
This commit is contained in:
1 parent
6a1e5532e4
commit
f2ae99768a
41 files changed
+76
-135
No files matched your search
@@ -31,7 +31,7 @@ const PageSpeedConfigure = () => {
|
||||
const navigate = useNavigate();
|
||||
const dispatch = useDispatch();
|
||||
const MS_PER_MINUTE = 60000;
|
||||
const { user, authToken } = useSelector((state) => state.auth);
|
||||
const { user } = useSelector((state) => state.auth);
|
||||
const { isLoading } = useSelector((state) => state.pageSpeedMonitors);
|
||||
const { monitorId } = useParams();
|
||||
const [monitor, setMonitor] = useState({});
|
||||
@@ -59,7 +59,7 @@ const PageSpeedConfigure = () => {
|
||||
useEffect(() => {
|
||||
const fetchMonitor = async () => {
|
||||
try {
|
||||
const action = await dispatch(getPagespeedMonitorById({ authToken, monitorId }));
|
||||
const action = await dispatch(getPagespeedMonitorById({ monitorId }));
|
||||
|
||||
if (getPagespeedMonitorById.fulfilled.match(action)) {
|
||||
const monitor = action.payload.data;
|
||||
@@ -73,7 +73,7 @@ const PageSpeedConfigure = () => {
|
||||
}
|
||||
};
|
||||
fetchMonitor();
|
||||
}, [dispatch, authToken, monitorId, navigate]);
|
||||
}, [dispatch, monitorId, navigate]);
|
||||
|
||||
const handleChange = (event, name) => {
|
||||
let { value, id } = event.target;
|
||||
@@ -130,7 +130,7 @@ const PageSpeedConfigure = () => {
|
||||
|
||||
const handlePause = async () => {
|
||||
try {
|
||||
const action = await dispatch(pausePageSpeed({ authToken, monitorId }));
|
||||
const action = await dispatch(pausePageSpeed({ monitorId }));
|
||||
if (pausePageSpeed.fulfilled.match(action)) {
|
||||
const monitor = action.payload.data;
|
||||
setMonitor(monitor);
|
||||
@@ -147,10 +147,10 @@ const PageSpeedConfigure = () => {
|
||||
|
||||
const handleSave = async (event) => {
|
||||
event.preventDefault();
|
||||
const action = await dispatch(updatePageSpeed({ authToken, monitor: monitor }));
|
||||
const action = await dispatch(updatePageSpeed({ monitor: monitor }));
|
||||
if (action.meta.requestStatus === "fulfilled") {
|
||||
createToast({ body: "Monitor updated successfully!" });
|
||||
dispatch(getPageSpeedByTeamId(authToken));
|
||||
dispatch(getPageSpeedByTeamId());
|
||||
} else {
|
||||
createToast({ body: "Failed to update monitor." });
|
||||
}
|
||||
@@ -160,7 +160,7 @@ const PageSpeedConfigure = () => {
|
||||
const handleRemove = async (event) => {
|
||||
event.preventDefault();
|
||||
setButtonLoading(true);
|
||||
const action = await dispatch(deletePageSpeed({ authToken, monitor }));
|
||||
const action = await dispatch(deletePageSpeed({ monitor }));
|
||||
if (action.meta.requestStatus === "fulfilled") {
|
||||
navigate("/pagespeed");
|
||||
} else {
|
||||
|
||||
@@ -54,7 +54,7 @@ const CreatePageSpeed = () => {
|
||||
|
||||
const [https, setHttps] = useState(true);
|
||||
const [errors, setErrors] = useState({});
|
||||
const { user, authToken } = useSelector((state) => state.auth);
|
||||
const { user } = useSelector((state) => state.auth);
|
||||
const { isLoading } = useSelector((state) => state.pageSpeedMonitors);
|
||||
|
||||
// Setup
|
||||
@@ -87,7 +87,7 @@ const CreatePageSpeed = () => {
|
||||
}
|
||||
|
||||
const checkEndpointAction = await dispatch(
|
||||
checkEndpointResolution({ authToken, monitorURL: form.url })
|
||||
checkEndpointResolution({ monitorURL: form.url })
|
||||
);
|
||||
|
||||
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
||||
@@ -106,7 +106,7 @@ const CreatePageSpeed = () => {
|
||||
notifications: monitor.notifications,
|
||||
};
|
||||
|
||||
const action = await dispatch(createPageSpeed({ authToken, monitor: form }));
|
||||
const action = await dispatch(createPageSpeed({ monitor: form }));
|
||||
if (action.meta.requestStatus === "fulfilled") {
|
||||
createToast({ body: "Monitor created successfully!" });
|
||||
navigate("/pagespeed");
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
|
||||
import { networkService } from "../../../../main";
|
||||
import { createToast } from "../../../../Utils/toastUtils";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
const useMonitorFetch = ({ authToken, monitorId }) => {
|
||||
const useMonitorFetch = ({ monitorId }) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [monitor, setMonitor] = useState(undefined);
|
||||
@@ -13,7 +13,6 @@ const useMonitorFetch = ({ authToken, monitorId }) => {
|
||||
const fetchMonitor = async () => {
|
||||
try {
|
||||
const res = await networkService.getStatsByMonitorId({
|
||||
authToken: authToken,
|
||||
monitorId: monitorId,
|
||||
sortOrder: "desc",
|
||||
limit: 50,
|
||||
@@ -32,7 +31,7 @@ const useMonitorFetch = ({ authToken, monitorId }) => {
|
||||
};
|
||||
|
||||
fetchMonitor();
|
||||
}, [authToken, monitorId, navigate]);
|
||||
}, [monitorId, navigate]);
|
||||
|
||||
return { monitor, audits, isLoading };
|
||||
};
|
||||
|
||||
@@ -25,10 +25,8 @@ const PageSpeedDetails = () => {
|
||||
const theme = useTheme();
|
||||
const isAdmin = useIsAdmin();
|
||||
const { monitorId } = useParams();
|
||||
const { authToken } = useSelector((state) => state.auth);
|
||||
|
||||
const { monitor, audits, isLoading, networkError } = useMonitorFetch({
|
||||
authToken,
|
||||
monitorId,
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useState } from "react";
|
||||
import { networkService } from "../../../../main";
|
||||
import { createToast } from "../../../../Utils/toastUtils";
|
||||
|
||||
const useMonitorsFetch = ({ authToken, teamId }) => {
|
||||
const useMonitorsFetch = ({ teamId }) => {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [monitors, setMonitors] = useState([]);
|
||||
const [summary, setSummary] = useState({});
|
||||
@@ -13,7 +13,6 @@ const useMonitorsFetch = ({ authToken, teamId }) => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const res = await networkService.getMonitorsByTeamId({
|
||||
authToken: authToken,
|
||||
teamId: teamId,
|
||||
limit: 10,
|
||||
types: ["pagespeed"],
|
||||
@@ -38,7 +37,7 @@ const useMonitorsFetch = ({ authToken, teamId }) => {
|
||||
};
|
||||
|
||||
fetchMonitors();
|
||||
}, [authToken, teamId]);
|
||||
}, [teamId]);
|
||||
return { isLoading, monitors, summary, networkError };
|
||||
};
|
||||
|
||||
|
||||
@@ -19,10 +19,9 @@ const BREADCRUMBS = [{ name: `pagespeed`, path: "/pagespeed" }];
|
||||
const PageSpeed = () => {
|
||||
const theme = useTheme();
|
||||
const isAdmin = useIsAdmin();
|
||||
const { user, authToken } = useSelector((state) => state.auth);
|
||||
const { user } = useSelector((state) => state.auth);
|
||||
|
||||
const { isLoading, monitors, summary, networkError } = useMonitorsFetch({
|
||||
authToken: authToken,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user