keycloak-scim/js/apps/admin-ui/src/user/UserAttributes.tsx
mposolda 692aeee17d Enable user profile by default
closes #25151

Signed-off-by: mposolda <mposolda@gmail.com>
2024-01-11 12:48:44 -03:00

48 lines
1.3 KiB
TypeScript

import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation";
import { PageSection, PageSectionVariants } from "@patternfly/react-core";
import { UseFormReturn, useFormContext } from "react-hook-form";
import {
AttributeForm,
AttributesForm,
} from "../components/key-value-form/AttributeForm";
import { UserFormFields, toUserFormFields } from "./form-state";
import {
UnmanagedAttributePolicy,
UserProfileConfig,
} from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata";
type UserAttributesProps = {
user: UserRepresentation;
save: (user: UserFormFields) => void;
upConfig?: UserProfileConfig;
};
export const UserAttributes = ({
user,
save,
upConfig,
}: UserAttributesProps) => {
const form = useFormContext<UserFormFields>();
return (
<PageSection variant={PageSectionVariants.light}>
<AttributesForm
form={form as UseFormReturn<AttributeForm>}
save={save}
fineGrainedAccess={user.access?.manage}
reset={() =>
form.reset({
...form.getValues(),
attributes: toUserFormFields(user).attributes,
})
}
name="unmanagedAttributes"
isDisabled={
UnmanagedAttributePolicy.AdminView ==
upConfig?.unmanagedAttributePolicy
}
/>
</PageSection>
);
};