ProSchedulerSign in

Timeline · Use cases

Work order assignment

Unassigned jobs wait in a list: drag one onto a technician to assign it, or drag an assigned job back onto the list — an ExternalDropZone — to unassign it.

Live demo

Assign a job to Chen Wei · Drag a job back to the list

Fullscreen
import { useState } from "react"
import { ExternalDraggable, ExternalDropZone, ProScheduler, type SchedulerEvent } from "@andreisaac/pro-scheduler"
import { priorityColors, technicians, workOrders } from "./data/operations"
import { useEvents } from "./kit"

/** A card in a side list. */
function Card({ color, title, meta }: { color?: string; title: string; meta?: string }) {
  return (
    <div className="flex items-center gap-2 rounded-md border border-border bg-card px-2.5 py-2 text-sm shadow-xs">
      <span className="size-2.5 shrink-0 rounded-full" style={{ backgroundColor: color ?? "var(--primary)" }} />
      <span className="min-w-0 flex-1 truncate font-medium">{title}</span>
      {meta && <span className="shrink-0 text-xs text-muted-foreground">{meta}</span>}
    </div>
  )
}

const minutes = (n = 60) => (n >= 60 ? `${n / 60} h` : `${n} min`)

export function WorkOrderAssignmentDemo() {
  // Half the jobs start unassigned, in the list.
  const all = workOrders().map((w) => ({ ...w, color: priorityColors[w.priority] }))
  const { events, setEvents } = useEvents(() => all.filter((_, i) => i % 2 === 0))
  const [queue, setQueue] = useState<SchedulerEvent[]>(() => all.filter((_, i) => i % 2 === 1))
  const lengthOf = (e: SchedulerEvent) =>
    Math.round((new Date(e.end!).getTime() - new Date(e.start).getTime()) / 60_000)
  return (
    <div className="grid gap-3 md:grid-cols-[230px_1fr]">
      <ExternalDropZone
        // An assigned job dragged back here is unassigned.
        onDrop={(job) => setQueue((q) => [...q, job])}
        className="flex flex-col gap-2 rounded-lg border border-dashed border-border p-2 data-[over]:border-primary data-[over]:bg-primary/5"
      >
        <p className="text-xs font-medium text-muted-foreground">Unassigned — drag in or out</p>
        {queue.map((job) => (
          <ExternalDraggable key={String(job.id)} event={{ ...job, start: undefined, end: undefined, duration: lengthOf(job) }}>
            <Card color={job.color} title={job.title} meta={minutes(lengthOf(job))} />
          </ExternalDraggable>
        ))}
      </ExternalDropZone>
      <ProScheduler
        data={events}
        resources={technicians}
        view={{ timeline: { type: "week", resolutionHorizontal: "hour", startTime: "07:00", endTime: "19:00" } }}
        styleConfig={{ unitWidthPx: 26, fitToWidth: false }}
        externalDrop
        externalDrag
        height={480}
        onEventCreated={(event) => {
          setEvents((list) => [...list, event as (typeof list)[number]])
          setQueue((q) => q.filter((j) => j.id !== event.id))
        }}
        onEventUpdated={(event) => setEvents((list) => list.map((e) => (e.id === event.id ? (event as typeof e) : e)))}
        onEventDeleted={(event) => setEvents((list) => list.filter((e) => e.id !== event.id))}
      />
    </div>
  )
}

About this demo

Unassigned jobs wait in a list: drag one onto a technician to assign it, or drag an assigned job back onto the list — an ExternalDropZone — to unassign it.

Things to try

  • Assign a job to Chen Wei
  • Drag a job back to the list

The props behind it are explained in Selection, drag and drop, links.

Use ProScheduler in your project