parent
8a3c30b918
commit
1955a468c9
1 changed files with 30 additions and 21 deletions
|
@ -13,17 +13,18 @@ import type UserRepresentation from "keycloak-admin/lib/defs/userRepresentation"
|
||||||
import { UserForm } from "./UserForm";
|
import { UserForm } from "./UserForm";
|
||||||
import { useAlerts } from "../components/alert/Alerts";
|
import { useAlerts } from "../components/alert/Alerts";
|
||||||
import { useAdminClient } from "../context/auth/AdminClient";
|
import { useAdminClient } from "../context/auth/AdminClient";
|
||||||
import { useHistory, useParams, useRouteMatch } from "react-router-dom";
|
import { useHistory, useParams } from "react-router-dom";
|
||||||
import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs";
|
import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs";
|
||||||
import { UserGroups } from "./UserGroups";
|
import { UserGroups } from "./UserGroups";
|
||||||
import { UserConsents } from "./UserConsents";
|
import { UserConsents } from "./UserConsents";
|
||||||
import type GroupRepresentation from "keycloak-admin/lib/defs/groupRepresentation";
|
import type GroupRepresentation from "keycloak-admin/lib/defs/groupRepresentation";
|
||||||
|
import { useRealm } from "../context/realm-context/RealmContext";
|
||||||
|
|
||||||
export const UsersTabs = () => {
|
export const UsersTabs = () => {
|
||||||
const { t } = useTranslation("roles");
|
const { t } = useTranslation("roles");
|
||||||
const { addAlert } = useAlerts();
|
const { addAlert } = useAlerts();
|
||||||
const { url } = useRouteMatch();
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { realm } = useRealm();
|
||||||
|
|
||||||
const adminClient = useAdminClient();
|
const adminClient = useAdminClient();
|
||||||
const userForm = useForm<UserRepresentation>({ mode: "onChange" });
|
const userForm = useForm<UserRepresentation>({ mode: "onChange" });
|
||||||
|
@ -51,17 +52,17 @@ export const UsersTabs = () => {
|
||||||
await adminClient.users.update({ id: user.id! }, user);
|
await adminClient.users.update({ id: user.id! }, user);
|
||||||
addAlert(t("users:userSaved"), AlertVariant.success);
|
addAlert(t("users:userSaved"), AlertVariant.success);
|
||||||
} else {
|
} else {
|
||||||
const getNewUserId = await adminClient.users.create(user);
|
const createdUser = await adminClient.users.create(user);
|
||||||
|
|
||||||
addedGroups.forEach(async (group) => {
|
addedGroups.forEach(async (group) => {
|
||||||
await adminClient.users.addToGroup({
|
await adminClient.users.addToGroup({
|
||||||
id: getNewUserId.id!,
|
id: createdUser.id!,
|
||||||
groupId: group.id!,
|
groupId: group.id!,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
addAlert(t("users:userCreated"), AlertVariant.success);
|
addAlert(t("users:userCreated"), AlertVariant.success);
|
||||||
history.push(url.substr(0, url.lastIndexOf("/")));
|
history.push(`/${realm}/users/${createdUser.id}/settings`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addAlert(
|
addAlert(
|
||||||
|
@ -75,8 +76,8 @@ export const UsersTabs = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ViewHeader titleKey={user! || t("users:createUser")} />
|
<ViewHeader titleKey={user! || t("users:createUser")} divider={!id} />
|
||||||
<PageSection variant="light">
|
<PageSection variant="light" className="pf-u-p-0">
|
||||||
{id && (
|
{id && (
|
||||||
<KeycloakTabs isBox>
|
<KeycloakTabs isBox>
|
||||||
<Tab
|
<Tab
|
||||||
|
@ -84,36 +85,44 @@ export const UsersTabs = () => {
|
||||||
data-testid="user-details-tab"
|
data-testid="user-details-tab"
|
||||||
title={<TabTitleText>{t("details")}</TabTitleText>}
|
title={<TabTitleText>{t("details")}</TabTitleText>}
|
||||||
>
|
>
|
||||||
|
<PageSection variant="light">
|
||||||
<UserForm
|
<UserForm
|
||||||
onGroupsUpdate={updateGroups}
|
onGroupsUpdate={updateGroups}
|
||||||
form={userForm}
|
form={userForm}
|
||||||
save={save}
|
save={save}
|
||||||
editMode={true}
|
editMode={true}
|
||||||
/>
|
/>
|
||||||
|
</PageSection>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab
|
<Tab
|
||||||
eventKey="groups"
|
eventKey="groups"
|
||||||
data-testid="user-groups-tab"
|
data-testid="user-groups-tab"
|
||||||
title={<TabTitleText>{t("groups")}</TabTitleText>}
|
title={<TabTitleText>{t("groups")}</TabTitleText>}
|
||||||
>
|
>
|
||||||
|
<PageSection variant="light">
|
||||||
<UserGroups />
|
<UserGroups />
|
||||||
|
</PageSection>
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab
|
<Tab
|
||||||
eventKey="consents"
|
eventKey="consents"
|
||||||
data-testid="user-consents-tab"
|
data-testid="user-consents-tab"
|
||||||
title={<TabTitleText>{t("users:consents")}</TabTitleText>}
|
title={<TabTitleText>{t("users:consents")}</TabTitleText>}
|
||||||
>
|
>
|
||||||
|
<PageSection variant="light">
|
||||||
<UserConsents />
|
<UserConsents />
|
||||||
|
</PageSection>
|
||||||
</Tab>
|
</Tab>
|
||||||
</KeycloakTabs>
|
</KeycloakTabs>
|
||||||
)}
|
)}
|
||||||
{!id && (
|
{!id && (
|
||||||
|
<PageSection variant="light">
|
||||||
<UserForm
|
<UserForm
|
||||||
onGroupsUpdate={updateGroups}
|
onGroupsUpdate={updateGroups}
|
||||||
form={userForm}
|
form={userForm}
|
||||||
save={save}
|
save={save}
|
||||||
editMode={false}
|
editMode={false}
|
||||||
/>
|
/>
|
||||||
|
</PageSection>
|
||||||
)}
|
)}
|
||||||
</PageSection>
|
</PageSection>
|
||||||
</>
|
</>
|
||||||
|
|
Loading…
Reference in a new issue