feat(client): split uptime monitor creation into a 3-step wizard

This commit is contained in:
Br0wnHammer committed 2026-05-27 12:07:07 +05:30
1 parent 967e415b0a
commit 37dfc67e33
2 files changed
+38 -27

No files matched your search

+27 -26
View File
@@ -47,7 +47,7 @@ import {
} from "@/Types/Monitor"; } from "@/Types/Monitor";
import type { Notification } from "@/Types/Notification"; import type { Notification } from "@/Types/Notification";
import type { Tag } from "@/Types/Tag"; import type { Tag } from "@/Types/Tag";
import type { MonitorFormData } from "@/Validation/monitor"; import { monitorFieldsByType, type MonitorFormData } from "@/Validation/monitor";
interface GeneralSettingsConfig { interface GeneralSettingsConfig {
urlLabel: string; urlLabel: string;
@@ -218,30 +218,31 @@ const getGeneralSettingsConfig = (
const hasAdvancedStep = (type: MonitorType): boolean => const hasAdvancedStep = (type: MonitorType): boolean =>
type === "http" || type === "grpc" || type === "websocket" || supportsGeoCheck(type); type === "http" || type === "grpc" || type === "websocket" || supportsGeoCheck(type);
// Fields validated before advancing past each wizard step (uptime create only). // The wizard step on which each field is validated. Fields not listed default
const STEP_FIELDS: FieldPath<MonitorFormData>[][] = [ // to step 0, so a field added to the schema is validated by default rather than
[ // silently skipped. Step membership is the only thing hardcoded here; the field
"type", // set itself is derived from the schema via `monitorFieldsByType`.
"url", const FIELD_STEP: Record<string, number> = {
"name", interval: 1,
"port", statusWindowSize: 1,
"gameId", statusWindowThreshold: 1,
"grpcServiceName", notifications: 1,
"dnsServer", tags: 1,
"dnsRecordType", ignoreTlsErrors: 2,
], useAdvancedMatching: 2,
["interval", "statusWindowSize", "statusWindowThreshold", "notifications", "tags"], matchMethod: 2,
[ expectedValue: 2,
"ignoreTlsErrors", jsonPath: 2,
"useAdvancedMatching", geoCheckEnabled: 2,
"matchMethod", geoCheckLocations: 2,
"expectedValue", geoCheckInterval: 2,
"jsonPath", };
"geoCheckEnabled",
"geoCheckLocations", // Exactly the selected type's fields that belong to the given step.
"geoCheckInterval", const stepFieldsFor = (type: MonitorType, step: number): FieldPath<MonitorFormData>[] =>
], (monitorFieldsByType[type] ?? []).filter(
]; (field) => (FIELD_STEP[field] ?? 0) === step
) as FieldPath<MonitorFormData>[];
const CreateMonitorPage = () => { const CreateMonitorPage = () => {
const theme = useTheme(); const theme = useTheme();
@@ -304,7 +305,7 @@ const CreateMonitorPage = () => {
const totalSteps = hasAdvancedStep(watchedType) ? 3 : 2; const totalSteps = hasAdvancedStep(watchedType) ? 3 : 2;
const handleNext = async () => { const handleNext = async () => {
const isValid = await trigger(STEP_FIELDS[currentStep]); const isValid = await trigger(stepFieldsFor(watchedType, currentStep));
if (isValid) { if (isValid) {
setCurrentStep((step) => step + 1); setCurrentStep((step) => step + 1);
} }
+11 -1
View File
@@ -1,6 +1,6 @@
import { z } from "zod"; import { z } from "zod";
import { GeoContinents } from "@/Types/GeoCheck"; import { GeoContinents } from "@/Types/GeoCheck";
import { DnsRecordTypes, PageSpeedStrategies } from "@/Types/Monitor"; import { DnsRecordTypes, PageSpeedStrategies, type MonitorType } from "@/Types/Monitor";
// URL schema with custom error message // URL schema with custom error message
const urlSchema = z.url({ message: "Please enter a valid URL" }); const urlSchema = z.url({ message: "Please enter a valid URL" });
@@ -164,6 +164,16 @@ export const monitorSchema = z.discriminatedUnion("type", [
export type MonitorFormData = z.infer<typeof monitorSchema>; export type MonitorFormData = z.infer<typeof monitorSchema>;
// Field names present in each monitor type's schema, derived from the schema
// itself. Consumers (e.g. the create wizard's per-step validation) should read
// this rather than hardcoding field lists, so renames/additions stay in sync.
export const monitorFieldsByType = Object.fromEntries(
monitorSchema.options.map((option) => [
option.shape.type.value,
Object.keys(option.shape),
])
) as Record<MonitorType, string[]>;
// Type-specific schemas exported for individual use // Type-specific schemas exported for individual use
export { export {
httpSchema, httpSchema,