Skip to content

Open-source status page, incident response and uptime monitoring

3.4 KB
Raw Blame
"use client";

import { ArrowUpRight, Success, Pending, Close } from "@openstatus/icons";
import {
  SidebarGroup,
  SidebarGroupLabel,
  SidebarMenu,
  SidebarMenuAction,
  SidebarMenuItem,
} from "@openstatus/ui/components/ui/sidebar";
import { useQuery } from "@tanstack/react-query";

import { Link } from "@/components/common/link";
import { useTRPC } from "@/lib/trpc/client";

export function NavBannerChecklist({
  handleClose,
}: {
  handleClose: () => void;
}) {
  const trpc = useTRPC();
  const { data: usage } = useQuery(trpc.workspace.usage.queryOptions());
  const { data: pages } = useQuery(trpc.page.list.queryOptions());

  // Hide until the counts land — every item would read as unchecked and the
  // banner would flash "0/5" before correcting itself.
  if (!usage) return null;

  const onlyPage = pages?.length === 1 ? pages[0] : undefined;

  const hasMonitors = usage.monitors > 0;
  const hasStatusPages = usage.pages > 0;
  const hasPageComponents = usage.pageComponents > 0;
  const hasNotifications = usage.notifications > 0;
  const hasStatusReports = usage.statusReports > 0;

  const items = [
    {
      title: "Create Monitor",
      checked: hasMonitors,
      href: "/monitors/create",
    },
    {
      title: "Create Status Page",
      checked: hasStatusPages,
      href: "/status-pages/create",
    },
    {
      title: "Add Page Components",
      checked: hasPageComponents,
      href: onlyPage
        ? `/status-pages/${onlyPage.id}/components`
        : "/status-pages",
    },
    {
      title: "Create Status Report",
      checked: hasStatusReports,
      href: onlyPage
        ? `/status-pages/${onlyPage.id}/status-reports`
        : "/status-pages",
    },
    {
      title: "Create Notification",
      checked: hasNotifications,
      href: "/notifications",
    },
  ];

  if (items.every((i) => i.checked)) return null;

  return (
    <SidebarGroup className="bg-background rounded-lg border px-2 py-1.5 group-data-[collapsible=icon]:hidden">
      <SidebarGroupLabel className="flex h-7 items-center justify-between pr-0 pl-0">
        <span>
          Getting Started ({items.filter((i) => i.checked).length}/
          {items.length})
        </span>
        <SidebarMenuAction
          className="relative top-0 right-0"
          onClick={handleClose}
        >
          <Close className="text-muted-foreground" size={16} />
        </SidebarMenuAction>
      </SidebarGroupLabel>
      <SidebarMenu>
        {items.map((item) => (
          <SidebarMenuItem
            key={item.title}
            className="flex items-center gap-2 text-sm"
          >
            {item.checked ? (
              <>
                <Success className="text-success size-3 shrink-0" />
                <span>{item.title}</span>
              </>
            ) : (
              <>
                <Pending className="text-muted-foreground/50 size-3 shrink-0" />
                <Link href={item.href}>{item.title}</Link>
              </>
            )}
          </SidebarMenuItem>
        ))}
        <SidebarMenuItem className="flex items-center gap-2 text-sm">
          <ArrowUpRight className="text-muted-foreground/50 size-3 shrink-0" />
          <a
            href="https://www.openstatus.dev/docs"
            target="_blank"
            rel="noopener noreferrer"
          >
            Read the Docs
          </a>
        </SidebarMenuItem>
      </SidebarMenu>
    </SidebarGroup>
  );
}