mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-20 16:49:46 -06:00
move bulk monitors hook to monitorHooks
This commit is contained in:
@@ -411,7 +411,7 @@ const useDeleteAllMonitors = () => {
|
||||
return [deleteAllMonitors, isLoading];
|
||||
};
|
||||
|
||||
const UseDeleteMonitorStats = () => {
|
||||
const useDeleteMonitorStats = () => {
|
||||
const { t } = useTranslation();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const deleteMonitorStats = async () => {
|
||||
@@ -429,6 +429,29 @@ const UseDeleteMonitorStats = () => {
|
||||
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 {
|
||||
useFetchMonitorsWithSummary,
|
||||
useFetchMonitorsWithChecks,
|
||||
@@ -443,5 +466,6 @@ export {
|
||||
usePauseMonitor,
|
||||
useAddDemoMonitors,
|
||||
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 {
|
||||
useAddDemoMonitors,
|
||||
useDeleteAllMonitors,
|
||||
UseDeleteMonitorStats,
|
||||
useDeleteMonitorStats,
|
||||
} from "../../Hooks/monitorHooks";
|
||||
// Constants
|
||||
const BREADCRUMBS = [{ name: `Settings`, path: "/settings" }];
|
||||
@@ -45,7 +45,7 @@ const Settings = () => {
|
||||
|
||||
const [isSaving, saveError, saveSettings] = useSaveSettings();
|
||||
const [deleteAllMonitors, isDeletingMonitors] = useDeleteAllMonitors();
|
||||
const [deleteMonitorStats, isDeletingMonitorStats] = UseDeleteMonitorStats();
|
||||
const [deleteMonitorStats, isDeletingMonitorStats] = useDeleteMonitorStats();
|
||||
|
||||
// Setup
|
||||
const isAdmin = useIsAdmin();
|
||||
|
||||
@@ -12,7 +12,7 @@ import UploadFile from "./Upload";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useNavigate } from "react-router";
|
||||
import { Trans, useTranslation } from "react-i18next";
|
||||
import { useBulkMonitors } from "../../../Hooks/useBulkMonitors";
|
||||
import { useCreateBulkMonitors } from "../../../Hooks/monitorHooks";
|
||||
|
||||
const BulkImport = () => {
|
||||
const theme = useTheme();
|
||||
@@ -26,7 +26,7 @@ const BulkImport = () => {
|
||||
{ name: t("bulkImport.title"), path: `/uptime/bulk-import` },
|
||||
];
|
||||
|
||||
const [createBulkMonitors, hookLoading] = useBulkMonitors();
|
||||
const [createBulkMonitors, hookLoading] = useCreateBulkMonitors();
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedFile) {
|
||||
|
||||
@@ -186,7 +186,12 @@ const createMonitorBodyValidation = joi.object({
|
||||
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({
|
||||
name: joi.string(),
|
||||
|
||||
Reference in New Issue
Block a user