keycloak-scim/js/apps/admin-ui/src/user/UserAttributes.tsx

49 lines
1.3 KiB
TypeScript
Raw Normal View History

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";
2021-10-25 14:38:54 +00:00
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";
2021-10-25 14:38:54 +00:00
type UserAttributesProps = {
user: UserRepresentation;
save: (user: UserFormFields) => void;
upConfig?: UserProfileConfig;
2021-10-25 14:38:54 +00:00
};
export const UserAttributes = ({
user,
save,
upConfig,
}: UserAttributesProps) => {
const form = useFormContext<UserFormFields>();
2021-10-25 14:38:54 +00:00
return (
<PageSection variant={PageSectionVariants.light}>
<AttributesForm
form={form as UseFormReturn<AttributeForm>}
2021-10-25 14:38:54 +00:00
save={save}
fineGrainedAccess={user.access?.manage}
2021-10-25 14:38:54 +00:00
reset={() =>
form.reset({
...form.getValues(),
attributes: toUserFormFields(user).attributes,
2021-10-25 14:38:54 +00:00
})
}
name="unmanagedAttributes"
isDisabled={
UnmanagedAttributePolicy.AdminView ==
upConfig?.unmanagedAttributePolicy
}
2021-10-25 14:38:54 +00:00
/>
</PageSection>
);
};