remove authToken reading and passing in UI component and hooks

This commit is contained in:
dongfang committed 2025-02-18 04:56:26 +00:00
1 parent 6a1e5532e4
commit f2ae99768a
41 files changed
+76 -135

No files matched your search

+6 -6
View File
@@ -48,7 +48,7 @@ const Configure = () => {
const navigate = useNavigate();
const theme = useTheme();
const dispatch = useDispatch();
const { user, authToken } = useSelector((state) => state.auth);
const { user } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.uptimeMonitors);
const [monitor, setMonitor] = useState({});
const [errors, setErrors] = useState({});
@@ -76,7 +76,7 @@ const Configure = () => {
useEffect(() => {
const fetchMonitor = async () => {
try {
const action = await dispatch(getUptimeMonitorById({ authToken, monitorId }));
const action = await dispatch(getUptimeMonitorById({ monitorId }));
if (getUptimeMonitorById.fulfilled.match(action)) {
const monitor = action.payload.data;
@@ -90,7 +90,7 @@ const Configure = () => {
}
};
fetchMonitor();
}, [monitorId, authToken, navigate]);
}, [monitorId, navigate]);
const handleChange = (event, name) => {
let { value, id } = event.target;
@@ -147,7 +147,7 @@ const Configure = () => {
const handlePause = async () => {
try {
const action = await dispatch(pauseUptimeMonitor({ authToken, monitorId }));
const action = await dispatch(pauseUptimeMonitor({ monitorId }));
if (pauseUptimeMonitor.fulfilled.match(action)) {
const monitor = action.payload.data;
setMonitor(monitor);
@@ -164,7 +164,7 @@ const Configure = () => {
const handleSubmit = async (event) => {
event.preventDefault();
const action = await dispatch(updateUptimeMonitor({ authToken, monitor: monitor }));
const action = await dispatch(updateUptimeMonitor({ monitor: monitor }));
if (action.meta.requestStatus === "fulfilled") {
createToast({ body: "Monitor updated successfully!" });
} else {
@@ -175,7 +175,7 @@ const Configure = () => {
const [isOpen, setIsOpen] = useState(false);
const handleRemove = async (event) => {
event.preventDefault();
const action = await dispatch(deleteUptimeMonitor({ authToken, monitor }));
const action = await dispatch(deleteUptimeMonitor({ monitor }));
if (action.meta.requestStatus === "fulfilled") {
navigate("/uptime");
} else {
+5 -5
View File
@@ -68,7 +68,7 @@ const CreateMonitor = () => {
},
};
const { user, authToken } = useSelector((state) => state.auth);
const { user } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.uptimeMonitors);
const dispatch = useDispatch();
const navigate = useNavigate();
@@ -126,7 +126,7 @@ const CreateMonitor = () => {
if (monitor.type === "http") {
// const checkEndpointAction = await dispatch(
// checkEndpointResolution({ authToken, monitorURL: form.url })
// checkEndpointResolution({ monitorURL: form.url })
// );
// if (checkEndpointAction.meta.requestStatus === "rejected") {
// createToast({
@@ -144,7 +144,7 @@ const CreateMonitor = () => {
userId: user._id,
notifications: monitor.notifications,
};
const action = await dispatch(createUptimeMonitor({ authToken, monitor: form }));
const action = await dispatch(createUptimeMonitor({ monitor: form }));
if (action.meta.requestStatus === "fulfilled") {
createToast({ body: "Monitor created successfully!" });
navigate("/uptime");
@@ -205,7 +205,7 @@ const CreateMonitor = () => {
useEffect(() => {
const fetchMonitor = async () => {
if (monitorId) {
const action = await dispatch(getUptimeMonitorById({ authToken, monitorId }));
const action = await dispatch(getUptimeMonitorById({ monitorId }));
if (action.payload.success) {
const data = action.payload.data;
@@ -228,7 +228,7 @@ const CreateMonitor = () => {
}
};
fetchMonitor();
}, [monitorId, authToken, dispatch, navigate]);
}, [monitorId, dispatch, navigate]);
return (
<Box className="create-monitor">
@@ -5,7 +5,6 @@ import { formatDateWithTz } from "../../../../Utils/timeUtils";
const useCertificateFetch = ({
monitor,
authToken,
monitorId,
certificateDateFormat,
uiTimezone,
@@ -22,7 +21,6 @@ const useCertificateFetch = ({
try {
setIsLoading(true);
const res = await networkService.getCertificateExpiry({
authToken: authToken,
monitorId: monitorId,
});
if (res?.data?.data?.certificateDate) {
@@ -39,7 +37,7 @@ const useCertificateFetch = ({
}
};
fetchCertificate();
}, [authToken, monitorId, certificateDateFormat, uiTimezone, monitor]);
}, [monitorId, certificateDateFormat, uiTimezone, monitor]);
return [certificateExpiry, isLoading];
};
@@ -3,7 +3,6 @@ import { useEffect } from "react";
import { networkService } from "../../../../main";
import { createToast } from "../../../../Utils/toastUtils";
export const useChecksFetch = ({
authToken,
monitorId,
dateRange,
page,
@@ -19,7 +18,6 @@ export const useChecksFetch = ({
try {
setIsLoading(true);
const res = await networkService.getChecksByMonitor({
authToken: authToken,
monitorId: monitorId,
sortOrder: "desc",
limit: null,
@@ -38,7 +36,7 @@ export const useChecksFetch = ({
}
};
fetchChecks();
}, [authToken, monitorId, dateRange, page, rowsPerPage]);
}, [monitorId, dateRange, page, rowsPerPage]);
return [checks, checksCount, isLoading, networkError];
};
@@ -3,7 +3,7 @@ import { networkService } from "../../../../main";
import { useNavigate } from "react-router-dom";
import { createToast } from "../../../../Utils/toastUtils";
export const useMonitorFetch = ({ authToken, monitorId, dateRange }) => {
export const useMonitorFetch = ({ monitorId, dateRange }) => {
const [networkError, setNetworkError] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const [monitor, setMonitor] = useState(undefined);
@@ -13,7 +13,6 @@ export const useMonitorFetch = ({ authToken, monitorId, dateRange }) => {
const fetchMonitors = async () => {
try {
const res = await networkService.getUptimeDetailsById({
authToken: authToken,
monitorId: monitorId,
dateRange: dateRange,
normalize: true,
@@ -27,7 +26,7 @@ export const useMonitorFetch = ({ authToken, monitorId, dateRange }) => {
}
};
fetchMonitors();
}, [authToken, dateRange, monitorId, navigate]);
}, [dateRange, monitorId, navigate]);
return [monitor, isLoading, networkError];
};
-4
View File
@@ -31,7 +31,6 @@ const certificateDateFormat = "MMM D, YYYY h A";
const UptimeDetails = () => {
// Redux state
const { authToken } = useSelector((state) => state.auth);
const uiTimezone = useSelector((state) => state.ui.timezone);
// Local state
@@ -48,21 +47,18 @@ const UptimeDetails = () => {
const isAdmin = useIsAdmin();
const [monitor, monitorIsLoading, monitorNetworkError] = useMonitorFetch({
authToken,
monitorId,
dateRange,
});
const [certificateExpiry, certificateIsLoading] = useCertificateFetch({
monitor,
authToken,
monitorId,
certificateDateFormat,
uiTimezone,
});
const [checks, checksCount, checksAreLoading, checksNetworkError] = useChecksFetch({
authToken,
monitorId,
dateRange,
page,
@@ -5,7 +5,6 @@ import { useTheme } from "@emotion/react";
import { useMonitorUtils } from "../../../../Hooks/useMonitorUtils";
export const useMonitorFetch = ({
authToken,
teamId,
limit,
page,
@@ -28,7 +27,6 @@ export const useMonitorFetch = ({
try {
setMonitorsAreLoading(true);
const res = await networkService.getMonitorsByTeamId({
authToken,
teamId,
limit,
types: ["http", "ping", "docker", "port"],
@@ -56,7 +54,6 @@ export const useMonitorFetch = ({
};
fetchMonitors();
}, [
authToken,
teamId,
limit,
field,
+1 -2
View File
@@ -54,7 +54,7 @@ CreateMonitorButton.propTypes = {
const UptimeMonitors = () => {
// Redux state
const { authToken, user } = useSelector((state) => state.auth);
const { user } = useSelector((state) => state.auth);
const rowsPerPage = useSelector((state) => state.ui.monitors.rowsPerPage);
// Local state
@@ -96,7 +96,6 @@ const UptimeMonitors = () => {
monitorsSummary,
networkError,
} = useMonitorsFetch({
authToken,
teamId,
limit: 25,
page: page,