diff --git a/apps/admin-ui/src/authentication/components/modals/AddSubFlowModal.tsx b/apps/admin-ui/src/authentication/components/modals/AddSubFlowModal.tsx index 530e86126b..6a26243295 100644 --- a/apps/admin-ui/src/authentication/components/modals/AddSubFlowModal.tsx +++ b/apps/admin-ui/src/authentication/components/modals/AddSubFlowModal.tsx @@ -1,6 +1,4 @@ -import { useState } from "react"; -import { useTranslation } from "react-i18next"; -import { Controller, useForm } from "react-hook-form"; +import type { AuthenticationProviderRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigRepresentation"; import { Button, ButtonVariant, @@ -13,8 +11,10 @@ import { SelectVariant, ValidatedOptions, } from "@patternfly/react-core"; +import { useEffect, useState } from "react"; +import { Controller, useForm } from "react-hook-form-v7"; +import { useTranslation } from "react-i18next"; -import type { AuthenticationProviderRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigRepresentation"; import { HelpItem } from "../../../components/help-enabler/HelpItem"; import { KeycloakTextInput } from "../../../components/keycloak-text-input/KeycloakTextInput"; import { useAdminClient, useFetch } from "../../../context/auth/AdminClient"; @@ -29,7 +29,7 @@ const types = ["basic-flow", "form-flow"] as const; export type Flow = { name: string; - description?: string; + description: string; type: typeof types[number]; provider: string; }; @@ -43,6 +43,7 @@ export const AddSubFlowModal = ({ const { register, control, + setValue, handleSubmit, formState: { errors }, } = useForm(); @@ -54,40 +55,42 @@ export const AddSubFlowModal = ({ useFetch( () => adminClient.authenticationManagement.getFormProviders(), - (providers) => setFormProviders(providers), + setFormProviders, [] ); + useEffect(() => { + if (formProviders?.length === 1) { + setValue("provider", formProviders[0].id!); + } + }, [formProviders]); + return ( onCancel()} + onClose={onCancel} actions={[ , , ]} + isOpen > -
+ } + isRequired > } - fieldId="flowType" > ( + render={({ field }) => ( { - onChange(value.toString()); + field.onChange(value.toString()); setOpenProvider(false); }} - selections={value.displayName} + selections={field.value} variant={SelectVariant.single} - aria-label={t("flowType")} isOpen={openProvider} > {formProviders.map((provider) => ( {provider.displayName} @@ -213,14 +210,6 @@ export const AddSubFlowModal = ({ /> )} - {formProviders?.length === 1 && ( - - )}
);