mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-02 00:36:38 +00:00
fix target validation on create site
This commit is contained in:
@@ -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")}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user