From 8a54fb7f23ff462deb1695e4c85ff9fa0fe74e90 Mon Sep 17 00:00:00 2001 From: Fred KISSIE Date: Tue, 3 Mar 2026 02:11:05 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20auth=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource-policy/EditPolicyForm.tsx | 282 +++++++++++------- 1 file changed, 166 insertions(+), 116 deletions(-) diff --git a/src/components/resource-policy/EditPolicyForm.tsx b/src/components/resource-policy/EditPolicyForm.tsx index 20c7a76e6..d138ff1a8 100644 --- a/src/components/resource-policy/EditPolicyForm.tsx +++ b/src/components/resource-policy/EditPolicyForm.tsx @@ -281,8 +281,8 @@ export function EditPolicyForm({ hidePolicyNameForm }: EditPolicyFormProps) { allUsers={allUsers} allIdps={allIdps} /> + {/* - ; -}; +export function PolicyAuthMethodsSection() { + const { policy } = useResourcePolicyContext(); + + const api = createApiClient(useEnvContext()); + + const form = useForm({ + resolver: zodResolver( + createPolicySchema.pick({ + password: true, + pincode: true, + headerAuth: true + }) + ), + defaultValues: {} + }); -export function PolicyAuthMethodsSection({ - form -}: PolicyAuthMethodsSectionProps) { 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); @@ -768,7 +775,18 @@ export function PolicyAuthMethodsSection({ defaultValues: { user: "", password: "", extendedCompatibility: true } }); - if (!isOpen) { + const [, formAction, isSubmitting] = useActionState(onSubmit, null); + + async function onSubmit() { + const isValid = await form.trigger(); + + if (!isValid) return; + + const payload = form.getValues(); + console.log({ payload }); + } + + if (!isExpanded) { return ( @@ -783,7 +801,7 @@ export function PolicyAuthMethodsSection({ - +
+ {}}> + + + + {t("resourceAuthMethods")} + + + {t("resourcePolicyAuthMethodsDescription")} + + + + + {/* Password row */} +
+
+ + + {t("resourcePasswordProtection", { + status: password + ? t("enabled") + : t("disabled") + })} + +
+ +
- {/* Pincode row */} -
-
- - - {t("resourcePincodeProtection", { - status: pincode - ? t("enabled") - : t("disabled") - })} - -
- -
+ {/* Pincode row */} +
+
+ + + {t("resourcePincodeProtection", { + status: pincode + ? t("enabled") + : t("disabled") + })} + +
+ +
- {/* Header auth row */} -
-
- - - {headerAuth - ? t( - "resourceHeaderAuthProtectionEnabled" - ) - : t( - "resourceHeaderAuthProtectionDisabled" - )} - -
+ {/* Header auth row */} +
+
+ + + {headerAuth + ? t( + "resourceHeaderAuthProtectionEnabled" + ) + : t( + "resourceHeaderAuthProtectionDisabled" + )} + +
+ +
+ + + +
- - - + + + ); } @@ -1170,13 +1220,13 @@ export function PolicyOtpEmailSection({ emailEnabled }: PolicyOtpEmailSectionProps) { const t = useTranslations(); - const [isOpen, setIsOpen] = useState(false); + const [isExpanded, setIsExpanded] = useState(false); const [whitelistEnabled, setWhitelistEnabled] = useState(false); const [activeEmailTagIndex, setActiveEmailTagIndex] = useState< number | null >(null); - if (!isOpen) { + if (!isExpanded) { return ( @@ -1191,7 +1241,7 @@ export function PolicyOtpEmailSection({