From 8e544cca42c12700b730679acb2386741338cb84 Mon Sep 17 00:00:00 2001 From: Owen Schwartz Date: Sun, 22 Dec 2024 12:37:01 -0500 Subject: [PATCH] enforce unique port and ip targets --- .../[resourceId]/connectivity/page.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app/[orgId]/settings/resources/[resourceId]/connectivity/page.tsx b/src/app/[orgId]/settings/resources/[resourceId]/connectivity/page.tsx index 9a47e03c..1c688421 100644 --- a/src/app/[orgId]/settings/resources/[resourceId]/connectivity/page.tsx +++ b/src/app/[orgId]/settings/resources/[resourceId]/connectivity/page.tsx @@ -130,6 +130,22 @@ export default function ReverseProxyTargets(props: { }, []); async function addTarget(data: AddTargetFormValues) { + // Check if target with same IP, port and method already exists + const isDuplicate = targets.some( + target => target.ip === data.ip && + target.port === data.port && + target.method === data.method + ); + + if (isDuplicate) { + toast({ + variant: "destructive", + title: "Duplicate target", + description: "A target with these settings already exists", + }); + return; + } + const newTarget: LocalTarget = { ...data, enabled: true, @@ -141,7 +157,7 @@ export default function ReverseProxyTargets(props: { setTargets([...targets, newTarget]); addTargetForm.reset(); } - + const removeTarget = (targetId: number) => { setTargets([ ...targets.filter((target) => target.targetId !== targetId),