import { LuPlus, LuX } from "react-icons/lu"; import { useFieldArray, useFormContext } from "react-hook-form"; import validator from "validator"; import { useEffect } from "react"; import { GridCard } from "@/components/Card"; import { Button } from "@/components/Button"; import { InputFieldWithLabel } from "@/components/InputField"; import { NetworkSettings } from "@/hooks/stores"; export default function StaticIpv6Card() { const formMethods = useFormContext(); const { register, formState, watch } = formMethods; const { fields, append, remove } = useFieldArray({ name: "ipv6_static.dns" }); useEffect(() => { if (fields.length === 0) append(""); }, [append, fields.length]); const dns = watch("ipv6_static.dns"); const cidrValidation = (value: string) => { if (value === "") return true; // Check if it's a valid IPv6 address with CIDR notation const parts = value.split("/"); if (parts.length !== 2) return "Please use CIDR notation (e.g., 2001:db8::1/64)"; const [address, prefix] = parts; if (!validator.isIP(address, 6)) return "Invalid IPv6 address"; const prefixNum = parseInt(prefix); if (isNaN(prefixNum) || prefixNum < 0 || prefixNum > 128) { return "Prefix must be between 0 and 128"; } return true; }; const ipv6Validation = (value: string) => { if (!validator.isIP(value, 6)) return "Invalid IPv6 address"; return true; }; return (

Static IPv6 Configuration

cidrValidation(value ?? "") })} error={formState.errors.ipv6_static?.prefix?.message} /> ipv6Validation(value ?? "") })} error={formState.errors.ipv6_static?.gateway?.message} /> {/* DNS server fields */}
{fields.map((dns, index) => { return (
ipv6Validation(value ?? "") })} error={formState.errors.ipv6_static?.dns?.[index]?.message} />
{index > 0 && (
)}
); })}
); }