Skip to content

Commit

Permalink
fix(console): fix mfa form mandatory reset (#6901)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsijie authored Dec 23, 2024
1 parent 74c9282 commit 6bb584a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/console/src/pages/Mfa/MfaForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function MfaForm({ data, onMfaUpdated }: Props) {
handleSubmit,
control,
watch,
setValue,
} = useForm<MfaConfigForm>({ defaultValues: convertMfaConfigToForm(data), mode: 'onChange' });
const api = useApi();

Expand All @@ -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(
() => [
Expand Down

0 comments on commit 6bb584a

Please sign in to comment.