move bulk monitors hook to monitorHooks
This commit is contained in:
1 parent
df69d06048
commit
cc8949538f
5 files changed
+36
-32
No files matched your search
@@ -411,7 +411,7 @@ const useDeleteAllMonitors = () => {
|
|||||||
return [deleteAllMonitors, isLoading];
|
return [deleteAllMonitors, isLoading];
|
||||||
};
|
};
|
||||||
|
|
||||||
const UseDeleteMonitorStats = () => {
|
const useDeleteMonitorStats = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const deleteMonitorStats = async () => {
|
const deleteMonitorStats = async () => {
|
||||||
@@ -429,6 +429,29 @@ const UseDeleteMonitorStats = () => {
|
|||||||
return [deleteMonitorStats, isLoading];
|
return [deleteMonitorStats, isLoading];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const useCreateBulkMonitors = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
const createBulkMonitors = async (file, user) => {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("csvFile", file);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await networkService.createBulkMonitors(formData);
|
||||||
|
return [true, response.data, null]; // [success, data, error]
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err?.response?.data?.msg || err.message;
|
||||||
|
return [false, null, errorMessage];
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [createBulkMonitors, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
useFetchMonitorsWithSummary,
|
useFetchMonitorsWithSummary,
|
||||||
useFetchMonitorsWithChecks,
|
useFetchMonitorsWithChecks,
|
||||||
@@ -443,5 +466,6 @@ export {
|
|||||||
usePauseMonitor,
|
usePauseMonitor,
|
||||||
useAddDemoMonitors,
|
useAddDemoMonitors,
|
||||||
useDeleteAllMonitors,
|
useDeleteAllMonitors,
|
||||||
UseDeleteMonitorStats,
|
useDeleteMonitorStats,
|
||||||
|
useCreateBulkMonitors,
|
||||||
};
|
};
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { networkService } from "../main";
|
|
||||||
|
|
||||||
export const useBulkMonitors = () => {
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
|
|
||||||
const createBulkMonitors = async (file, user) => {
|
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("csvFile", file);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await networkService.createBulkMonitors(formData);
|
|
||||||
return [true, response.data, null]; // [success, data, error]
|
|
||||||
} catch (err) {
|
|
||||||
const errorMessage = err?.response?.data?.msg || err.message;
|
|
||||||
return [false, null, errorMessage];
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return [createBulkMonitors, isLoading];
|
|
||||||
};
|
|
||||||
@@ -23,7 +23,7 @@ import { useIsAdmin } from "../../Hooks/useIsAdmin";
|
|||||||
import {
|
import {
|
||||||
useAddDemoMonitors,
|
useAddDemoMonitors,
|
||||||
useDeleteAllMonitors,
|
useDeleteAllMonitors,
|
||||||
UseDeleteMonitorStats,
|
useDeleteMonitorStats,
|
||||||
} from "../../Hooks/monitorHooks";
|
} from "../../Hooks/monitorHooks";
|
||||||
// Constants
|
// Constants
|
||||||
const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
|
const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
|
||||||
@@ -45,7 +45,7 @@ const Settings = () => {
|
|||||||
|
|
||||||
const [isSaving, saveError, saveSettings] = useSaveSettings();
|
const [isSaving, saveError, saveSettings] = useSaveSettings();
|
||||||
const [deleteAllMonitors, isDeletingMonitors] = useDeleteAllMonitors();
|
const [deleteAllMonitors, isDeletingMonitors] = useDeleteAllMonitors();
|
||||||
const [deleteMonitorStats, isDeletingMonitorStats] = UseDeleteMonitorStats();
|
const [deleteMonitorStats, isDeletingMonitorStats] = useDeleteMonitorStats();
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import UploadFile from "./Upload";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
import { useBulkMonitors } from "../../../Hooks/useBulkMonitors";
|
import { useCreateBulkMonitors } from "../../../Hooks/monitorHooks";
|
||||||
|
|
||||||
const BulkImport = () => {
|
const BulkImport = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -26,7 +26,7 @@ const BulkImport = () => {
|
|||||||
{ name: t("bulkImport.title"), path: `/uptime/bulk-import` },
|
{ name: t("bulkImport.title"), path: `/uptime/bulk-import` },
|
||||||
];
|
];
|
||||||
|
|
||||||
const [createBulkMonitors, hookLoading] = useBulkMonitors();
|
const [createBulkMonitors, hookLoading] = useCreateBulkMonitors();
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!selectedFile) {
|
if (!selectedFile) {
|
||||||
|
|||||||
@@ -186,7 +186,12 @@ const createMonitorBodyValidation = joi.object({
|
|||||||
matchMethod: joi.string(),
|
matchMethod: joi.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const createMonitorsBodyValidation = joi.array().items(createMonitorBodyValidation);
|
const createMonitorsBodyValidation = joi.array().items(
|
||||||
|
createMonitorBodyValidation.keys({
|
||||||
|
userId: joi.string().required(),
|
||||||
|
teamId: joi.string().required(),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
const editMonitorBodyValidation = joi.object({
|
const editMonitorBodyValidation = joi.object({
|
||||||
name: joi.string(),
|
name: joi.string(),
|
||||||
|
|||||||
Reference in new issue
Block a user