From 003f0cfa6d475c0c6e785ab3a6598eceab588dcd Mon Sep 17 00:00:00 2001 From: miloschwartz Date: Wed, 15 Oct 2025 20:43:59 -0700 Subject: [PATCH] fix target validation on create site --- .../resources/[niceId]/proxy/page.tsx | 2 +- .../settings/resources/create/page.tsx | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/app/[orgId]/settings/resources/[niceId]/proxy/page.tsx b/src/app/[orgId]/settings/resources/[niceId]/proxy/page.tsx index 7c90789a..a399a6fa 100644 --- a/src/app/[orgId]/settings/resources/[niceId]/proxy/page.tsx +++ b/src/app/[orgId]/settings/resources/[niceId]/proxy/page.tsx @@ -1051,7 +1051,7 @@ export default function ReverseProxyTargets(props: { "text-muted-foreground" )} > - + {row.original.siteId ? selectedSite?.name : t("siteSelect")} diff --git a/src/app/[orgId]/settings/resources/create/page.tsx b/src/app/[orgId]/settings/resources/create/page.tsx index 92413149..04103a13 100644 --- a/src/app/[orgId]/settings/resources/create/page.tsx +++ b/src/app/[orgId]/settings/resources/create/page.tsx @@ -372,6 +372,30 @@ export default function Page() { const watchedPort = addTargetForm.watch("port"); const watchedSiteId = addTargetForm.watch("siteId"); + // Helper function to check if all targets have required fields using schema validation + const areAllTargetsValid = () => { + if (targets.length === 0) return true; // No targets is valid + + return targets.every(target => { + try { + addTargetSchema.parse({ + ip: target.ip, + method: target.method, + port: target.port, + siteId: target.siteId, + path: target.path, + pathMatchType: target.pathMatchType, + rewritePath: target.rewritePath, + rewritePathType: target.rewritePathType, + priority: target.priority + }); + return true; + } catch { + return false; + } + }); + }; + const handleContainerSelect = (hostname: string, port?: number) => { addTargetForm.setValue("ip", hostname); if (port) { @@ -968,7 +992,7 @@ export default function Page() { "text-muted-foreground" )} > - + {row.original.siteId ? selectedSite?.name : t("siteSelect")} @@ -1736,6 +1760,7 @@ export default function Page() { } }} loading={createLoading} + disabled={!areAllTargetsValid()} > {t("resourceCreate")}