import {
Avatar,
AvatarProps,
Brand,
BrandProps,
DropdownItem,
PageHeader,
PageHeaderProps,
PageHeaderTools,
PageHeaderToolsGroup,
PageHeaderToolsItem,
} from "@patternfly/react-core";
import { ReactNode } from "react";
import { KeycloakDropdown } from "./KeycloakDropdown";
import { useTranslation } from "./translation/useTranslation";
import { loggedInUserName } from "./util";
import { DefaultAvatar } from "./DefaultAvatar";
import { useKeycloak } from "./KeycloakContext";
type BrandLogo = BrandProps & {
href: string;
};
type KeycloakMastheadProps = PageHeaderProps & {
brand: BrandLogo;
avatar?: AvatarProps;
features?: {
hasLogout?: boolean;
hasManageAccount?: boolean;
hasUsername?: boolean;
};
kebabDropdownItems?: ReactNode[];
dropdownItems?: ReactNode[];
toolbarItems?: ReactNode[];
};
const KeycloakMasthead = ({
brand: { href: brandHref, ...brandProps },
avatar,
features: {
hasLogout = true,
hasManageAccount = true,
hasUsername = true,
} = {},
kebabDropdownItems,
dropdownItems = [],
toolbarItems,
...rest
}: KeycloakMastheadProps) => {
const { t } = useTranslation();
const { keycloak } = useKeycloak()!;
const extraItems = [];
if (hasManageAccount) {
extraItems.push(
keycloak?.accountManagement()}
>
{t("manageAccount")}
,
);
}
if (hasLogout) {
extraItems.push(
keycloak?.logout()}>
{t("signOut")}
,
);
}
const picture = keycloak?.tokenParsed?.picture;
return (
}
logoProps={{ href: brandHref }}
headerTools={
{toolbarItems}
{picture || avatar?.src ? (
) : (
)}
}
/>
);
};
export default KeycloakMasthead;