ProSchedulerSign in

Timeline · Resources

Resource footers and revenue sidebar

renderSidebar adds a right-hand column per row — days booked and revenue — with a total in the footer corner.

Live demo

Stretch an assignment and watch the revenue

Fullscreen
import { useMemo } from "react"
import { ProScheduler, type SchedulerEvent, type SchedulerResource } from "@andreisaac/pro-scheduler"
import { studioAssignments, studioResources } from "./data/studio"
import { useEvents } from "./kit"

const days = (e: SchedulerEvent) =>
  (new Date(e.end!).getTime() - new Date(e.start).getTime()) / 86_400_000

const dayRate: Record<string, number> = { Director: 900, Producer: 700, Editor: 600, Colourist: 650, Sound: 550, Camera: 600, Motion: 600, Designer: 550 }

export function FootersSidebarDemo() {
  const { events, handlers } = useEvents(studioAssignments)

  const booked = useMemo(() => {
    const map = new Map<string, number>()
    for (const e of events) map.set(String(e.resource), (map.get(String(e.resource)) ?? 0) + days(e))
    return map
  }, [events])
  const revenue = (r: SchedulerResource) => Math.round((booked.get(String(r.id)) ?? 0) * (dayRate[String(r.role)] ?? 500))
  const total = studioResources.reduce((sum, r) => sum + revenue(r), 0)

  return (
    <ProScheduler
      data={events}
      resources={studioResources}
      view={{ timeline: { type: "month" } }}
      // A right-hand column with a cell per row, and its heading.
      renderSidebarHeader={() => <span>Booked · revenue</span>}
      renderSidebar={(r) => (
        <div className="grid w-full text-right text-xs leading-tight tabular-nums">
          <span className="font-medium">{Math.round(booked.get(String(r.id)) ?? 0)} days</span>
          <span className="text-muted-foreground">€{revenue(r).toLocaleString()}</span>
        </div>
      )}
      renderResourceFooter={() => <span className="tabular-nums">Total €{total.toLocaleString()}</span>}
      renderDayFooter={({ events: onDay }) => <span className="text-muted-foreground">{onDay.length || ""}</span>}
      styleConfig={{ sidebarWidth: 140 }}
      height={560}
      {...handlers}
    />
  )
}

About this demo

renderSidebar adds a right-hand column per row — days booked and revenue — with a total in the footer corner.

Things to try

  • Stretch an assignment and watch the revenue

The props behind it are explained in Resources.

Use ProScheduler in your project