import {
Avatar,
AvatarProps,
Brand,
BrandProps,
DropdownItem,
PageHeader,
PageHeaderProps,
PageHeaderTools,
PageHeaderToolsGroup,
PageHeaderToolsItem,
} from "@patternfly/react-core";
import Keycloak from "keycloak-js";
import { ReactNode } from "react";
import { KeycloakDropdown } from "./KeycloakDropdown";
import { useTranslation } from "./translation/useTranslation";
import { loggedInUserName } from "./util";
type BrandLogo = BrandProps & {
onClick?: () => void;
};
type KeycloakMastheadProps = PageHeaderProps & {
brand: BrandLogo;
avatar?: AvatarProps;
features?: {
hasLogout?: boolean;
hasManageAccount?: boolean;
hasUsername?: boolean;
};
keycloak?: Keycloak;
kebabDropdownItems?: ReactNode[];
dropdownItems: ReactNode[];
};
const KeycloakMasthead = ({
brand: { onClick: onBrandLogoClick, ...brandProps },
avatar,
features: {
hasLogout = true,
hasManageAccount = true,
hasUsername = true,
} = {},
keycloak,
kebabDropdownItems,
dropdownItems,
...rest
}: KeycloakMastheadProps) => {
const { t } = useTranslation();
const extraItems = [];
if (hasManageAccount) {
extraItems.push(
keycloak?.accountManagement()}
>
{t("manageAccount")}
);
}
if (hasLogout) {
extraItems.push(
keycloak?.logout()}>
{t("signOut")}
);
}
const picture = keycloak?.tokenParsed?.picture;
return (
}
logoComponent="div"
headerTools={
}
/>
);
};
export default KeycloakMasthead;