ProSchedulerSign in

Timeline · Configuring the view

Role-based access

Per-event editable and resourceEditable, derived from who's signed in: viewers read, planners reschedule their team, admins change anything.

Live demo

As Planner, move Chloé's work — then try to reassign it · Switch to Viewer

Fullscreen
import { useMemo, useState } from "react"
import { ProScheduler } from "@andreisaac/pro-scheduler"
import { studioAssignments, studioResources } from "./data/studio"
import { Choice, Toolbar, useEvents } from "./kit"

type Role = "Viewer" | "Planner" | "Admin"

export function RoleAccessDemo() {
  const { events, handlers } = useEvents(studioAssignments)
  const [role, setRole] = useState<Role>("Planner")

  // Planners edit their own team (post-production) and only in time;
  // admins edit everything; viewers nothing.
  const team = ["chloe", "dev", "elin", "gus"]
  const shown = useMemo(
    () =>
      events.map((event) => ({
        ...event,
        editable: role === "Admin" || (role === "Planner" && team.includes(String(event.resource))),
        resourceEditable: role === "Admin",
      })),
    // team is a constant list
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [events, role]
  )

  return (
    <div className="docs-demo__stack">
      <Toolbar label="Signed in as">
        {(["Viewer", "Planner", "Admin"] as Role[]).map((r) => (
          <Choice key={r} active={role === r} onClick={() => setRole(r)}>
            {r}
          </Choice>
        ))}
        <span className="demo-muted">
          {role === "Viewer" && "Read-only."}
          {role === "Planner" && "Can reschedule post-production (Chloé, Dev, Elin, Gus), not reassign."}
          {role === "Admin" && "Can change anything."}
        </span>
      </Toolbar>
      <ProScheduler
        data={shown}
        resources={studioResources}
        view={{ timeline: { type: "month" } }}
        dragToCreate={role !== "Viewer"}
        showDefaultEditor={role === "Admin"}
        height={500}
        {...handlers}
      />
    </div>
  )
}

About this demo

Per-event editable and resourceEditable, derived from who's signed in: viewers read, planners reschedule their team, admins change anything.

Things to try

  • As Planner, move Chloé's work — then try to reassign it
  • Switch to Viewer

The props behind it are explained in Rules and backgrounds.

Use ProScheduler in your project