Reset actions should not be hard-coded. (#3499)
This commit is contained in:
parent
d75753aa0c
commit
32f75ca109
1 changed files with 19 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useAdminClient, useFetch } from "../../context/auth/AdminClient";
|
||||||
import { Controller, useFormContext } from "react-hook-form";
|
import { Controller, useFormContext } from "react-hook-form";
|
||||||
import {
|
import {
|
||||||
FormGroup,
|
FormGroup,
|
||||||
|
@ -8,13 +9,25 @@ import {
|
||||||
SelectVariant,
|
SelectVariant,
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
|
|
||||||
import { RequiredActionAlias } from "@keycloak/keycloak-admin-client/lib/defs/requiredActionProviderRepresentation";
|
|
||||||
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
||||||
|
import type RequiredActionProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/requiredActionProviderRepresentation";
|
||||||
|
|
||||||
export const CredentialsResetActionMultiSelect = () => {
|
export const CredentialsResetActionMultiSelect = () => {
|
||||||
const { t } = useTranslation("users");
|
const { t } = useTranslation("users");
|
||||||
|
const { adminClient } = useAdminClient();
|
||||||
const { control } = useFormContext();
|
const { control } = useFormContext();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [requiredActions, setRequiredActions] = useState<
|
||||||
|
RequiredActionProviderRepresentation[]
|
||||||
|
>([]);
|
||||||
|
|
||||||
|
useFetch(
|
||||||
|
() => adminClient.authenticationManagement.getRequiredActions(),
|
||||||
|
(actions) => {
|
||||||
|
setRequiredActions(actions);
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
|
@ -55,13 +68,13 @@ export const CredentialsResetActionMultiSelect = () => {
|
||||||
}}
|
}}
|
||||||
typeAheadAriaLabel={t("resetActions")}
|
typeAheadAriaLabel={t("resetActions")}
|
||||||
>
|
>
|
||||||
{Object.values(RequiredActionAlias).map((action, index) => (
|
{requiredActions.map(({ alias, name }) => (
|
||||||
<SelectOption
|
<SelectOption
|
||||||
key={index}
|
key={alias}
|
||||||
value={action}
|
value={alias}
|
||||||
data-testid={`${action}-option`}
|
data-testid={`${alias}-option`}
|
||||||
>
|
>
|
||||||
{t(action)}
|
{name}
|
||||||
</SelectOption>
|
</SelectOption>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
|
Loading…
Reference in a new issue