ProSchedulerSign in

Scheduler · Use cases

Drop attendees on meetings

Drag a person onto a meeting to add them. onExternalDropOnEvent fires when something dragged in lands on an event rather than an empty slot; the event it would join is outlined while you hover.

Live demo

Drag Hana onto a meeting · Drag the same person again — no duplicate

Fullscreen
import { ExternalDraggable, ProScheduler, type SchedulerEvent } from "@andreisaac/pro-scheduler"
import { studioResources, studioSessions } from "./data/studio"
import { useEvents } from "./kit"

type Meeting = SchedulerEvent & { attendees?: string[] }

export function DropAssigneeDemo() {
  const { events, setEvents, handlers } = useEvents<Meeting>(() =>
    studioSessions().map((e) => ({ ...e, resource: undefined, attendees: [e.resource] })),
  )
  const initials = (id: string) =>
    studioResources
      .find((r) => r.id === id)
      ?.name.split(" ")
      .map((w) => w[0])
      .join("") ?? "?"
  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap gap-2" aria-label="People">
        {studioResources.map((person) => (
          <ExternalDraggable key={person.id} event={{ title: person.name, person: person.id }}>
            <span
              className="flex items-center gap-1.5 rounded-full border border-border bg-card py-1 pr-3 pl-1 text-sm shadow-xs"
            >
              <span
                className="flex size-6 items-center justify-center rounded-full text-[10px] font-semibold text-white"
                style={{ backgroundColor: person.color }}
              >
                {initials(person.id)}
              </span>
              {person.name.split(" ")[0]}
            </span>
          </ExternalDraggable>
        ))}
      </div>
      <ProScheduler
        data={events}
        view={{ scheduler: { type: "week", startTime: "08:00", endTime: "19:00" } }}
        externalDrop
        // A person dropped on a meeting joins it (on empty space nothing happens).
        onExternalDropOnEvent={({ event, data }) => {
          const person = String(data.person)
          setEvents((list) =>
            list.map((e) =>
              e.id === event.id && !e.attendees?.includes(person)
                ? { ...e, attendees: [...(e.attendees ?? []), person] }
                : e,
            ),
          )
        }}
        dragToCreate={false}
        onEventCreate={() => false}
        renderEventContent={({ original, title }) => (
          <div className="flex h-full flex-col gap-1 overflow-hidden">
            <span className="truncate">{title}</span>
            <span className="flex -space-x-1.5">
              {((original as Meeting).attendees ?? []).map((id) => (
                <span
                  key={id}
                  className="flex size-5 items-center justify-center rounded-full text-[9px] font-semibold text-white ring-1 ring-white/80"
                  style={{ backgroundColor: studioResources.find((r) => r.id === id)?.color }}
                >
                  {initials(id)}
                </span>
              ))}
            </span>
          </div>
        )}
        height={600}
        {...handlers}
      />
    </div>
  )
}

About this demo

Drag a person onto a meeting to add them. onExternalDropOnEvent fires when something dragged in lands on an event rather than an empty slot; the event it would join is outlined while you hover.

Things to try

  • Drag Hana onto a meeting
  • Drag the same person again — no duplicate

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

Use ProScheduler in your project