import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; import { ActionGroup, Button, FormGroup, NumberInput, Switch, } from "@patternfly/react-core"; import { useEffect } from "react"; import { Controller, FormProvider, useForm, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { FormAccess } from "../../components/form/FormAccess"; import { HelpItem } from "ui-shared"; import { convertToFormValues } from "../../util"; import { Time } from "./Time"; type BruteForceDetectionProps = { realm: RealmRepresentation; save: (realm: RealmRepresentation) => void; }; export const BruteForceDetection = ({ realm, save, }: BruteForceDetectionProps) => { const { t } = useTranslation("realm-settings"); const form = useForm(); const { setValue, handleSubmit, control, formState: { isDirty }, } = form; const enable = useWatch({ control, name: "bruteForceProtected", }); const permanentLockout = useWatch({ control, name: "permanentLockout", }); const setupForm = () => convertToFormValues(realm, setValue); useEffect(setupForm, []); return ( ( )} /> {enable && ( <> } fieldId="failureFactor" > ( field.onChange(field.value + 1)} onMinus={() => field.onChange(field.value - 1)} onChange={(event) => field.onChange( Number((event.target as HTMLInputElement).value) ) } /> )} /> ( )} /> {!permanentLockout && ( <> ); };