diff --git a/js/apps/admin-ui/src/user/EditUser.tsx b/js/apps/admin-ui/src/user/EditUser.tsx index 53723172a3..eccec6d3c8 100644 --- a/js/apps/admin-ui/src/user/EditUser.tsx +++ b/js/apps/admin-ui/src/user/EditUser.tsx @@ -337,7 +337,7 @@ export default function EditUser() { title={{t("credentials")}} {...credentialsTab} > - + void; }; type ExpandableCredentialRepresentation = { @@ -52,7 +53,7 @@ type ExpandableCredentialRepresentation = { isExpanded: boolean; }; -export const UserCredentials = ({ user }: UserCredentialsProps) => { +export const UserCredentials = ({ user, setUser }: UserCredentialsProps) => { const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const [key, setKey] = useState(0); @@ -286,6 +287,13 @@ export const UserCredentials = ({ user }: UserCredentialsProps) => { } }; + const onAddRequiredActions = (requiredActions: string[]) => { + setUser({ + ...user, + requiredActions: [...(user.requiredActions ?? []), ...requiredActions], + }); + }; + const onDragEnd = ({ target }: ReactDragEvent) => { if (!(target instanceof HTMLTableRowElement)) { return; @@ -357,6 +365,7 @@ export const UserCredentials = ({ user }: UserCredentialsProps) => { setIsOpen(false)} /> diff --git a/js/apps/admin-ui/src/user/UserForm.tsx b/js/apps/admin-ui/src/user/UserForm.tsx index cc40f4585c..8e570e922d 100644 --- a/js/apps/admin-ui/src/user/UserForm.tsx +++ b/js/apps/admin-ui/src/user/UserForm.tsx @@ -13,7 +13,7 @@ import { Switch, } from "@patternfly/react-core"; import { TFunction } from "i18next"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { Controller, UseFormReturn } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { Link } from "react-router-dom"; @@ -82,7 +82,9 @@ export const UserForm = ({ const [open, setOpen] = useState(false); const [locked, setLocked] = useState(isLocked); - setValue("requiredActions", user?.requiredActions || []); + useEffect(() => { + setValue("requiredActions", user?.requiredActions || []); + }, [user, setValue]); const unLockUser = async () => { try { diff --git a/js/apps/admin-ui/src/user/user-credentials/ResetPasswordDialog.tsx b/js/apps/admin-ui/src/user/user-credentials/ResetPasswordDialog.tsx index 45d6d3665e..1326cc2055 100644 --- a/js/apps/admin-ui/src/user/user-credentials/ResetPasswordDialog.tsx +++ b/js/apps/admin-ui/src/user/user-credentials/ResetPasswordDialog.tsx @@ -1,4 +1,5 @@ import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation"; +import { RequiredActionAlias } from "@keycloak/keycloak-admin-client/lib/defs/requiredActionProviderRepresentation"; import { AlertVariant, ButtonVariant, @@ -23,6 +24,7 @@ import useToggle from "../../utils/useToggle"; type ResetPasswordDialogProps = { user: UserRepresentation; isResetPassword: boolean; + onAddRequiredActions?: (requiredActions: string[]) => void; refresh: () => void; onClose: () => void; }; @@ -42,6 +44,7 @@ const credFormDefaultValues: CredentialsForm = { export const ResetPasswordDialog = ({ user, isResetPassword, + onAddRequiredActions, refresh, onClose, }: ResetPasswordDialogProps) => { @@ -88,7 +91,9 @@ export const ResetPasswordDialog = ({ value: password, }, }); - user.requiredActions = ["UPDATE_PASSWORD"]; + if (temporaryPassword) { + onAddRequiredActions?.([RequiredActionAlias.UPDATE_PASSWORD]); + } const credentials = await adminClient.users.getCredentials({ id: user.id!, });