Reset actions should not be hard-coded. (#3499)

This commit is contained in:
Stan Silvert 2022-10-11 06:15:31 -04:00 committed by GitHub
parent d75753aa0c
commit 32f75ca109
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
import { Controller, useFormContext } from "react-hook-form";
import {
FormGroup,
@ -8,13 +9,25 @@ import {
SelectVariant,
} from "@patternfly/react-core";
import { RequiredActionAlias } from "@keycloak/keycloak-admin-client/lib/defs/requiredActionProviderRepresentation";
import { HelpItem } from "../../components/help-enabler/HelpItem";
import type RequiredActionProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/requiredActionProviderRepresentation";
export const CredentialsResetActionMultiSelect = () => {
const { t } = useTranslation("users");
const { adminClient } = useAdminClient();
const { control } = useFormContext();
const [open, setOpen] = useState(false);
const [requiredActions, setRequiredActions] = useState<
RequiredActionProviderRepresentation[]
>([]);
useFetch(
() => adminClient.authenticationManagement.getRequiredActions(),
(actions) => {
setRequiredActions(actions);
},
[]
);
return (
<FormGroup
@ -55,13 +68,13 @@ export const CredentialsResetActionMultiSelect = () => {
}}
typeAheadAriaLabel={t("resetActions")}
>
{Object.values(RequiredActionAlias).map((action, index) => (
{requiredActions.map(({ alias, name }) => (
<SelectOption
key={index}
value={action}
data-testid={`${action}-option`}
key={alias}
value={alias}
data-testid={`${alias}-option`}
>
{t(action)}
{name}
</SelectOption>
))}
</Select>