remove unused hooks
This commit is contained in:
1 parent
07aad0204e
commit
3d1bd94279
5 files changed
-508
No files matched your search
@@ -1,193 +0,0 @@
|
|||||||
import { useState, useEffect } from "react";
|
|
||||||
import { networkService } from "../main.jsx";
|
|
||||||
import { createToast } from "../Utils/toastUtils.jsx";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
const useFetchChecksTeam = ({
|
|
||||||
status,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
filter,
|
|
||||||
ack,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
enabled = true,
|
|
||||||
updateTrigger,
|
|
||||||
}) => {
|
|
||||||
const [checks, setChecks] = useState(undefined);
|
|
||||||
const [checksCount, setChecksCount] = useState(undefined);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchChecks = async () => {
|
|
||||||
if (!enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = {
|
|
||||||
status,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
filter,
|
|
||||||
ack,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const res = await networkService.getChecksByTeam(config);
|
|
||||||
setChecks(res.data.data.checks);
|
|
||||||
setChecksCount(res.data.data.checksCount);
|
|
||||||
} catch (error) {
|
|
||||||
setNetworkError(true);
|
|
||||||
createToast({ body: error.message });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchChecks();
|
|
||||||
}, [
|
|
||||||
status,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
filter,
|
|
||||||
ack,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
enabled,
|
|
||||||
updateTrigger,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return [checks, checksCount, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
const useFetchChecksByMonitor = ({
|
|
||||||
monitorId,
|
|
||||||
type,
|
|
||||||
status,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
filter,
|
|
||||||
ack,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
enabled = true,
|
|
||||||
updateTrigger,
|
|
||||||
}) => {
|
|
||||||
const [checks, setChecks] = useState(undefined);
|
|
||||||
const [checksCount, setChecksCount] = useState(undefined);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchChecks = async () => {
|
|
||||||
if (!enabled || !type) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = {
|
|
||||||
monitorId,
|
|
||||||
type,
|
|
||||||
status,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
filter,
|
|
||||||
ack,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const res = await networkService.getChecksByMonitor(config);
|
|
||||||
setChecks(res.data.data.checks);
|
|
||||||
setChecksCount(res.data.data.checksCount);
|
|
||||||
} catch (error) {
|
|
||||||
setNetworkError(true);
|
|
||||||
createToast({ body: error.message });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchChecks();
|
|
||||||
}, [
|
|
||||||
monitorId,
|
|
||||||
type,
|
|
||||||
status,
|
|
||||||
sortOrder,
|
|
||||||
limit,
|
|
||||||
dateRange,
|
|
||||||
filter,
|
|
||||||
ack,
|
|
||||||
page,
|
|
||||||
rowsPerPage,
|
|
||||||
enabled,
|
|
||||||
updateTrigger,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return [checks, checksCount, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
const useFetchChecksSummaryByTeamId = ({ dateRange, updateTrigger } = {}) => {
|
|
||||||
const [summary, setSummary] = useState(undefined);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [networkError, setNetworkError] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchSummary = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
const res = await networkService.getChecksAndSummaryByTeamId({ dateRange });
|
|
||||||
setSummary(res.data.data);
|
|
||||||
} catch (error) {
|
|
||||||
setNetworkError(true);
|
|
||||||
createToast({ body: error.message });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchSummary();
|
|
||||||
}, [dateRange, updateTrigger]);
|
|
||||||
|
|
||||||
return [summary, isLoading, networkError];
|
|
||||||
};
|
|
||||||
|
|
||||||
const useResolveIncident = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const resolveIncident = async (checkId, setUpdateTrigger) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
await networkService.updateCheckStatus({
|
|
||||||
checkId,
|
|
||||||
ack: true,
|
|
||||||
});
|
|
||||||
setUpdateTrigger((prev) => !prev);
|
|
||||||
} catch (error) {
|
|
||||||
createToast({ body: t("checkHooks.failureResolveOne") });
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return [resolveIncident, isLoading];
|
|
||||||
};
|
|
||||||
|
|
||||||
export {
|
|
||||||
useFetchChecksByMonitor,
|
|
||||||
useFetchChecksTeam,
|
|
||||||
useFetchChecksSummaryByTeamId,
|
|
||||||
useResolveIncident,
|
|
||||||
};
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { networkService } from "../main.jsx";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
const CLIENT_HOST = import.meta.env.VITE_APP_CLIENT_HOST;
|
|
||||||
|
|
||||||
const useGetInviteToken = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(undefined);
|
|
||||||
const [token, setToken] = useState(undefined);
|
|
||||||
|
|
||||||
const clearToken = () => {
|
|
||||||
setToken(undefined);
|
|
||||||
};
|
|
||||||
const fetchToken = async (email, role) => {
|
|
||||||
const response = await networkService.requestInvitationToken({ email, role });
|
|
||||||
const token = response?.data?.data?.token;
|
|
||||||
if (typeof token === "undefined") {
|
|
||||||
throw new Error(t("inviteNoTokenFound"));
|
|
||||||
}
|
|
||||||
return token;
|
|
||||||
};
|
|
||||||
const getInviteToken = async ({ email, role }) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const token = await fetchToken(email, role);
|
|
||||||
let inviteLink = token;
|
|
||||||
|
|
||||||
if (typeof CLIENT_HOST !== "undefined") {
|
|
||||||
inviteLink = `${CLIENT_HOST}/register/${token}`;
|
|
||||||
}
|
|
||||||
setToken(inviteLink);
|
|
||||||
return token;
|
|
||||||
} catch (error) {
|
|
||||||
setError(error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const addTeamMember = async (formData, role) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const token = await fetchToken(formData.email, role);
|
|
||||||
const toSubmit = {
|
|
||||||
...formData,
|
|
||||||
inviteToken: token,
|
|
||||||
};
|
|
||||||
delete toSubmit.confirm;
|
|
||||||
const responseRegister = await networkService.registerUser(toSubmit);
|
|
||||||
return responseRegister;
|
|
||||||
} catch (error) {
|
|
||||||
setError(error);
|
|
||||||
throw error;
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return [getInviteToken, clearToken, isLoading, error, token, addTeamMember];
|
|
||||||
};
|
|
||||||
|
|
||||||
export { useGetInviteToken };
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
import { useState, useEffect } from "react";
|
|
||||||
import { networkService } from "../main.jsx";
|
|
||||||
import { createToast } from "../Utils/toastUtils.jsx";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
const useFetchLogs = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [logs, setLogs] = useState(undefined);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(undefined);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchLogs = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const response = await networkService.getLogs();
|
|
||||||
setLogs(response.data.data);
|
|
||||||
} catch (error) {
|
|
||||||
setError(error);
|
|
||||||
createToast({
|
|
||||||
message: error.message,
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchLogs();
|
|
||||||
}, [t]);
|
|
||||||
return [logs, isLoading, error];
|
|
||||||
};
|
|
||||||
|
|
||||||
const useFetchQueueData = (trigger) => {
|
|
||||||
const [jobs, setJobs] = useState(undefined);
|
|
||||||
const [metrics, setMetrics] = useState(undefined);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(undefined);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchJobs = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const response = await networkService.getQueueData();
|
|
||||||
if (response.status === 200) {
|
|
||||||
setJobs(response.data.data.jobs);
|
|
||||||
setMetrics(response.data.data.metrics);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
setError(error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchJobs();
|
|
||||||
}, [trigger]);
|
|
||||||
|
|
||||||
return [jobs, metrics, isLoading, error];
|
|
||||||
};
|
|
||||||
|
|
||||||
const useFlushQueue = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(undefined);
|
|
||||||
|
|
||||||
const flushQueue = async (trigger, setTrigger) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
await networkService.flushQueue();
|
|
||||||
createToast({
|
|
||||||
body: "Queue flushed",
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
setError(error);
|
|
||||||
createToast({
|
|
||||||
body: error.message,
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
setTrigger(!trigger);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return [flushQueue, isLoading, error];
|
|
||||||
};
|
|
||||||
|
|
||||||
const useFetchDiagnostics = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(undefined);
|
|
||||||
const [diagnostics, setDiagnostics] = useState(undefined);
|
|
||||||
|
|
||||||
const fetchDiagnostics = async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const response = await networkService.getDiagnostics();
|
|
||||||
setDiagnostics(response.data.data);
|
|
||||||
} catch (error) {
|
|
||||||
createToast({
|
|
||||||
body: error.message,
|
|
||||||
});
|
|
||||||
setError(error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchDiagnostics();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return [diagnostics, fetchDiagnostics, isLoading, error];
|
|
||||||
};
|
|
||||||
|
|
||||||
export { useFetchLogs, useFetchQueueData, useFlushQueue, useFetchDiagnostics };
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
import { useState, useEffect, useCallback } from "react";
|
|
||||||
import { createToast } from "../Utils/toastUtils.jsx";
|
|
||||||
import { networkService } from "../main.jsx";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
const useGetNotificationsByTeamId = (updateTrigger) => {
|
|
||||||
const [notifications, setNotifications] = useState([]);
|
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const getNotifications = useCallback(async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const response = await networkService.getNotificationsByTeamId();
|
|
||||||
setNotifications(response?.data?.data ?? []);
|
|
||||||
} catch (error) {
|
|
||||||
setError(error);
|
|
||||||
createToast({
|
|
||||||
body: t("notifications.fetch.failed"),
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
}, [t]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getNotifications();
|
|
||||||
}, [getNotifications, updateTrigger]);
|
|
||||||
|
|
||||||
return [notifications, isLoading, error];
|
|
||||||
};
|
|
||||||
|
|
||||||
const useTestAllNotifications = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(undefined);
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const testAllNotifications = async ({ monitorId }) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
await networkService.testAllNotifications({ monitorId });
|
|
||||||
createToast({
|
|
||||||
body: t("notifications.test.success"),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
createToast({
|
|
||||||
body: error.response?.data?.msg || error.message,
|
|
||||||
});
|
|
||||||
setError(error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return [testAllNotifications, isLoading, error];
|
|
||||||
};
|
|
||||||
|
|
||||||
export { useGetNotificationsByTeamId, useTestAllNotifications };
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
import { useEffect, useState, useCallback } from "react";
|
|
||||||
import { networkService } from "../main.jsx";
|
|
||||||
import { createToast } from "../Utils/toastUtils.jsx";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
export const useGetUser = (userId) => {
|
|
||||||
const [user, setUser] = useState(undefined);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
const fetchUser = useCallback(async () => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
const response = await networkService.getUserById({ userId });
|
|
||||||
setUser(response?.data?.data);
|
|
||||||
} catch (error) {
|
|
||||||
createToast({
|
|
||||||
body: error.message,
|
|
||||||
});
|
|
||||||
setError(error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
}, [userId]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (userId) {
|
|
||||||
fetchUser();
|
|
||||||
}
|
|
||||||
}, [userId, fetchUser]);
|
|
||||||
|
|
||||||
return [user, isLoading, error];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useEditUser = (userId) => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [error, setError] = useState(null);
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const editUser = useCallback(
|
|
||||||
async (user) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
await networkService.editUser({ userId, user });
|
|
||||||
createToast({
|
|
||||||
body: t("editUserPage.toast.successUserUpdate"),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
createToast({
|
|
||||||
body: error.message,
|
|
||||||
});
|
|
||||||
setError(error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[userId, t]
|
|
||||||
);
|
|
||||||
|
|
||||||
const changePassword = useCallback(
|
|
||||||
async (passwordForm) => {
|
|
||||||
try {
|
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
await networkService.changePasswordByAdmin({ userId, passwordForm });
|
|
||||||
createToast({
|
|
||||||
body: t("teamPanel.changeTeamPassword.success"),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
createToast({
|
|
||||||
body: error.message,
|
|
||||||
});
|
|
||||||
setError(error);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[userId, t]
|
|
||||||
);
|
|
||||||
|
|
||||||
return [editUser, isLoading, error, changePassword];
|
|
||||||
};
|
|
||||||
Reference in new issue
Block a user