keycloak-scim/js/apps/admin-ui/src/user/FederatedUserLink.tsx

57 lines
1.6 KiB
TypeScript
Raw Normal View History

import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation";
import type UserRepresentation from "@keycloak/keycloak-admin-client/lib/defs/userRepresentation";
2022-12-06 10:05:41 +00:00
import { Button } from "@patternfly/react-core";
import { useState } from "react";
2023-01-18 12:09:49 +00:00
import { Link } from "react-router-dom";
2022-12-06 10:05:41 +00:00
import { adminClient } from "../admin-client";
2022-12-06 10:05:41 +00:00
import { useAccess } from "../context/access/Access";
import { useRealm } from "../context/realm-context/RealmContext";
import { toCustomUserFederation } from "../user-federation/routes/CustomUserFederation";
import { useFetch } from "../utils/useFetch";
2022-12-06 10:05:41 +00:00
type FederatedUserLinkProps = {
user: UserRepresentation;
};
export const FederatedUserLink = ({ user }: FederatedUserLinkProps) => {
const access = useAccess();
const { realm } = useRealm();
const [component, setComponent] = useState<ComponentRepresentation>();
useFetch(
() =>
access.hasAccess("view-realm")
? adminClient.components.findOne({
id: (user.federationLink || user.origin)!,
})
: adminClient.userStorageProvider.name({
id: (user.federationLink || user.origin)!,
}),
setComponent,
[],
2022-12-06 10:05:41 +00:00
);
if (!component) return null;
return (
<Button
variant="link"
isDisabled={!access.hasAccess("view-realm")}
component={(props) => (
<Link
{...props}
to={toCustomUserFederation({
2022-12-06 10:05:41 +00:00
id: component.id!,
providerId: component.providerId!,
2022-12-06 10:05:41 +00:00
realm,
})}
/>
)}
>
{component.name}
</Button>
);
};