handle delete
This commit is contained in:
1 parent
40e5550e0f
commit
a80df60fc1
9 files changed
+47
-25
No files matched your search
@@ -1,12 +1,10 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { Icon, MonitorStatus } from "@/Components/v2/design-elements";
|
import { Icon } from "@/Components/v2/design-elements";
|
||||||
import { Button } from "@/Components/v2/inputs";
|
import { Button } from "@/Components/v2/inputs";
|
||||||
import { Trash } from "lucide-react";
|
import { Trash } from "lucide-react";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { usePost } from "@/Hooks/UseApi";
|
|
||||||
|
|
||||||
interface HeaderConfigStatusControlsProps {
|
interface HeaderConfigStatusControlsProps {
|
||||||
onDelete: () => void;
|
onDelete: () => void;
|
||||||
|
|||||||
@@ -13,16 +13,17 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
|
Dialog,
|
||||||
} from "@/Components/v2/inputs";
|
} from "@/Components/v2/inputs";
|
||||||
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, Controller } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useStatusPageForm } from "@/Hooks/useStatusPageForm";
|
import { useStatusPageForm } from "@/Hooks/useStatusPageForm";
|
||||||
import type { StatusPageFormData } from "@/Validation/statusPage";
|
import type { StatusPageFormData } from "@/Validation/statusPage";
|
||||||
import { useGet, usePost, usePut } from "@/Hooks/UseApi";
|
import { useGet, usePost, usePut, useDelete } from "@/Hooks/UseApi";
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
import type { Monitor } from "@/Types/Monitor";
|
||||||
import type { StatusPageResponse } from "@/Types/StatusPage";
|
import type { StatusPageResponse } from "@/Types/StatusPage";
|
||||||
import timezones from "@/Utils/timezones.json";
|
import timezones from "@/Utils/timezones.json";
|
||||||
@@ -55,6 +56,10 @@ const CreateStatusPage = () => {
|
|||||||
|
|
||||||
const { post, loading: isSubmittingPost } = usePost();
|
const { post, loading: isSubmittingPost } = usePost();
|
||||||
const { put, loading: isSubmittingPut } = usePut();
|
const { put, loading: isSubmittingPut } = usePut();
|
||||||
|
const { deleteFn, loading: isDeleting } = useDelete();
|
||||||
|
|
||||||
|
// Delete dialog state
|
||||||
|
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
||||||
const isSubmitting = isSubmittingPost || isSubmittingPut;
|
const isSubmitting = isSubmittingPost || isSubmittingPut;
|
||||||
|
|
||||||
const { schema, defaults } = useStatusPageForm({
|
const { schema, defaults } = useStatusPageForm({
|
||||||
@@ -78,6 +83,22 @@ const CreateStatusPage = () => {
|
|||||||
console.log(errors);
|
console.log(errors);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeleteClick = () => {
|
||||||
|
setIsDeleteDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteConfirm = async () => {
|
||||||
|
const result = await deleteFn(`/status-page/${statusPageData?.statusPage?.id}`);
|
||||||
|
if (result) {
|
||||||
|
navigate("/status");
|
||||||
|
}
|
||||||
|
setIsDeleteDialogOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteCancel = () => {
|
||||||
|
setIsDeleteDialogOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
const onSubmit = async (data: StatusPageFormData) => {
|
const onSubmit = async (data: StatusPageFormData) => {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append("type", "uptime");
|
fd.append("type", "uptime");
|
||||||
@@ -136,13 +157,7 @@ const CreateStatusPage = () => {
|
|||||||
component="form"
|
component="form"
|
||||||
onSubmit={handleSubmit(onSubmit, onError)}
|
onSubmit={handleSubmit(onSubmit, onError)}
|
||||||
>
|
>
|
||||||
{!isCreate && (
|
{!isCreate && <HeaderConfigStatusControls onDelete={handleDeleteClick} />}
|
||||||
<HeaderConfigStatusControls
|
|
||||||
onDelete={() => {
|
|
||||||
console.log("poo");
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.statusPages.form.access.title")}
|
title={t("pages.statusPages.form.access.title")}
|
||||||
subtitle={t("pages.statusPages.form.access.description")}
|
subtitle={t("pages.statusPages.form.access.description")}
|
||||||
@@ -459,6 +474,14 @@ const CreateStatusPage = () => {
|
|||||||
{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>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export const HeaderStatusPageControls = ({
|
|||||||
<Typography
|
<Typography
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
window.open(
|
window.open(
|
||||||
`/status/uptime/public/${statusPage.url}`,
|
`/status/public/${statusPage.url}`,
|
||||||
"_blank",
|
"_blank",
|
||||||
"noopener,noreferrer"
|
"noopener,noreferrer"
|
||||||
);
|
);
|
||||||
@@ -77,7 +77,7 @@ export const HeaderStatusPageControls = ({
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
startIcon={<Icon icon={Settings} />}
|
startIcon={<Icon icon={Settings} />}
|
||||||
onClick={() => navigate(`/status/uptime/configure/${statusPage.url}`)}
|
onClick={() => navigate(`/status/configure/${statusPage.url}`)}
|
||||||
>
|
>
|
||||||
{t("common.buttons.configure")}
|
{t("common.buttons.configure")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const StatusPageView = () => {
|
|||||||
const { url } = useParams();
|
const { url } = useParams();
|
||||||
const isAdmin = useIsAdmin();
|
const isAdmin = useIsAdmin();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isPublic = location.pathname.startsWith("/status/uptime/public");
|
const isPublic = location.pathname.startsWith("/status/public");
|
||||||
|
|
||||||
const apiUrl = url ? `/status-page/${url}?type=uptime` : null;
|
const apiUrl = url ? `/status-page/${url}?type=uptime` : null;
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ const StatusPageView = () => {
|
|||||||
{t("pages.statusPages.details.empty.title")}
|
{t("pages.statusPages.details.empty.title")}
|
||||||
</Typography>
|
</Typography>
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<Link to={`/status/uptime/configure/${url}`}>
|
<Link to={`/status/configure/${url}`}>
|
||||||
{t("pages.statusPages.details.empty.addMonitor")}
|
{t("pages.statusPages.details.empty.addMonitor")}
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const StatusPagesTable = ({ data }: StatusPagesTableProps) => {
|
|||||||
const handleUrlClick = (e: React.MouseEvent, row: StatusPage) => {
|
const handleUrlClick = (e: React.MouseEvent, row: StatusPage) => {
|
||||||
if (row.isPublished) {
|
if (row.isPublished) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
const url = `/status/uptime/public/${row.url}`;
|
const url = `/status/public/${row.url}`;
|
||||||
window.open(url, "_blank", "noopener,noreferrer");
|
window.open(url, "_blank", "noopener,noreferrer");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -91,7 +91,7 @@ export const StatusPagesTable = ({ data }: StatusPagesTableProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleRowClick = (statusPage: StatusPage) => {
|
const handleRowClick = (statusPage: StatusPage) => {
|
||||||
navigate(`/status/uptime/${statusPage.url}`);
|
navigate(`/status/${statusPage.url}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ const StatusPages = () => {
|
|||||||
error={!!error}
|
error={!!error}
|
||||||
items={statusPages ?? []}
|
items={statusPages ?? []}
|
||||||
actionButtonText={t("pages.statusPages.fallback.actionButton")}
|
actionButtonText={t("pages.statusPages.fallback.actionButton")}
|
||||||
actionLink="/status/uptime/create"
|
actionLink="/status/create"
|
||||||
>
|
>
|
||||||
<HeaderCreate
|
<HeaderCreate
|
||||||
path="/status/uptime/create"
|
path="/status/create"
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
/>
|
/>
|
||||||
<StatusPagesTable data={statusPages ?? []} />
|
<StatusPagesTable data={statusPages ?? []} />
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ const Routes = () => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="status/uptime/:url"
|
path="status/:url"
|
||||||
element={
|
element={
|
||||||
<>
|
<>
|
||||||
<ThemeProvider theme={v2theme}>
|
<ThemeProvider theme={v2theme}>
|
||||||
@@ -248,7 +248,7 @@ const Routes = () => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="status/uptime/create"
|
path="status/create"
|
||||||
element={
|
element={
|
||||||
<>
|
<>
|
||||||
<ThemeProvider theme={v2theme}>
|
<ThemeProvider theme={v2theme}>
|
||||||
@@ -259,7 +259,7 @@ const Routes = () => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Route
|
<Route
|
||||||
path="status/uptime/configure/:url"
|
path="status/configure/:url"
|
||||||
element={
|
element={
|
||||||
<>
|
<>
|
||||||
<ThemeProvider theme={v2theme}>
|
<ThemeProvider theme={v2theme}>
|
||||||
@@ -377,7 +377,7 @@ const Routes = () => {
|
|||||||
element={<AuthNewPasswordConfirmed />}
|
element={<AuthNewPasswordConfirmed />}
|
||||||
/>
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="/status/uptime/public/:url"
|
path="/status/public/:url"
|
||||||
element={
|
element={
|
||||||
<>
|
<>
|
||||||
<ThemeProvider theme={v2theme}>
|
<ThemeProvider theme={v2theme}>
|
||||||
|
|||||||
@@ -861,6 +861,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"statusPages": {
|
"statusPages": {
|
||||||
|
"deleteSuccess": "Status page deleted successfully",
|
||||||
"fallback": {
|
"fallback": {
|
||||||
"title": "A status page is used to:",
|
"title": "A status page is used to:",
|
||||||
"checks": [
|
"checks": [
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class StatusPageRoutes {
|
|||||||
this.router.put("/:id", upload.single("logo"), verifyJWT, this.statusPageController.updateStatusPage);
|
this.router.put("/:id", upload.single("logo"), verifyJWT, this.statusPageController.updateStatusPage);
|
||||||
|
|
||||||
this.router.get("/:url", this.statusPageController.getStatusPageByUrl);
|
this.router.get("/:url", this.statusPageController.getStatusPageByUrl);
|
||||||
this.router.delete("/:url(*)", verifyJWT, this.statusPageController.deleteStatusPage);
|
this.router.delete("/:id", verifyJWT, this.statusPageController.deleteStatusPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRouter() {
|
getRouter() {
|
||||||
|
|||||||
Reference in new issue
Block a user