feat(client): split uptime monitor creation into a 3-step wizard
This commit is contained in:
1 parent
9ffe0caed9
commit
c98ec7d047
2 files changed
+110
-13
No files matched your search
@@ -3,6 +3,7 @@ import { useEffect } from "react";
|
||||
import { logger } from "@/Utils/logger";
|
||||
import { useParams, useLocation, useNavigate } from "react-router";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import type { FieldPath } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useTheme } from "@mui/material";
|
||||
import Stack from "@mui/material/Stack";
|
||||
@@ -18,7 +19,12 @@ import { Trash2 } from "lucide-react";
|
||||
import { HeaderDeleteControls } from "@/Components/monitors";
|
||||
import { GeoContinents } from "@/Types/GeoCheck";
|
||||
|
||||
import { BasePage, ColoredLabel, ConfigBox } from "@/Components/design-elements";
|
||||
import {
|
||||
BasePage,
|
||||
ColoredLabel,
|
||||
ConfigBox,
|
||||
StepProgress,
|
||||
} from "@/Components/design-elements";
|
||||
import {
|
||||
RadioWithDescription,
|
||||
Button,
|
||||
@@ -207,6 +213,33 @@ const getGeneralSettingsConfig = (
|
||||
return configs[type] || configs.http;
|
||||
};
|
||||
|
||||
const TOTAL_STEPS = 3;
|
||||
|
||||
// Fields validated before advancing past each wizard step (uptime create only).
|
||||
const STEP_FIELDS: FieldPath<MonitorFormData>[][] = [
|
||||
[
|
||||
"type",
|
||||
"url",
|
||||
"name",
|
||||
"port",
|
||||
"gameId",
|
||||
"grpcServiceName",
|
||||
"dnsServer",
|
||||
"dnsRecordType",
|
||||
],
|
||||
["interval", "statusWindowSize", "statusWindowThreshold", "notifications", "tags"],
|
||||
[
|
||||
"ignoreTlsErrors",
|
||||
"useAdvancedMatching",
|
||||
"matchMethod",
|
||||
"expectedValue",
|
||||
"jsonPath",
|
||||
"geoCheckEnabled",
|
||||
"geoCheckLocations",
|
||||
"geoCheckInterval",
|
||||
],
|
||||
];
|
||||
|
||||
const CreateMonitorPage = () => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
@@ -249,12 +282,25 @@ const CreateMonitorPage = () => {
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: defaults,
|
||||
});
|
||||
const { control, watch, handleSubmit, clearErrors } = form;
|
||||
const { control, watch, handleSubmit, clearErrors, trigger } = form;
|
||||
|
||||
useEffect(() => {
|
||||
form.reset(defaults);
|
||||
}, [defaults, form]);
|
||||
|
||||
// Multi-step wizard (uptime create only). Other flows keep the flat form.
|
||||
const isWizard = showTypeSelector;
|
||||
const [currentStep, setCurrentStep] = useState(0);
|
||||
const showStep = (step: number) => !isWizard || currentStep === step;
|
||||
|
||||
const handleNext = async () => {
|
||||
const isValid = await trigger(STEP_FIELDS[currentStep]);
|
||||
if (isValid) {
|
||||
setCurrentStep((step) => Math.min(step + 1, TOTAL_STEPS - 1));
|
||||
}
|
||||
};
|
||||
const handleBack = () => setCurrentStep((step) => Math.max(step - 1, 0));
|
||||
|
||||
const watchedType = watch("type") as MonitorType;
|
||||
|
||||
const watchedUseAdvancedMatching = watch("useAdvancedMatching") as boolean;
|
||||
@@ -332,8 +378,14 @@ const CreateMonitorPage = () => {
|
||||
refetch={refetchMonitor}
|
||||
onDelete={handleDeleteClick}
|
||||
/>
|
||||
{isWizard && (
|
||||
<StepProgress
|
||||
steps={TOTAL_STEPS}
|
||||
current={currentStep}
|
||||
/>
|
||||
)}
|
||||
{/* Monitor Type Selection - only shown for uptime monitors */}
|
||||
{showTypeSelector && (
|
||||
{showTypeSelector && showStep(0) && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.type.title")}
|
||||
subtitle={t("pages.createMonitor.form.type.description")}
|
||||
@@ -411,6 +463,7 @@ const CreateMonitorPage = () => {
|
||||
/>
|
||||
)}
|
||||
|
||||
{showStep(0) && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.general.title")}
|
||||
subtitle={
|
||||
@@ -513,7 +566,9 @@ const CreateMonitorPage = () => {
|
||||
error={!!fieldState.error}
|
||||
>
|
||||
<MenuItem value="">
|
||||
{t("pages.createMonitor.form.general.option.game.placeholder")}{" "}
|
||||
{t(
|
||||
"pages.createMonitor.form.general.option.game.placeholder"
|
||||
)}{" "}
|
||||
</MenuItem>
|
||||
{games &&
|
||||
Object.entries(games).map(([key, game]) => (
|
||||
@@ -563,7 +618,9 @@ const CreateMonitorPage = () => {
|
||||
{...field}
|
||||
value={field.value ?? ""}
|
||||
type="text"
|
||||
fieldLabel={t("pages.createMonitor.form.general.option.secret.label")}
|
||||
fieldLabel={t(
|
||||
"pages.createMonitor.form.general.option.secret.label"
|
||||
)}
|
||||
placeholder={t(
|
||||
"pages.createMonitor.form.general.option.secret.placeholder"
|
||||
)}
|
||||
@@ -611,7 +668,9 @@ const CreateMonitorPage = () => {
|
||||
error={!!fieldState.error}
|
||||
>
|
||||
<MenuItem value={"A"}>
|
||||
{t("pages.createMonitor.form.general.option.dnsRecordType.value.A")}
|
||||
{t(
|
||||
"pages.createMonitor.form.general.option.dnsRecordType.value.A"
|
||||
)}
|
||||
</MenuItem>
|
||||
<MenuItem value={"AAAA"}>
|
||||
{t(
|
||||
@@ -661,7 +720,9 @@ const CreateMonitorPage = () => {
|
||||
</Stack>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{showStep(1) && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.frequency.title")}
|
||||
subtitle={t("pages.createMonitor.form.frequency.description")}
|
||||
@@ -733,9 +794,10 @@ const CreateMonitorPage = () => {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Alert Thresholds - only for hardware type */}
|
||||
{generalSettingsConfig.showSecret && (
|
||||
{generalSettingsConfig.showSecret && showStep(1) && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.thresholds.title")}
|
||||
subtitle={t("pages.createMonitor.form.thresholds.description")}
|
||||
@@ -818,6 +880,7 @@ const CreateMonitorPage = () => {
|
||||
/>
|
||||
)}
|
||||
|
||||
{showStep(1) && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.incidents.title")}
|
||||
subtitle={t("pages.createMonitor.form.incidents.description")}
|
||||
@@ -830,7 +893,9 @@ const CreateMonitorPage = () => {
|
||||
<SliderWithLabel
|
||||
{...field}
|
||||
sliderMaxWidth={{ xs: "100%", md: "50%" }}
|
||||
fieldLabel={t("pages.createMonitor.form.incidents.option.checks.label")}
|
||||
fieldLabel={t(
|
||||
"pages.createMonitor.form.incidents.option.checks.label"
|
||||
)}
|
||||
min={1}
|
||||
max={25}
|
||||
valueLabelDisplay="auto"
|
||||
@@ -856,7 +921,9 @@ const CreateMonitorPage = () => {
|
||||
</Stack>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{showStep(1) && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.notifications.title")}
|
||||
subtitle={t("pages.createMonitor.form.notifications.description")}
|
||||
@@ -924,7 +991,9 @@ const CreateMonitorPage = () => {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{showStep(1) && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.tags.title")}
|
||||
subtitle={t("pages.createMonitor.form.tags.description")}
|
||||
@@ -978,7 +1047,9 @@ const CreateMonitorPage = () => {
|
||||
size="small"
|
||||
onClick={() => {
|
||||
field.onChange(
|
||||
(field.value ?? []).filter((id: string) => id !== tag.id)
|
||||
(field.value ?? []).filter(
|
||||
(id: string) => id !== tag.id
|
||||
)
|
||||
);
|
||||
}}
|
||||
aria-label="Remove tag"
|
||||
@@ -996,8 +1067,10 @@ const CreateMonitorPage = () => {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
{(watchedType === "http" ||
|
||||
{showStep(2) &&
|
||||
(watchedType === "http" ||
|
||||
watchedType === "grpc" ||
|
||||
watchedType === "websocket") && (
|
||||
<ConfigBox
|
||||
@@ -1027,7 +1100,7 @@ const CreateMonitorPage = () => {
|
||||
/>
|
||||
)}
|
||||
|
||||
{watchedType === "http" && (
|
||||
{showStep(2) && watchedType === "http" && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.advanced.title")}
|
||||
subtitle={t("pages.createMonitor.form.advanced.description")}
|
||||
@@ -1142,7 +1215,7 @@ const CreateMonitorPage = () => {
|
||||
/>
|
||||
)}
|
||||
|
||||
{supportsGeoCheck(watchedType) && (
|
||||
{showStep(2) && supportsGeoCheck(watchedType) && (
|
||||
<ConfigBox
|
||||
title={t("pages.createMonitor.form.geoChecks.title")}
|
||||
subtitle={t("pages.createMonitor.form.geoChecks.description")}
|
||||
@@ -1278,8 +1351,29 @@ const CreateMonitorPage = () => {
|
||||
|
||||
<Stack
|
||||
direction="row"
|
||||
justifyContent="flex-end"
|
||||
justifyContent={isWizard ? "space-between" : "flex-end"}
|
||||
>
|
||||
{isWizard && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outlined"
|
||||
color="secondary"
|
||||
disabled={currentStep === 0}
|
||||
onClick={handleBack}
|
||||
>
|
||||
{t("common.buttons.back")}
|
||||
</Button>
|
||||
)}
|
||||
{isWizard && currentStep < TOTAL_STEPS - 1 ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
onClick={handleNext}
|
||||
>
|
||||
{t("common.buttons.next")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
loading={isSubmitting}
|
||||
type="submit"
|
||||
@@ -1288,6 +1382,7 @@ const CreateMonitorPage = () => {
|
||||
>
|
||||
{t("common.buttons.save")}
|
||||
</Button>
|
||||
)}
|
||||
</Stack>
|
||||
<Dialog
|
||||
open={isDeleteDialogOpen}
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
"pause": "Pause",
|
||||
"resume": "Resume",
|
||||
"save": "Save",
|
||||
"next": "Next",
|
||||
"back": "Back",
|
||||
"sendInvite": "Send invite",
|
||||
"test": "Test",
|
||||
"testNotifications": "Test notifications",
|
||||
|
||||
Reference in new issue
Block a user