From 6bb584a336b975e835b865210b0180f54c66dc73 Mon Sep 17 00:00:00 2001 From: wangsijie Date: Mon, 23 Dec 2024 12:19:55 +0800 Subject: [PATCH] fix(console): fix mfa form mandatory reset (#6901) --- packages/console/src/pages/Mfa/MfaForm/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/console/src/pages/Mfa/MfaForm/index.tsx b/packages/console/src/pages/Mfa/MfaForm/index.tsx index 27bb02b0c..c96faf021 100644 --- a/packages/console/src/pages/Mfa/MfaForm/index.tsx +++ b/packages/console/src/pages/Mfa/MfaForm/index.tsx @@ -50,6 +50,7 @@ function MfaForm({ data, onMfaUpdated }: Props) { handleSubmit, control, watch, + setValue, } = useForm({ defaultValues: convertMfaConfigToForm(data), mode: 'onChange' }); const api = useApi(); @@ -69,11 +70,12 @@ function MfaForm({ data, onMfaUpdated }: Props) { }, [formValues, isMfaDisabled]); useEffect(() => { - // Reset the `isMandatory` to false when the policy settings are disabled - if (isPolicySettingsDisabled) { - reset({ ...formValues, isMandatory: false }); + // Reset the `isMandatory` to false when there is no MFA factor + const { factors } = convertMfaFormToConfig(formValues); + if (factors.length === 0 && formValues.isMandatory) { + setValue('isMandatory', false); } - }, [isPolicySettingsDisabled, reset, formValues]); + }, [formValues, setValue]); const mfaPolicyOptions = useMemo( () => [