diff --git a/apps/admin-ui/src/components/alert/AlertPanel.tsx b/apps/admin-ui/src/components/alert/AlertPanel.tsx index e9895cd020..5d61bf8e2e 100644 --- a/apps/admin-ui/src/components/alert/AlertPanel.tsx +++ b/apps/admin-ui/src/components/alert/AlertPanel.tsx @@ -13,7 +13,11 @@ type AlertPanelProps = { export function AlertPanel({ alerts, onCloseAlert }: AlertPanelProps) { return ( - + {alerts.map(({ id, variant, message, description }) => ( { addAlert(t("userSaved"), AlertVariant.success); refresh(); } catch (error) { - addError("users:userCreateError", error); + if (isUserProfileError(error)) { + addError(userProfileErrorToString(error), error); + } else { + addError("users:userCreateError", error); + } } }; diff --git a/apps/admin-ui/src/user/UserProfileFields.tsx b/apps/admin-ui/src/user/UserProfileFields.tsx index 0bcab26d76..d4438125a9 100644 --- a/apps/admin-ui/src/user/UserProfileFields.tsx +++ b/apps/admin-ui/src/user/UserProfileFields.tsx @@ -1,6 +1,3 @@ -import { Fragment } from "react"; -import { useTranslation } from "react-i18next"; -import { Controller, useFormContext } from "react-hook-form"; import { Form, FormGroup, @@ -8,13 +5,16 @@ import { SelectOption, Text, } from "@patternfly/react-core"; +import { Fragment } from "react"; +import { Controller, useFormContext } from "react-hook-form"; +import { useTranslation } from "react-i18next"; import type { UserProfileAttribute, UserProfileAttributeRequired, } from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig"; -import { ScrollForm } from "../components/scroll-form/ScrollForm"; import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput"; +import { ScrollForm } from "../components/scroll-form/ScrollForm"; import { useUserProfile } from "../realm-settings/user-profile/UserProfileContext"; import useToggle from "../utils/useToggle"; @@ -25,6 +25,20 @@ type UserProfileFieldsProps = { roles?: string[]; }; +export type UserProfileError = { + responseData: { errors?: { errorMessage: string }[] }; +}; + +export function isUserProfileError(error: unknown): error is UserProfileError { + return !!(error as UserProfileError).responseData.errors; +} + +export function userProfileErrorToString(error: UserProfileError) { + return ( + error.responseData["errors"]?.map((e) => e["errorMessage"]).join("\n") || "" + ); +} + export const UserProfileFields = ({ roles = ["admin"], }: UserProfileFieldsProps) => {