From d26d9aaa888e45e73f39176bb92a12e295da4909 Mon Sep 17 00:00:00 2001 From: wangsijie Date: Fri, 20 Dec 2024 11:47:57 +0800 Subject: [PATCH] fix(console): auto close mfa switch (#6895) --- packages/console/src/pages/Mfa/MfaForm/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/console/src/pages/Mfa/MfaForm/index.tsx b/packages/console/src/pages/Mfa/MfaForm/index.tsx index c2d8354e3..27bb02b0c 100644 --- a/packages/console/src/pages/Mfa/MfaForm/index.tsx +++ b/packages/console/src/pages/Mfa/MfaForm/index.tsx @@ -1,5 +1,5 @@ import { MfaFactor, MfaPolicy, type SignInExperience } from '@logto/schemas'; -import { useContext, useMemo } from 'react'; +import { useContext, useEffect, useMemo } from 'react'; import { Controller, useForm } from 'react-hook-form'; import { toast } from 'react-hot-toast'; import { useTranslation } from 'react-i18next'; @@ -68,6 +68,13 @@ function MfaForm({ data, onMfaUpdated }: Props) { return factors.length === 0; }, [formValues, isMfaDisabled]); + useEffect(() => { + // Reset the `isMandatory` to false when the policy settings are disabled + if (isPolicySettingsDisabled) { + reset({ ...formValues, isMandatory: false }); + } + }, [isPolicySettingsDisabled, reset, formValues]); + const mfaPolicyOptions = useMemo( () => [ {