Skip to content

Open-source status page, incident response and uptime monitoring

2.7 KB
Raw Blame
"use client";

import { Clock } from "@openstatus/icons";
import {
  StatusPageFooter,
  StatusPageFooterActions,
  StatusPageFooterContent,
  StatusPagePoweredBy,
} from "@openstatus/ui/components/blocks/status-page-footer";
import { cn } from "@openstatus/ui/lib/utils";
import { useQuery } from "@tanstack/react-query";
import { useParams } from "next/navigation";

import { useEmbed } from "../../hooks/use-embed";
import { useTRPC } from "../../lib/trpc/client";
import { Link } from "../common/link";
import { TimestampHoverCard } from "../content/timestamp-hover-card";
import { LocaleSwitcher } from "../locale-switcher";
import { useStatusPage } from "../status-page/floating-button";
import { ThemeSwitcher } from "../themes/theme-switcher";

export function Footer({
  className,
  ...props
}: React.ComponentProps<"footer">) {
  const { domain } = useParams<{ domain: string }>();
  const trpc = useTRPC();
  const { data: page, dataUpdatedAt } = useQuery({
    ...trpc.statusPage.get.queryOptions({ slug: domain }),
  });
  const embed = useEmbed();
  // the zone the page's days and timestamps render in, not the viewer's
  const { timezone } = useStatusPage();

  if (!page) return null;

  // Whitelabel pages: hide the footer entirely in embed mode.
  // Non-whitelabel pages: keep the "powered by" attribution visible; right-side controls hidden via CSS.
  if (embed.mode && page.whiteLabel) return null;

  return (
    <StatusPageFooter
      className={cn("group-data-[embed=true]/embed:border-t-0", className)}
      {...props}
    >
      <StatusPageFooterContent className="group-data-[embed=true]/embed:justify-center">
        <div>
          {!page.whiteLabel ? (
            <StatusPagePoweredBy>
              <Link
                href={`https://openstatus.dev?utm_medium=status-page&utm_source=${page.slug}`}
                target="_blank"
                rel="noreferrer"
              >
                openstatus.dev
              </Link>
            </StatusPagePoweredBy>
          ) : null}
        </div>
        <StatusPageFooterActions className="group-data-[embed=true]/embed:hidden">
          <TimestampHoverCard
            date={new Date(dataUpdatedAt)}
            side="top"
            align="end"
            className="text-muted-foreground/70 mr-2 flex items-center gap-1.5"
          >
            <Clock className="size-3" />
            <span className="font-mono text-xs">{timezone}</span>
          </TimestampHoverCard>
          <LocaleSwitcher
            pageLocales={page.locales}
            pageDefaultLocale={page.defaultLocale}
          />
          <ThemeSwitcher />
        </StatusPageFooterActions>
      </StatusPageFooterContent>
    </StatusPageFooter>
  );
}