Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions js/apps/admin-ui/src/user/UserProfileFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TextAreaComponent } from "./components/TextAreaComponent";
import { TextComponent } from "./components/TextComponent";
import { UserFormFields } from "./form-state";
import { fieldName, isRootAttribute } from "./utils";
import { MultiInputComponent } from "./components/MultiInputComponent";

export type UserProfileError = {
responseData: { errors?: { errorMessage: string }[] };
Expand Down Expand Up @@ -50,6 +51,7 @@ const INPUT_TYPES = [
"html5-date",
"html5-month",
"html5-time",
"multi-input",
] as const;

export type InputType = (typeof INPUT_TYPES)[number];
Expand Down Expand Up @@ -79,6 +81,7 @@ export const FIELDS: {
"html5-date": TextComponent,
"html5-month": TextComponent,
"html5-time": TextComponent,
"multi-input": MultiInputComponent,
} as const;

export type UserProfileFieldsProps = {
Expand Down Expand Up @@ -179,7 +182,7 @@ const FormField = ({ form, attribute, roles }: FormFieldProps) => {
);
};

const DEFAULT_INPUT_TYPE = "multiselect" satisfies InputType;
const DEFAULT_INPUT_TYPE = "text" satisfies InputType;

function determineInputType(
attribute: UserProfileAttributeMetadata,
Expand All @@ -199,7 +202,7 @@ function determineInputType(

// An attribute with multiple values is always multi-valued, even if an input type is provided.
if (Array.isArray(value) && value.length > 1) {
return DEFAULT_INPUT_TYPE;
return "multi-input";
}

return inputType;
Expand Down
24 changes: 24 additions & 0 deletions js/apps/admin-ui/src/user/components/MultiInputComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useTranslation } from "react-i18next";
import { MultiLineInput } from "../../components/multi-line-input/MultiLineInput";
import { UserProfileFieldProps } from "../UserProfileFields";
import { fieldName, label } from "../utils";
import { UserProfileGroup } from "./UserProfileGroup";

export const MultiInputComponent = ({
form,
attribute,
}: UserProfileFieldProps) => {
const { t } = useTranslation();

return (
<UserProfileGroup form={form} attribute={attribute}>
<MultiLineInput
aria-label={label(attribute, t)}
name={fieldName(attribute)!}
addButtonLabel={t("addMultivaluedLabel", {
fieldLabel: label(attribute, t),
})}
/>
</UserProfileGroup>
);
};