diff --git a/src/components/resource-policy/CreatePolicyAuthMethodsSectionForm.tsx b/src/components/resource-policy/CreatePolicyAuthMethodsSectionForm.tsx index fb456e823..f881104cb 100644 --- a/src/components/resource-policy/CreatePolicyAuthMethodsSectionForm.tsx +++ b/src/components/resource-policy/CreatePolicyAuthMethodsSectionForm.tsx @@ -43,10 +43,11 @@ import { InputOTPSlot } from "@app/components/ui/input-otp"; +import { cn } from "@app/lib/cn"; import { Binary, Bot, Key, Plus } from "lucide-react"; import { useState } from "react"; -import { type UseFormReturn, useForm } from "react-hook-form"; +import { type UseFormReturn, useForm, useWatch } from "react-hook-form"; // ─── CreatePolicyAuthMethodsSectionForm ─────────────────────────────────────── @@ -72,14 +73,23 @@ export function CreatePolicyAuthMethodsSectionForm({ form }: CreatePolicyAuthMethodsSectionFormProps) { const t = useTranslations(); - const [isOpen, setIsOpen] = useState(false); + const [isExpanded, setIsExpanded] = useState(false); const [isSetPasswordOpen, setIsSetPasswordOpen] = useState(false); const [isSetPincodeOpen, setIsSetPincodeOpen] = useState(false); const [isSetHeaderAuthOpen, setIsSetHeaderAuthOpen] = useState(false); - const password = form.watch("password"); - const pincode = form.watch("pincode"); - const headerAuth = form.watch("headerAuth"); + const password = useWatch({ + control: form.control, + name: "password" + }); + const pincode = useWatch({ + control: form.control, + name: "pincode" + }); + const headerAuth = useWatch({ + control: form.control, + name: "headerAuth" + }); const passwordForm = useForm({ resolver: zodResolver(setPasswordSchema), @@ -96,7 +106,7 @@ export function CreatePolicyAuthMethodsSectionForm({ defaultValues: { user: "", password: "", extendedCompatibility: true } }); - if (!isOpen) { + if (!isExpanded) { return ( @@ -111,7 +121,7 @@ export function CreatePolicyAuthMethodsSectionForm({