"use client"; import { useFormState } from "react-dom"; import { useEffect, useState } from "react"; import { createL4ProxyHostAction, deleteL4ProxyHostAction, updateL4ProxyHostAction, } from "@/app/(dashboard)/l4-proxy-hosts/actions"; 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 { Badge } from "@/components/ui/badge"; 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"; import { cn } from "@/lib/utils"; import { Globe, Layers, MapPin, Pin } from "lucide-react"; function FormField({ label, htmlFor, helperText, children, }: { label: string; htmlFor: string; helperText?: string; children: React.ReactNode; }) { return (
{children} {helperText && (

{helperText}

)}
); } function L4HostForm({ formId, formAction, state, initialData, }: { formId: string; formAction: (formData: FormData) => void; state: { status: string; message?: string }; initialData?: L4ProxyHost | null; }) { const [enabled, setEnabled] = useState(initialData?.enabled ?? true); const [protocol, setProtocol] = useState(initialData?.protocol ?? "tcp"); 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} )}

{enabled ? "L4 Host Enabled" : "L4 Host Paused"}

{enabled ? "This host is active and proxying connections" : "This host is disabled and will not accept connections"}