maintenance

This commit is contained in:
Alex Holliday committed 2025-12-28 19:12:35 +00:00
1 parent e55ae64222
commit 24cbcec2c9
10 files changed
+40 -51

No files matched your search

@@ -1,14 +1,13 @@
import { maintenanceSchema } from "@/validation/zod";
import { useMemo } from "react";
import type { FormValues } from "@/pages/maintenance/MaintenanceForm";
import { z } from "zod";
export const useInitForm = ({
initialData,
}: {
initialData: Partial<z.infer<typeof maintenanceSchema>> | undefined;
initialData: Partial<FormValues> | undefined;
}) => {
return useMemo(() => {
const defaults: z.infer<typeof maintenanceSchema> = {
const defaults: FormValues = {
name: initialData?.name || "",
repeat: initialData?.repeat || "no repeat",
startTime: initialData?.startTime
@@ -2,13 +2,10 @@ import { MaintenanceForm } from "@/pages/maintenance/MaintenanceForm";
import { useParams } from "react-router";
import { useNavigate } from "react-router";
import { z } from "zod";
import { usePatch, useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/types/api";
import { maintenanceSchema } from "@/validation/zod";
import type { IMonitor } from "@/types/monitor";
type FormValues = z.infer<typeof maintenanceSchema>;
import type { FormValues } from "@/pages/maintenance/MaintenanceForm";
const MaintenanceConfigPage = () => {
const { id } = useParams<{ id: string }>();
@@ -1,14 +1,11 @@
import { MaintenanceForm } from "@/pages/maintenance/MaintenanceForm";
import { useNavigate } from "react-router";
import { z } from "zod";
import { usePost, useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/types/api";
import { maintenanceSchema } from "@/validation/zod";
import type { IMonitor } from "@/types/monitor";
import type { IMaintenance } from "@/types/maintenance";
type FormValues = z.infer<typeof maintenanceSchema>;
import type { FormValues } from "@/pages/maintenance/MaintenanceForm";
const MaintenanceCreatePage = () => {
const navigate = useNavigate();
@@ -12,13 +12,13 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { useTranslation } from "react-i18next";
import { z } from "zod";
import { MaintenanceRepeats } from "@/types/maintenance";
import { maintenanceSchema } from "@/validation/zod";
import { maintenanceSchema } from "@/validation";
import { useForm, Controller, type SubmitHandler } from "react-hook-form";
import { useEffect } from "react";
import { useInitForm } from "@/hooks/forms/UseInitMaintenanceForm";
import type { IMonitor } from "@/types/monitor";
type FormValues = z.infer<typeof maintenanceSchema>;
export type FormValues = z.infer<typeof maintenanceSchema>;
export const MaintenanceForm = ({
monitorOptions,
@@ -2,13 +2,10 @@ import { NotificationChannelsForm } from "./NotificationChannelsForm";
import { useParams } from "react-router";
import { useNavigate } from "react-router";
import { z } from "zod";
import { usePatch, useGet } from "@/hooks/UseApi";
import type { ApiResponse } from "@/types/api";
import { notificationChannelSchema } from "@/validation";
import type { INotificationChannel } from "@/types/notification-channel";
type FormValues = z.infer<typeof notificationChannelSchema>;
import type { FormValues } from "./NotificationChannelsForm";
const NotificationsChannelConfigPage = () => {
const navigate = useNavigate();
@@ -1,12 +1,9 @@
import { NotificationChannelsForm } from "./NotificationChannelsForm";
import { useNavigate } from "react-router";
import { z } from "zod";
import { usePost } from "@/hooks/UseApi";
import { notificationChannelSchema } from "@/validation";
import type { INotificationChannel } from "@/types/notification-channel";
type FormValues = z.infer<typeof notificationChannelSchema>;
import type { FormValues } from "./NotificationChannelsForm";
const NotificationsChannelCreatePage = () => {
const { post, loading } = usePost<FormValues, INotificationChannel>();
@@ -17,7 +17,7 @@ import { useInitForm } from "@/hooks/forms/UseInitNotificationsChannelForm";
import { Typography } from "@mui/material";
import { useTheme } from "@mui/material/styles";
type FormValues = z.infer<typeof notificationChannelSchema>;
export type FormValues = z.infer<typeof notificationChannelSchema>;
export const NotificationChannelsForm = ({
initialData,
+1
View File
@@ -6,3 +6,4 @@ export * from "./pagespeed";
export * from "./infra";
export * from "./utils";
export * from "./notification-channel";
export * from "./maintenance";
+29
View File
@@ -0,0 +1,29 @@
import { z } from "zod";
import { MaintenanceRepeats } from "@/types/maintenance";
export const maintenanceSchema = z
.object({
name: z.string().min(1, "Maintenance name is required"),
repeat: z.enum(MaintenanceRepeats),
startTime: z.date(),
endTime: z.date(),
monitors: z.array(z.string()),
})
.superRefine((data, ctx) => {
if (data.endTime <= data.startTime) {
ctx.addIssue({
code: "custom",
path: ["endTime"],
message: "End time must be after start time",
});
}
if (data.startTime === data.endTime) {
ctx.addIssue({
code: "custom",
path: ["endTime"],
message: "Start time and end time cannot be the same",
});
}
});
-28
View File
@@ -39,34 +39,6 @@ export const inviteSchema = z.object({
orgRoleId: z.string().optional(),
});
// moved to client/src/validation/notification-channel.ts
export const maintenanceSchema = z
.object({
name: z.string().min(1, "Maintenance name is required"),
repeat: z.enum(MaintenanceRepeats),
startTime: z.date(),
endTime: z.date(),
monitors: z.array(z.string()),
})
.superRefine((data, ctx) => {
if (data.endTime <= data.startTime) {
ctx.addIssue({
code: "custom",
path: ["endTime"],
message: "End time must be after start time",
});
}
if (data.startTime === data.endTime) {
ctx.addIssue({
code: "custom",
path: ["endTime"],
message: "Start time and end time cannot be the same",
});
}
});
export const systemSettingsSchema = z.object({
systemEmailHost: optionalString(
z.string().trim().min(1, { message: "SMTP host is required" }).max(255, {