2023-05-03 13:51:02 +00:00
|
|
|
import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation";
|
2023-08-09 11:26:04 +00:00
|
|
|
import { PageSection, PageSectionVariants } from "@patternfly/react-core";
|
2023-09-04 04:55:34 +00:00
|
|
|
import { useFormContext } from "react-hook-form";
|
2021-10-25 14:38:54 +00:00
|
|
|
|
2023-09-04 04:55:34 +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;
|
2023-09-04 04:55:34 +00:00
|
|
|
save: (user: UserFormFields) => void;
|
2021-10-25 14:38:54 +00:00
|
|
|
};
|
|
|
|
|
2023-08-09 11:26:04 +00:00
|
|
|
export const UserAttributes = ({ user, save }: UserAttributesProps) => {
|
2023-09-04 04:55:34 +00:00
|
|
|
const form = useFormContext<UserFormFields>();
|
2021-10-25 14:38:54 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<PageSection variant={PageSectionVariants.light}>
|
|
|
|
<AttributesForm
|
|
|
|
form={form}
|
|
|
|
save={save}
|
2022-04-21 15:03:48 +00:00
|
|
|
fineGrainedAccess={user.access?.manage}
|
2021-10-25 14:38:54 +00:00
|
|
|
reset={() =>
|
|
|
|
form.reset({
|
2023-09-04 04:55:34 +00:00
|
|
|
...form.getValues(),
|
|
|
|
attributes: toUserFormFields(user).attributes,
|
2021-10-25 14:38:54 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</PageSection>
|
|
|
|
);
|
|
|
|
};
|