delete
This commit is contained in:
1 parent
91bb60f2ff
commit
ec818eaacb
2 files changed
+48
-12
No files matched your search
@@ -42,8 +42,8 @@ export const HeaderMonitorControls = ({
|
|||||||
refetch,
|
refetch,
|
||||||
}: HeaderMonitorControlsProps) => {
|
}: HeaderMonitorControlsProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const navigate = useNavigate();
|
||||||
const {
|
const {
|
||||||
post,
|
post,
|
||||||
loading: isPosting,
|
loading: isPosting,
|
||||||
@@ -117,15 +117,16 @@ interface HeaderDeleteControlsProps {
|
|||||||
monitor?: Monitor | null;
|
monitor?: Monitor | null;
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
refetch: Function;
|
refetch: Function;
|
||||||
|
onDelete?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HeaderDeleteControls = ({
|
export const HeaderDeleteControls = ({
|
||||||
monitor,
|
monitor,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
refetch,
|
refetch,
|
||||||
|
onDelete,
|
||||||
}: HeaderDeleteControlsProps) => {
|
}: HeaderDeleteControlsProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const {
|
const {
|
||||||
post,
|
post,
|
||||||
@@ -158,14 +159,14 @@ export const HeaderDeleteControls = ({
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="error"
|
color="error"
|
||||||
startIcon={<Icon icon={Trash} />}
|
startIcon={<Icon icon={Trash} />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
console.log("delete");
|
onDelete?.();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("common.buttons.delete")}
|
{t("common.buttons.delete")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useParams, useLocation, useNavigate } from "react-router";
|
import { useParams, useLocation, useNavigate } from "react-router";
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, Controller } from "react-hook-form";
|
||||||
@@ -25,8 +25,9 @@ import {
|
|||||||
Autocomplete,
|
Autocomplete,
|
||||||
SwitchComponent as Switch,
|
SwitchComponent as Switch,
|
||||||
SliderWithLabel,
|
SliderWithLabel,
|
||||||
|
Dialog,
|
||||||
} from "@/Components/v2/inputs";
|
} from "@/Components/v2/inputs";
|
||||||
import { useGet, usePost, usePatch } from "@/Hooks/UseApi";
|
import { useGet, usePost, usePatch, useDelete } from "@/Hooks/UseApi";
|
||||||
import { useMonitorForm } from "@/Hooks/useMonitorForm";
|
import { useMonitorForm } from "@/Hooks/useMonitorForm";
|
||||||
import type { Monitor, MonitorType } from "@/Types/Monitor";
|
import type { Monitor, MonitorType } from "@/Types/Monitor";
|
||||||
import type { Notification } from "@/Types/Notification";
|
import type { Notification } from "@/Types/Notification";
|
||||||
@@ -177,6 +178,31 @@ const CreateMonitorPage = () => {
|
|||||||
const { post, loading: isCreating } = usePost<MonitorFormData, Monitor>();
|
const { post, loading: isCreating } = usePost<MonitorFormData, Monitor>();
|
||||||
const { patch, loading: isUpdating } = usePatch<MonitorFormData, Monitor>();
|
const { patch, loading: isUpdating } = usePatch<MonitorFormData, Monitor>();
|
||||||
const isSubmitting = isCreating || isUpdating;
|
const isSubmitting = isCreating || isUpdating;
|
||||||
|
// Delete functionality
|
||||||
|
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
||||||
|
const { deleteFn, loading: isDeleting } = useDelete();
|
||||||
|
|
||||||
|
const handleDeleteClick = () => {
|
||||||
|
setIsDeleteDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
if (!monitorId) return;
|
||||||
|
await deleteFn(`/monitors/${monitorId}`);
|
||||||
|
setIsDeleteDialogOpen(false);
|
||||||
|
// Navigate based on page type
|
||||||
|
if (pageType === "pagespeed") {
|
||||||
|
navigate("/pagespeed");
|
||||||
|
} else if (pageType === "hardware") {
|
||||||
|
navigate("/infrastructure");
|
||||||
|
} else {
|
||||||
|
navigate("/uptime");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteCancel = () => {
|
||||||
|
setIsDeleteDialogOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
const onSubmit = async (data: MonitorFormData) => {
|
const onSubmit = async (data: MonitorFormData) => {
|
||||||
let result;
|
let result;
|
||||||
@@ -211,6 +237,7 @@ const CreateMonitorPage = () => {
|
|||||||
monitor={existingMonitor}
|
monitor={existingMonitor}
|
||||||
isAdmin={true}
|
isAdmin={true}
|
||||||
refetch={refetchMonitor}
|
refetch={refetchMonitor}
|
||||||
|
onDelete={handleDeleteClick}
|
||||||
/>
|
/>
|
||||||
{/* Monitor Type Selection - only shown for uptime monitors */}
|
{/* Monitor Type Selection - only shown for uptime monitors */}
|
||||||
{showTypeSelector && (
|
{showTypeSelector && (
|
||||||
@@ -668,6 +695,14 @@ const CreateMonitorPage = () => {
|
|||||||
{t("common.buttons.save")}
|
{t("common.buttons.save")}
|
||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
<Dialog
|
||||||
|
open={isDeleteDialogOpen}
|
||||||
|
title={t("common.dialogs.delete.title")}
|
||||||
|
content={t("common.dialogs.delete.description")}
|
||||||
|
onConfirm={handleDeleteConfirm}
|
||||||
|
onCancel={handleDeleteCancel}
|
||||||
|
loading={isDeleting}
|
||||||
|
/>
|
||||||
</BasePage>
|
</BasePage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user