Merge pull request #3624 from bluewave-labs/fix/status-page-mutate-on-save
fix: mutate status page on save
This commit is contained in:
1 file changed
+9
-3
@@ -32,6 +32,7 @@ import type { MonitorDisplayType, StatusPageResponse } from "@/Types/StatusPage"
|
|||||||
import { getMonitorTypeLabel } from "@/Types/StatusPage";
|
import { getMonitorTypeLabel } from "@/Types/StatusPage";
|
||||||
import timezones from "@/Utils/timezones.json";
|
import timezones from "@/Utils/timezones.json";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
|
import { mutate } from "swr";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { HeaderConfigStatusControls } from "./Components/HeaderConfigStatusControls";
|
import { HeaderConfigStatusControls } from "./Components/HeaderConfigStatusControls";
|
||||||
import { ThemePicker } from "./Components/ThemePicker";
|
import { ThemePicker } from "./Components/ThemePicker";
|
||||||
@@ -49,6 +50,9 @@ interface TimezoneOption {
|
|||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildStatusPageKey = (slug: string | null | undefined) =>
|
||||||
|
slug ? `/status-page/${slug}?type=uptime&type=infrastructure` : null;
|
||||||
|
|
||||||
const CreateStatusPage = () => {
|
const CreateStatusPage = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -59,9 +63,7 @@ const CreateStatusPage = () => {
|
|||||||
|
|
||||||
// Fetch existing status page data when configuring
|
// Fetch existing status page data when configuring
|
||||||
const { data: statusPageData, isLoading: isLoadingStatusPage } =
|
const { data: statusPageData, isLoading: isLoadingStatusPage } =
|
||||||
useGet<StatusPageResponse>(
|
useGet<StatusPageResponse>(isCreate ? null : buildStatusPageKey(url));
|
||||||
isCreate ? null : `/status-page/${url}?type=uptime&type=infrastructure`
|
|
||||||
);
|
|
||||||
|
|
||||||
const { data: monitorsResponse } = useGet<Monitor[]>(monitorsUrl);
|
const { data: monitorsResponse } = useGet<Monitor[]>(monitorsUrl);
|
||||||
const monitors = monitorsResponse ?? [];
|
const monitors = monitorsResponse ?? [];
|
||||||
@@ -181,6 +183,10 @@ const CreateStatusPage = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
await mutate(buildStatusPageKey(data.url));
|
||||||
|
if (!isCreate && url !== data.url) {
|
||||||
|
await mutate(buildStatusPageKey(url));
|
||||||
|
}
|
||||||
navigate(`/status/${data.url}`);
|
navigate(`/status/${data.url}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user