Fixed creating user (#23484)

Closes #23327
This commit is contained in:
agagancarczyk 2023-09-22 20:46:21 +01:00 committed by GitHub
parent 0bae359058
commit d8ff73e34f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View file

@ -19,6 +19,8 @@ import { UserFormFields, toUserRepresentation } from "./form-state";
import { toUser } from "./routes/User";
import "./user-section.css";
import RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
import { useFetch } from "../utils/useFetch";
export default function CreateUser() {
const { t } = useTranslation();
@ -28,6 +30,15 @@ export default function CreateUser() {
const userForm = useForm<UserFormFields>({ mode: "onChange" });
const [addedGroups, setAddedGroups] = useState<GroupRepresentation[]>([]);
const [realmRepresentation, setRealmRepresentation] =
useState<RealmRepresentation>();
useFetch(
() => adminClient.realms.findOne({ realm }),
(result) => setRealmRepresentation(result),
[],
);
const save = async (data: UserFormFields) => {
try {
const createdUser = await adminClient.users.create({
@ -57,7 +68,11 @@ export default function CreateUser() {
<UserProfileProvider>
<FormProvider {...userForm}>
<PageSection variant="light">
<UserForm onGroupsUpdate={setAddedGroups} save={save} />
<UserForm
realm={realmRepresentation}
onGroupsUpdate={setAddedGroups}
save={save}
/>
</PageSection>
</FormProvider>
</UserProfileProvider>

View file

@ -182,7 +182,6 @@ export const UserForm = ({
filterGroups={selectedGroups}
/>
)}
{isUserProfileEnabled && <EmailVerified />}
{user?.id && (
<>
<FormGroup label={t("id")} fieldId="kc-id" isRequired>
@ -224,8 +223,8 @@ export const UserForm = ({
<FederatedUserLink user={user} />
</FormGroup>
)}
{isUserProfileEnabled ? (
<UserProfileFields config={user?.userProfileMetadata!} />
{isUserProfileEnabled && user?.userProfileMetadata ? (
<UserProfileFields config={user.userProfileMetadata} />
) : (
<>
{!realm?.registrationEmailAsUsername && (