Skip to main content
⌘K

Search

Search pages, pieces and blocks.

Dashboard header/An overview in the App Shell (Strip): six metric tabs, the chosen one over time as a heatmap, and the recent bookings.

components/blocks/dashboard-header.tsx
"use client"
import * as React from "react"
import { AsteriskIcon } from "@/components/icons"import { AppShell, type AppShellNavItem } from "@/components/ui/app-shell"import { Badge } from "@/components/ui/badge"import { Breadcrumb, BreadcrumbLink, BreadcrumbList, BreadcrumbSection, BreadcrumbSwitcher } from "@/components/ui/breadcrumb"import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"import { ChartHeatmap } from "@/components/ui/chart"import { DataTable, createDataTableColumns } from "@/components/ui/data-table"import { DropdownMenuRadioGroup, DropdownMenuRadioItem } from "@/components/ui/dropdown-menu"import { Link } from "@/components/ui/link"import { PageHeader, PageHeaderActions } from "@/components/ui/page-header"import { SearchInput } from "@/components/ui/search-input"import { SegmentedControl, SegmentedControlItem } from "@/components/ui/segmented-control"import { StatCard, StatCardTabs } from "@/components/ui/stat-card"
// Dashboard header: the Maré overview in the App Shell (Strip). The top row// (where the page sits, "Bookings / Overview", the second part a switcher// of Overview, Schools and Instructors, the same layout under each with its// own line; Search; New booking), then three parts 32 apart:// six metric tabs for the last 12 months, one radio group; the chosen// metric over time as a heatmap, by week across the year or by hour across// the week; and the eight most recent bookings in the framed Data Table.
type Metric = "bookings" | "revenue" | "cancellations" | "group" | "students" | "rating"type View = "year" | "hour"type Page = "overview" | "schools" | "instructors"
// The views in the top row's switcher: one layout, each with its own line.const pages: { value: Page; label: string; line: string }[] = [  { value: "overview", label: "Overview", line: "Last 12 months, every school" },  { value: "schools", label: "Schools", line: "Last 12 months, the seven schools" },  { value: "instructors", label: "Instructors", line: "Last 12 months, every instructor" },]
const weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]const weekdayNames = ["Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fridays", "Saturdays", "Sundays"]const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]const hours = Array.from({ length: 12 }, (_, index) => `${String(8 + index).padStart(2, "0")}:00`)
// The year runs to the last full week before Mon 30 Nov 2026: 52 weeks,// Monday to Sunday, the first from Mon 1 Dec 2025.const firstMonday = Date.UTC(2025, 11, 1)const day = 24 * 60 * 60 * 1000const dateOf = (row: number, column: number) => new Date(firstMonday + (column * 7 + row) * day)const dateName = (date: Date) => `${weekdays[(date.getUTCDay() + 6) % 7]} ${date.getUTCDate()} ${months[date.getUTCMonth()]}`
// A month's name over the first week that starts in it.const weekLabels = Array.from({ length: 52 }, (_, column) => {  const month = dateOf(0, column).getUTCMonth()  return column === 0 || dateOf(0, column - 1).getUTCMonth() !== month ? months[month] : undefined})
// Swell and holidays: busier from June to September and at weekends.function bookingsYear() {  let seed = 27  const random = () => {    seed = (seed * 16807) % 2147483647    return seed / 2147483647  }  const raw = weekdays.map((_, row) =>    weekLabels.map((_, column) => {      const month = dateOf(row, column).getUTCMonth()      const season = [0.35, 0.3, 0.45, 0.6, 0.8, 1.1, 1.5, 1.6, 1.2, 0.8, 0.5, 0.4][month]      const weekend = row >= 5 ? 1.7 : 1      const value = season * weekend * (0.4 + random() * 1.2)      return random() < 0.08 ? 0 : value    })  )  // Scaled so the year comes to 4,120 bookings exactly.  const sum = raw.flat().reduce((a, b) => a + b, 0)  const counts = raw.map((row) => row.map((value) => Math.round((value / sum) * 4120)))  const off = 4120 - counts.flat().reduce((a, b) => a + b, 0)  counts[5][30] += off  return counts}
const yearBookings = bookingsYear()
// The same year by weekday and hour: mornings and late afternoons, the tides.const hourBookings = weekdays.map((_, row) =>  hours.map((_, column) => {    const total = yearBookings[row].reduce((a, b) => a + b, 0)    const shape = [0.6, 1.4, 1.5, 1.1, 0.5, 0.3, 0.4, 0.7, 1.0, 1.2, 0.9, 0.4][column]    return Math.round((total * shape) / 10)  }))
const metrics: {  value: Metric  label: string  figure: string  change: { value: string; direction: "up" | "down"; good?: "up" | "down" }  title: string  // A square's value, from its bookings.  from: (bookings: number, row: number, column: number) => number  say: (value: number) => string  total: string}[] = [  {    value: "bookings",    label: "Bookings",    figure: "4,120",    change: { value: "12%", direction: "up" },    title: "Bookings over time",    from: (bookings) => bookings,    say: (value) => `${value} ${value === 1 ? "booking" : "bookings"}`,    total: "4,120 bookings in the last year",  },  {    value: "revenue",    label: "Revenue",    figure: "€218,460",    change: { value: "9%", direction: "up" },    title: "Revenue over time",    from: (bookings) => bookings * 53,    say: (value) => `€${value.toLocaleString("en-GB")}`,    total: "€218,460 in the last year",  },  {    value: "cancellations",    label: "Cancellations",    figure: "186",    change: { value: "3%", direction: "up", good: "down" },    title: "Cancellations over time",    from: (bookings, row, column) => Math.round(bookings * 0.045 + ((row + column) % 5 === 0 ? 1 : 0)),    say: (value) => `${value} ${value === 1 ? "cancellation" : "cancellations"}`,    total: "186 cancellations in the last year",  },  {    value: "group",    label: "Average group",    figure: "4.6",    change: { value: "4%", direction: "up" },    title: "Average group over time",    from: (bookings, row, column) => (bookings ? Math.round((3.6 + ((row * 7 + column * 3) % 10) / 5) * 10) / 10 : 0),    say: (value) => `${value.toFixed(1)} students a lesson`,    total: "4.6 students a lesson on average",  },  {    value: "students",    label: "Students",    figure: "1,384",    change: { value: "15%", direction: "up" },    title: "Students over time",    from: (bookings) => Math.round(bookings * 0.8),    say: (value) => `${value} ${value === 1 ? "student" : "students"}`,    total: "1,384 students in the last year",  },  {    value: "rating",    label: "Rating",    figure: "4.8",    change: { value: "1%", direction: "down" },    title: "Rating over time",    from: (bookings, row, column) => (bookings ? Math.round((4.2 + ((row * 5 + column) % 9) / 10) * 10) / 10 : 0),    say: (value) => `${value.toFixed(1)} average rating`,    total: "4.8 average from 2,960 reviews",  },]
type Status = "Confirmed" | "Pending" | "Cancelled"
type Booking = { id: string; student: string; school: string; status: Status; level: string; date: string; price: number }
const recent: Booking[] = [  { id: "MR-2058", student: "Beatriz Carvalho", school: "Sagres", status: "Cancelled", level: "Private", date: "Sun 29 Nov, 13:00", price: 90 },  { id: "MR-2057", student: "Diogo Ribeiro", school: "Peniche", status: "Confirmed", level: "Beginner", date: "Sun 29 Nov, 09:00", price: 45 },  { id: "MR-2056", student: "Inês Lopes", school: "Ericeira", status: "Confirmed", level: "Improver", date: "Sat 28 Nov, 10:30", price: 55 },  { id: "MR-2055", student: "Rita Fonseca", school: "Carcavelos", status: "Pending", level: "Private", date: "Sat 28 Nov, 08:00", price: 90 },  { id: "MR-2054", student: "Tomás Amaro", school: "Ericeira", status: "Confirmed", level: "Beginner", date: "Fri 27 Nov, 12:30", price: 45 },  { id: "MR-2053", student: "Catarina Correia", school: "Nazaré", status: "Pending", level: "Beginner", date: "Fri 27 Nov, 10:00", price: 45 },  { id: "MR-2052", student: "Afonso Moreira", school: "Sagres", status: "Confirmed", level: "Improver", date: "Thu 26 Nov, 11:00", price: 55 },  { id: "MR-2051", student: "Mariana Cardoso", school: "Costa da Caparica", status: "Confirmed", level: "Improver", date: "Thu 26 Nov, 09:00", price: 55 },]
const tones: Record<Status, "success" | "warning" | "destructive"> = {  Confirmed: "success",  Pending: "warning",  Cancelled: "destructive",}
const euros = new Intl.NumberFormat("en-GB", { style: "currency", currency: "EUR" })
const helper = createDataTableColumns<Booking>()
const columns = helper.columns([  helper.accessor("student", { header: "Student", meta: { kind: "person", emphasis: "strong" } }),  helper.accessor("status", {    header: "Status",    meta: { kind: "status" },    cell: ({ getValue }) => (      <Badge look="status" tone={tones[getValue()]}>        {getValue()}      </Badge>    ),  }),  helper.accessor("school", { header: "School", meta: { kind: "text", emphasis: "muted" } }),  helper.accessor("level", {    header: "Level",    meta: { kind: "text" },    cell: ({ getValue }) => <Badge variant="secondary">{getValue()}</Badge>,  }),  helper.accessor("date", { header: "Date", meta: { kind: "date", numeric: true } }),  helper.accessor("price", {    header: "Price",    meta: { kind: "number", align: "end", numeric: true },    cell: ({ getValue }) => euros.format(getValue()),  }),])
const stripNav = ["Overview", "Bookings", "Calendar", "Schools", "Instructors", "Students", "Lessons", "Payouts", "Reviews", "Messages", "Reports"]
function DashboardHeaderBlock() {  const [metric, setMetric] = React.useState<Metric>("bookings")  const [view, setView] = React.useState<View>("year")  const [page, setPage] = React.useState<Page>("overview")  const currentPage = pages.find((each) => each.value === page) ?? pages[0]  const current = metrics.find((each) => each.value === metric) ?? metrics[0]  const nav: AppShellNavItem[] = stripNav.map((label) => ({    label,    count: label === "Bookings" ? "104" : undefined,    active: label === "Overview",  }))  const source = view === "year" ? yearBookings : hourBookings  const values = React.useMemo(    () => source.map((row, rowIndex) => row.map((bookings, column) => current.from(bookings, rowIndex, column))),    [source, current]  )  const when = (row: number, column: number) =>    view === "year" ? `on ${dateName(dateOf(row, column))}` : `on ${weekdayNames[row]} at ${hours[column]}`
  return (    <AppShell      id="mare-overview"      contentAlign="top"      brand={{ name: "Maré", logo: <AsteriskIcon /> }}      nav={nav}      settings={{ label: "Settings" }}      header={        <PageHeader look="toprow">          <Breadcrumb>            <BreadcrumbList>              <BreadcrumbSection>                <BreadcrumbLink href="#">Bookings</BreadcrumbLink>              </BreadcrumbSection>              <BreadcrumbSwitcher label={currentPage.label} aria-label={`Bookings view: ${currentPage.label}`}>                <DropdownMenuRadioGroup                  value={page}                  onValueChange={(value) => {                    const next = pages.find((each) => each.value === value)                    if (next) setPage(next.value)                  }}                >                  {pages.map((each) => (                    <DropdownMenuRadioItem key={each.value} value={each.value} closeOnClick>                      {each.label}                    </DropdownMenuRadioItem>                  ))}                </DropdownMenuRadioGroup>              </BreadcrumbSwitcher>            </BreadcrumbList>          </Breadcrumb>          <SearchInput aria-label="Search bookings" placeholder="Search" />          <PageHeaderActions primary={{ label: "New booking" }} />        </PageHeader>      }    >      <div className="flex min-w-0 flex-col gap-8">        <StatCardTabs          aria-label="Metric, last 12 months"          value={metric}          onValueChange={(value) => {            const next = metrics.find((each) => each.value === value)            if (next) setMetric(next.value)          }}        >          {metrics.map((each) => (            <StatCard key={each.value} look="tab" tabValue={each.value} label={each.label} value={each.figure} change={each.change} />          ))}        </StatCardTabs>
        <Card look="section">          <CardHeader>            <CardTitle>{current.title}</CardTitle>            <CardDescription>{currentPage.line}</CardDescription>            <CardAction>              <SegmentedControl                aria-label="View"                value={view}                onValueChange={(value) => {                  if (value === "year" || value === "hour") setView(value)                }}              >                <SegmentedControlItem value="year">Year</SegmentedControlItem>                <SegmentedControlItem value="hour">By hour</SegmentedControlItem>              </SegmentedControl>            </CardAction>          </CardHeader>          <CardContent>            <ChartHeatmap              values={values}              columnLabels={view === "year" ? weekLabels : hours}              rowLabels={["Mon", undefined, "Wed", undefined, "Fri", undefined, undefined]}              squareColumns={52}              phoneColumns={view === "year" ? 13 : undefined}              describe={(row, column, value) => `${current.say(value)} ${when(row, column)}`}              summary={`${current.title}, ${view === "year" ? "by week across the last 12 months" : "by weekday and hour"}: ${current.total}. Busiest from June to September and at weekends.`}              total={current.total}            />          </CardContent>        </Card>
        <Card look="section">          <CardHeader>            <CardTitle>Recent bookings</CardTitle>            <CardAction>              <Link href="#">View all</Link>            </CardAction>          </CardHeader>          <CardContent>            <DataTable              id="mare-recent-table"              columns={columns}              data={recent}              getRowId={(booking) => booking.id}              toolbar="none"              pagination={false}              phoneRow={(booking) => ({                title: booking.student,                description: booking.date,                end: (                  <Badge look="status" tone={tones[booking.status]}>                    {booking.status}                  </Badge>                ),              })}            />          </CardContent>        </Card>      </div>    </AppShell>  )}
export { DashboardHeaderBlock }