added min length > 0 check to required (#20234)

fixes: #20096
This commit is contained in:
Erik Jan de Wit 2023-05-11 18:17:24 +02:00 committed by GitHub
parent 4326a46dd0
commit a2bdfab9c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,4 @@
import type { import type { UserProfileAttribute } from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig";
UserProfileAttribute,
UserProfileAttributeRequired,
} from "@keycloak/keycloak-admin-client/lib/defs/userProfileConfig";
import { import {
Form, Form,
FormGroup, FormGroup,
@ -92,8 +89,9 @@ const FormField = ({ attribute, roles }: FormFieldProps) => {
const isRootAttribute = (attr?: string) => const isRootAttribute = (attr?: string) =>
attr && ROOT_ATTRIBUTES.includes(attr); attr && ROOT_ATTRIBUTES.includes(attr);
const isRequired = (required: UserProfileAttributeRequired | undefined) => const isRequired = (attribute: UserProfileAttribute) =>
Object.keys(required || {}).length !== 0; Object.keys(attribute.required || {}).length !== 0 ||
((attribute.validations?.length?.min as number) || 0) > 0;
const fieldName = (attribute: UserProfileAttribute) => const fieldName = (attribute: UserProfileAttribute) =>
`${isRootAttribute(attribute.name) ? "" : "attributes."}${attribute.name}`; `${isRootAttribute(attribute.name) ? "" : "attributes."}${attribute.name}`;
@ -107,7 +105,7 @@ const FormField = ({ attribute, roles }: FormFieldProps) => {
: attribute.displayName) || attribute.name : attribute.displayName) || attribute.name
} }
fieldId={attribute.name} fieldId={attribute.name}
isRequired={isRequired(attribute.required)} isRequired={isRequired(attribute)}
validated={errors.username ? "error" : "default"} validated={errors.username ? "error" : "default"}
helperTextInvalid={t("common:required")} helperTextInvalid={t("common:required")}
> >