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

View file

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