parent
0bae359058
commit
d8ff73e34f
2 changed files with 18 additions and 4 deletions
|
@ -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>
|
||||||
|
|
|
@ -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 && (
|
||||||
|
|
Loading…
Reference in a new issue