diff --git a/src/components/modules/networkRoutes.tsx b/src/components/modules/networkRoutes.tsx index e37b42a7..9a2b3ce8 100644 --- a/src/components/modules/networkRoutes.tsx +++ b/src/components/modules/networkRoutes.tsx @@ -5,9 +5,14 @@ import { type RoutesEntity } from "~/types/network"; import { type ChangeEvent, useState } from "react"; import { type ErrorData } from "~/types/errorHandling"; +const initialRouteInput = { + target: "", + via: "", +}; + export const NettworkRoutes = () => { const [showRouteInput, setShowRouteInput] = useState(false); - const [routeInput, setRouteInput] = useState(); + const [routeInput, setRouteInput] = useState(initialRouteInput); const { query } = useRouter(); const { @@ -64,6 +69,7 @@ export const NettworkRoutes = () => { onSuccess: () => { void refecthNetworkById(); setShowRouteInput(false); + setRouteInput(initialRouteInput); }, } ); diff --git a/src/server/api/routers/networkRouter.ts b/src/server/api/routers/networkRouter.ts index e74d93b0..0b012b0e 100644 --- a/src/server/api/routers/networkRouter.ts +++ b/src/server/api/routers/networkRouter.ts @@ -42,14 +42,20 @@ function isValidDomain(domain: string): boolean { return domainRegex.test(domain); } const RouteSchema = z.object({ - target: z.string().refine(isValidCIDR, { - message: "Destination IP must be a valid CIDR notation!", - }), + target: z + .string() + .optional() + .refine((val) => val !== undefined && isValidCIDR(val), { + message: "Destination IP must be a valid CIDR notation!", + }), via: z .union([ - z.string().refine(isValidIP, { - message: "Via IP must be a valid IP address!", - }), + z + .string() + .optional() + .refine((val) => !val || isValidIP(val), { + message: "Via IP must be a valid IP address!", + }), z.null(), ]) .optional(),