fix target validation on create site

This commit is contained in:
miloschwartz
2025-10-15 20:43:59 -07:00
parent ee3df081ef
commit 003f0cfa6d
2 changed files with 27 additions and 2 deletions

View File

@@ -1051,7 +1051,7 @@ export default function ReverseProxyTargets(props: {
"text-muted-foreground" "text-muted-foreground"
)} )}
> >
<span className="truncate max-w-[90px]"> <span className="truncate max-w-[150px]">
{row.original.siteId {row.original.siteId
? selectedSite?.name ? selectedSite?.name
: t("siteSelect")} : t("siteSelect")}

View File

@@ -372,6 +372,30 @@ export default function Page() {
const watchedPort = addTargetForm.watch("port"); const watchedPort = addTargetForm.watch("port");
const watchedSiteId = addTargetForm.watch("siteId"); 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) => { const handleContainerSelect = (hostname: string, port?: number) => {
addTargetForm.setValue("ip", hostname); addTargetForm.setValue("ip", hostname);
if (port) { if (port) {
@@ -968,7 +992,7 @@ export default function Page() {
"text-muted-foreground" "text-muted-foreground"
)} )}
> >
<span className="truncate max-w-[90px]"> <span className="truncate max-w-[150px]">
{row.original.siteId {row.original.siteId
? selectedSite?.name ? selectedSite?.name
: t("siteSelect")} : t("siteSelect")}
@@ -1736,6 +1760,7 @@ export default function Page() {
} }
}} }}
loading={createLoading} loading={createLoading}
disabled={!areAllTargetsValid()}
> >
{t("resourceCreate")} {t("resourceCreate")}
</Button> </Button>