diff --git a/src/components/l4-proxy-hosts/L4HostDialogs.tsx b/src/components/l4-proxy-hosts/L4HostDialogs.tsx index 423d71ca..3cfa030a 100644 --- a/src/components/l4-proxy-hosts/L4HostDialogs.tsx +++ b/src/components/l4-proxy-hosts/L4HostDialogs.tsx @@ -1,5 +1,5 @@ -import { Accordion, AccordionDetails, AccordionSummary, Alert, Box, FormControlLabel, MenuItem, Stack, Switch, TextField, Typography } from "@mui/material"; -import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; +"use client"; + import { useFormState } from "react-dom"; import { useEffect, useState } from "react"; import { @@ -7,9 +7,49 @@ import { deleteL4ProxyHostAction, updateL4ProxyHostAction, } from "@/app/(dashboard)/l4-proxy-hosts/actions"; -import { INITIAL_ACTION_STATE } from "@/src/lib/actions"; -import type { L4ProxyHost } from "@/src/lib/models/l4-proxy-hosts"; -import { AppDialog } from "@/src/components/ui/AppDialog"; +import { INITIAL_ACTION_STATE } from "@/lib/actions"; +import type { L4ProxyHost } from "@/lib/models/l4-proxy-hosts"; +import { AppDialog } from "@/components/ui/AppDialog"; +import { Alert, AlertDescription } from "@/components/ui/alert"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Switch } from "@/components/ui/switch"; +import { Textarea } from "@/components/ui/textarea"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/ui/accordion"; + +function FormField({ + label, + htmlFor, + helperText, + children, +}: { + label: string; + htmlFor: string; + helperText?: string; + children: React.ReactNode; +}) { + return ( +
+ + {children} + {helperText && ( +

{helperText}

+ )} +
+ ); +} function L4HostForm({ formId, @@ -23,310 +63,694 @@ function L4HostForm({ initialData?: L4ProxyHost | null; }) { const [protocol, setProtocol] = useState(initialData?.protocol ?? "tcp"); - const [matcherType, setMatcherType] = useState(initialData?.matcher_type ?? "none"); + const [matcherType, setMatcherType] = useState( + initialData?.matcher_type ?? "none" + ); + + const defaultLbAccordion = initialData?.load_balancer?.enabled + ? "load-balancer" + : undefined; + const defaultDnsAccordion = initialData?.dns_resolver?.enabled + ? "dns-resolver" + : undefined; + const defaultGeoblockAccordion = initialData?.geoblock?.enabled + ? "geoblock" + : undefined; + const defaultUpstreamDnsAccordion = + initialData?.upstream_dns_resolution?.enabled === true + ? "upstream-dns" + : undefined; return ( - +
{state.status !== "idle" && state.message && ( - - {state.message} + + {state.message} )} - - } - label="Enabled" - /> +
+ + +
- + + + - setProtocol(e.target.value as "tcp" | "udp")} - fullWidth - > - TCP - UDP - +
+ + +
- - - - - setMatcherType(e.target.value as "none" | "tls_sni" | "http_host" | "proxy_protocol")} - helperText="Match incoming connections before proxying. 'None' matches all connections on this port." - fullWidth > - None (catch-all) - TLS SNI - HTTP Host - Proxy Protocol - + + + + +