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

32 lines
962 B
TypeScript
Raw Normal View History

import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation";
import { PageSection, PageSectionVariants } from "@patternfly/react-core";
import { useFormContext } from "react-hook-form";
2021-10-25 14:38:54 +00:00
import { AttributesForm } from "../components/key-value-form/AttributeForm";
import { UserFormFields, toUserFormFields } from "./form-state";
2021-10-25 14:38:54 +00:00
type UserAttributesProps = {
user: UserRepresentation;
save: (user: UserFormFields) => void;
2021-10-25 14:38:54 +00:00
};
export const UserAttributes = ({ user, save }: UserAttributesProps) => {
const form = useFormContext<UserFormFields>();
2021-10-25 14:38:54 +00:00
return (
<PageSection variant={PageSectionVariants.light}>
<AttributesForm
form={form}
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
})
}
/>
</PageSection>
);
};