6
} from "keycloak-masthead";
7
import { useMemo } from "react";
8
import { useTranslation } from "react-i18next";
9
import { useHref } from "react-router-dom";
10
import { useEnvironment } from "./KeycloakContext";
11
import { joinPath } from "../utils/joinPath";
12
import { ExternalLinkSquareAltIcon } from "@patternfly/react-icons";
13
import { Button } from "@patternfly/react-core";
15
import style from "./header.module.css";
17
const ReferrerLink = () => {
18
const { t } = useTranslation();
19
const searchParams = new URLSearchParams(location.search);
21
return searchParams.has("referrer_uri") ? (
23
data-testid="referrer-link"
25
href={searchParams.get("referrer_uri")!.replace("_hash_", "#")}
27
icon={<ExternalLinkSquareAltIcon />}
31
{t("backTo", { app: searchParams.get("referrer") })}
36
export const Header = () => {
37
const { environment, keycloak } = useEnvironment();
38
const { t } = useTranslation();
40
const brandImage = environment.logo || "logo.svg";
41
const logoUrl = environment.logoUrl ? environment.logoUrl : "/";
42
const internalLogoHref = useHref(logoUrl);
44
// User can indicate that he wants an internal URL by starting it with "/"
45
const indexHref = logoUrl.startsWith("/") ? internalLogoHref : logoUrl;
46
const translations = useMemo<Translations>(
49
fullName: t("fullName"),
50
manageAccount: t("manageAccount"),
51
signOut: t("signOut"),
52
unknownUser: t("unknownUser"),
58
<TranslationsProvider translations={translations}>
59
<KeycloakProvider keycloak={keycloak}>
61
features={{ hasManageAccount: false }}
65
src: joinPath(environment.resourceUrl, brandImage),
67
className: style.brand,
69
toolbarItems={[<ReferrerLink key="link" />]}
72
</TranslationsProvider>