added missing setup (#39632) (#39679)

fixes: #39612


(cherry picked from commit 9273ac965a4ee0c37fef00c3402e002dc7f5d024)

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2025-05-14 19:40:53 +02:00 committed by GitHub
parent e9d240acb5
commit 63396368d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,7 +46,19 @@ export const OtpPolicy = ({ realm, realmUpdated }: OtpPolicyProps) => {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const form = useForm<FormFields>({ mode: "onChange" });
const form = useForm<FormFields>({
mode: "onChange",
defaultValues: {
otpPolicyType: realm.otpPolicyType ?? POLICY_TYPES[0],
otpPolicyAlgorithm:
realm.otpPolicyAlgorithm ?? `Hmac${OTP_HASH_ALGORITHMS[0]}`,
otpPolicyDigits: realm.otpPolicyDigits ?? NUMBER_OF_DIGITS[0],
otpPolicyLookAheadWindow: realm.otpPolicyLookAheadWindow ?? 1,
otpPolicyPeriod: realm.otpPolicyPeriod ?? 30,
otpPolicyInitialCounter: realm.otpPolicyInitialCounter ?? 30,
otpPolicyCodeReusable: realm.otpPolicyCodeReusable ?? false,
},
});
const {
control,
reset,
@ -57,11 +69,7 @@ export const OtpPolicy = ({ realm, realmUpdated }: OtpPolicyProps) => {
const { addAlert, addError } = useAlerts();
const localeSort = useLocaleSort();
const otpType = useWatch({
name: "otpPolicyType",
control,
defaultValue: POLICY_TYPES[0],
});
const otpType = useWatch({ name: "otpPolicyType", control });
const setupForm = (formValues: FormFields) => reset(formValues);
@ -108,16 +116,16 @@ export const OtpPolicy = ({ realm, realmUpdated }: OtpPolicyProps) => {
data-testid="otpPolicyType"
defaultValue={POLICY_TYPES[0]}
control={control}
render={({ field }) => (
render={({ field: { value, onChange } }) => (
<>
{POLICY_TYPES.map((type) => (
<Radio
key={type}
id={type}
data-testid={type}
isChecked={field.value === type}
isChecked={value === type}
name="otpPolicyType"
onChange={() => field.onChange(type)}
onChange={() => onChange(type)}
label={t(`policyType.${type}`)}
className="keycloak__otp_policies_authentication__policy-type"
/>