keycloak-scim/src/realm-roles/UsersInRoleTab.tsx

70 lines
2 KiB
TypeScript
Raw Normal View History

2021-03-01 15:55:54 +00:00
import React, { useEffect } from "react";
2021-02-24 20:05:19 +00:00
import { useParams } from "react-router-dom";
2021-02-24 13:47:27 +00:00
import { useTranslation } from "react-i18next";
2021-02-24 20:05:19 +00:00
import { PageSection } from "@patternfly/react-core";
2021-02-24 13:47:27 +00:00
import { ListEmptyState } from "../components/list-empty-state/ListEmptyState";
import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable";
import { boolFormatter, emptyFormatter } from "../util";
import { useAdminClient } from "../context/auth/AdminClient";
2021-02-24 20:05:19 +00:00
export const UsersInRoleTab = () => {
2021-02-24 13:47:27 +00:00
const { t } = useTranslation("roles");
2021-02-24 20:05:19 +00:00
const { id } = useParams<{ id: string }>();
2021-02-24 13:47:27 +00:00
const adminClient = useAdminClient();
const loader = async () => {
2021-02-24 20:05:19 +00:00
const role = await adminClient.roles.findOneById({ id: id });
const usersWithRole = await adminClient.roles.findUsersWithRole({
name: role.name!,
});
return usersWithRole;
2021-02-24 13:47:27 +00:00
};
2021-02-24 20:05:19 +00:00
useEffect(() => {
loader();
}, []);
2021-02-24 13:47:27 +00:00
return (
<>
2021-03-01 15:22:25 +00:00
<PageSection data-testid="users-page" variant="light">
2021-03-01 15:30:16 +00:00
<KeycloakDataTable
loader={loader}
ariaLabelKey="roles:roleList"
searchPlaceholderKey=""
emptyState={
<ListEmptyState
hasIcon={true}
message={t("noDirectUsers")}
instructions={t("noUsersEmptyStateDescription")}
/>
}
columns={[
{
name: "username",
displayKey: "roles:userName",
cellFormatters: [emptyFormatter()],
},
{
name: "email",
displayKey: "roles:email",
cellFormatters: [emptyFormatter()],
},
{
name: "lastName",
displayKey: "roles:lastName",
cellFormatters: [emptyFormatter()],
},
{
name: "firstName",
displayKey: "roles:firstName",
cellFormatters: [boolFormatter(), emptyFormatter()],
},
]}
/>
2021-02-24 13:47:27 +00:00
</PageSection>
</>
);
};