Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 8x 8x 8x 8x 8x 8x 8x 8x 8x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | 'use client'
import {useRouter} from 'next/navigation'
import {AddToCalendar, SubscribeCalendar} from '@/components/CalendarLinks'
import MapLink from '@/components/MapLink'
import Avatar from '@/components/Avatar'
import {useMemo, useState} from 'react'
import Link from 'next/link'
import {
nextAllFree,
formatDay,
scoreDays,
weekday,
withBlocks,
type Block,
type Entry,
type Kind,
type Member,
} from '@/lib/availability'
type RehearsalRow = {
id: string
date: string
time: string | null
place: string | null
note: string | null
by: string
mine: boolean
}
const STATES: {kind: Kind | null; label: string; on: string}[] = [
{kind: null, label: 'Free', on: 'bg-good-bg text-good-fg'},
{kind: 'PREFER_NOT', label: 'Prefer not', on: 'bg-info-bg text-info-fg'},
{kind: 'PM_OUT', label: 'PM out', on: 'bg-warn-bg text-warn-fg'},
{kind: 'OUT', label: 'Out', on: 'bg-bad-bg text-bad-fg'},
]
export default function Rehearsals({
me,
isAdmin,
horizon,
members,
entries: initialEntries,
blocks,
rehearsals,
bandName,
timezone,
blocksOn,
scheduling = true,
}: {
me: string
isAdmin: boolean
/** Every day ahead that the suggestions may search */
horizon: string[]
members: Member[]
entries: Entry[]
/** Members' rehearsals and gigs with their other bands */
blocks: Block[]
rehearsals: RehearsalRow[]
bandName: string
timezone: string
/** I'm in other bands and their dates count here */
blocksOn: boolean
/** The scheduling tool (days off, suggested days); off = just the list */
scheduling?: boolean
}) {
const router = useRouter()
const [entries, setEntries] = useState(initialEntries)
const [answered, setAnswered] = useState(
() => new Set(members.filter((m) => m.answered).map((m) => m.id)),
)
const [failed, setFailed] = useState<string | null>(null)
const [planning, setPlanning] = useState<string | null>(null)
const liveMembers = useMemo(
() => members.map((m) => ({...m, answered: answered.has(m.id)})),
[members, answered],
)
// Lists start short and grow on demand: the band books far ahead
const [aheadLimit, setAheadLimit] = useState(5)
const [weekCount, setWeekCount] = useState(8)
const [gridDays, setGridDays] = useState(28)
const [ranging, setRanging] = useState(false)
const days = horizon.slice(0, weekCount * 7)
// What counts: people's own marks plus their other bands' dates
const effective = useMemo(
() => withBlocks(entries, blocks),
[entries, blocks],
)
const blockAt = useMemo(
() => new Map(blocks.map((b) => [`${b.userId}|${b.date}`, b])),
[blocks],
)
const scores = useMemo(
() => scoreDays(horizon.slice(0, gridDays), liveMembers, effective),
[horizon, gridDays, liveMembers, effective],
)
const ahead = useMemo(
() => nextAllFree(scoreDays(horizon, liveMembers, effective), aheadLimit),
[horizon, liveMembers, effective, aheadLimit],
)
const lastMarked = entries.reduce((m, e) => (e.date > m ? e.date : m), '')
const booked = new Set(rehearsals.map((r) => r.date))
const mineOn = (date: string) =>
entries.find((e) => e.userId === me && e.date === date)?.kind ?? null
const unanswered = liveMembers.filter((m) => !m.answered).map((m) => m.name)
async function mark(date: string, kind: Kind | null) {
const before = entries
setEntries([
...entries.filter((e) => !(e.userId === me && e.date === date)),
...(kind ? [{userId: me, date, kind}] : []),
])
setAnswered(new Set([...answered, me]))
const r = await fetch('/api/availability', {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({date, kind}),
})
if (!r.ok) {
setEntries(before)
setFailed(date)
} else setFailed(null)
}
async function cancel(id: string) {
const r = await fetch(`/api/rehearsals/${id}`, {method: 'DELETE'})
if (r.ok) router.refresh()
}
// Group my days by week for the list
const weeks: string[][] = []
days.forEach((d, i) =>
i % 7 === 0 ? weeks.push([d]) : weeks[weeks.length - 1].push(d),
)
return (
<main className="mx-auto max-w-5xl px-4 pb-10 pt-5">
<h1 className="text-3xl font-extrabold">Rehearsals</h1>
{rehearsals.length > 0 && (
<section
aria-labelledby="next-reh"
className="mt-4 rounded-2xl border border-amber bg-panel p-4"
>
<h2
id="next-reh"
className="text-xs font-bold uppercase tracking-widest text-amber"
>
Coming up
</h2>
<ul className="mt-2 space-y-2">
{rehearsals.map((r) => (
<li
key={r.id}
className="flex flex-wrap items-baseline gap-x-3 gap-y-1"
>
<strong className="text-lg">{formatDay(r.date)}</strong>
{r.time && <span>{r.time}</span>}
{r.place && (
<MapLink
place={r.place}
className="text-sky no-underline hover:underline"
/>
)}
{r.note && (
<span className="basis-full text-sm text-muted">
{r.note}
</span>
)}
<span className="text-xs text-faint">set by {r.by}</span>
<AddToCalendar r={r} band={{name: bandName, timezone}} />
{(r.mine || isAdmin) && (
<button
type="button"
onClick={() => cancel(r.id)}
className="min-h-9 text-sm text-bad underline"
>
Cancel
</button>
)}
</li>
))}
</ul>
<SubscribeCalendar />
</section>
)}
{scheduling ? (
<>
<section
aria-labelledby="best-h"
data-tour="best-days"
className="mt-4 rounded-2xl bg-panel p-4"
>
<h2
id="best-h"
className="text-xs font-bold uppercase tracking-widest text-muted"
>
Next days everyone can make
</h2>
{unanswered.length > 0 && (
<p className="mt-1 text-sm text-muted">
Not answered yet: {unanswered.join(', ')} — counted as free
until they do.
</p>
)}
{!ahead.length && (
<p className="mt-2 text-sm text-bad">
No day in the next two years has nobody out.
</p>
)}
<ul className="mt-2">
{ahead.map((d, i) => (
<li
key={d.date}
className="border-t border-line py-2 first:border-t-0"
>
{d.date.slice(0, 7) !== ahead[i - 1]?.date.slice(0, 7) &&
i > 0 && (
<p className="mb-1 text-xs font-bold uppercase tracking-widest text-faint">
{monthName(d.date)}
</p>
)}
<div className="flex items-center gap-3">
<span className="flex min-w-0 flex-1 flex-col gap-0.5 sm:flex-row sm:items-center sm:gap-3">
<span className="shrink-0 font-mono font-bold text-amber sm:w-28">
{formatDay(d.date)}
</span>
<span className="min-w-0 text-sm">
{d.pmOut.length || d.preferNot.length ? (
<>
{d.pmOut.length > 0 && (
<span className="text-warn-fg">
Evening only (afternoon out:{' '}
{d.pmOut.join(', ')})
</span>
)}
{d.pmOut.length > 0 &&
d.preferNot.length > 0 &&
' · '}
{d.preferNot.length > 0 && (
<span className="text-info-fg">
Would rather not: {d.preferNot.join(', ')}
</span>
)}
</>
) : (
<strong className="text-good">Everyone free</strong>
)}
</span>
</span>
{booked.has(d.date) ? (
<span className="shrink-0 px-3 text-sm font-semibold leading-[44px] text-good">
Booked ✓
</span>
) : (
<button
type="button"
onClick={() =>
setPlanning(planning === d.date ? null : d.date)
}
className="min-h-11 shrink-0 rounded-lg border border-line-2 px-3 text-sm font-semibold"
>
Set rehearsal
</button>
)}
</div>
{planning === d.date && (
<PlanForm
date={d.date}
onDone={() => (setPlanning(null), router.refresh())}
/>
)}
</li>
))}
</ul>
{ahead.length === aheadLimit && (
<button
type="button"
onClick={() => setAheadLimit(aheadLimit + 5)}
className="mt-2 min-h-11 w-full rounded-lg border border-line-2 text-sm font-semibold"
>
Show 5 more days
</button>
)}
{ahead.length > 0 && ahead.length < aheadLimit && (
<p className="mt-2 text-xs text-faint">
That’s every such day in the next two years.
</p>
)}
{lastMarked && ahead.some((d) => d.date > lastMarked) && (
<p className="mt-2 text-xs text-faint">
Nobody has marked any days after {formatDay(lastMarked)} yet, so
later dates are only free as far as we know.
</p>
)}
</section>
<div className="mt-6 grid gap-8 lg:grid-cols-[minmax(0,22rem)_minmax(0,1fr)]">
<section aria-labelledby="mine-h">
{/* The tour points here, not at the whole list of days */}
<div data-tour="my-days">
<div className="flex items-baseline justify-between">
<h2 id="mine-h" className="text-lg font-bold">
Your days
</h2>
<button
type="button"
onClick={() => setRanging(!ranging)}
aria-expanded={ranging}
className="min-h-11 rounded-lg px-2 text-sm font-semibold text-sky"
>
Mark a stretch…
</button>
<span className="text-[13px] text-muted">
{failed ? 'Couldn’t save — try again' : 'Saved as you tap'}
</span>
</div>
<p className="mt-1 text-[13px] text-muted">
Mark the days you can’t make, or would rather not. Everything
else counts as free.
{blocksOn && (
<>
{' '}
Rehearsals and gigs with your other bands count
automatically (
<Link href="/account" className="text-sky">
change
</Link>
).
</>
)}
</p>
</div>
{ranging && (
<RangeForm
onApplied={(marked, kind) => {
const set = new Set(marked)
setEntries([
...entries.filter(
(e) => !(e.userId === me && set.has(e.date)),
),
...(kind
? marked.map((date) => ({userId: me, date, kind}))
: []),
])
setAnswered(new Set([...answered, me]))
setRanging(false)
}}
/>
)}
{weeks.map((w, wi) => (
<div key={wi} className="mt-3">
<h3 className="text-xs font-bold uppercase tracking-widest text-faint">
{wi === 0 ? 'This week' : `Week of ${formatDay(w[0])}`}
</h3>
{w.map((d) => {
const current = mineOn(d)
const busy = blockAt.get(`${me}|${d}`)
return (
<div
key={d}
className="flex flex-wrap items-center gap-x-2 border-t border-line py-1.5"
>
<span className="w-20 text-sm font-semibold">
{weekday(d)} {Number(d.slice(8))}
</span>
<div
role="radiogroup"
aria-label={formatDay(d)}
className="grid flex-1 grid-cols-4 overflow-hidden rounded-lg border border-line-2"
>
{STATES.map((s) => (
<button
key={s.label}
type="button"
role="radio"
aria-checked={current === s.kind}
onClick={() => mark(d, s.kind)}
className={`min-h-10 text-[13px] font-semibold ${current === s.kind ? s.on : 'text-faint'}`}
>
{s.label}
</button>
))}
</div>
{busy && (
<p className="basis-full pl-[5.5rem] pt-1 text-xs text-warn-fg">
{busy.label} — counts as{' '}
{busy.kind === 'OUT'
? 'out'
: 'out in the afternoon'}{' '}
here
</p>
)}
</div>
)
})}
</div>
))}
{weekCount * 7 < horizon.length && (
<button
type="button"
onClick={() => setWeekCount(weekCount + 4)}
className="mt-3 min-h-11 w-full rounded-lg border border-line-2 text-sm font-semibold"
>
Show 4 more weeks
</button>
)}
</section>
<section aria-labelledby="all-h" className="min-w-0">
<h2 id="all-h" className="text-lg font-bold">
Everyone
</h2>
<div className="mt-3 overflow-x-auto rounded-xl border border-line">
<table className="w-full border-collapse text-sm">
<thead>
<tr>
<th className="sticky left-0 bg-ink px-3 py-2 text-left align-bottom font-semibold">
{/* level with the names, above their status line */}
<span
className={`block ${unanswered.length ? 'pb-5' : ''}`}
>
Day
</span>
</th>
{liveMembers.map((m) => (
<th
key={m.id}
className="px-2 py-2 text-center align-bottom font-semibold"
>
{/* Picture, name, and a status line kept even when
empty, so every name sits on the same line */}
<span className="flex flex-col items-center gap-1">
<Avatar name={m.name} src={m.avatar} size={28} />
<span className="whitespace-nowrap">{m.name}</span>
{unanswered.length > 0 && (
<span className="block min-h-[1rem] text-[11px] font-normal text-faint">
{m.answered ? '' : 'no answer'}
</span>
)}
</span>
</th>
))}
</tr>
</thead>
<tbody>
{scores.slice(0, 28).map((s) => (
<tr key={s.date} className="border-t border-line">
<th
scope="row"
className="sticky left-0 whitespace-nowrap bg-ink px-3 py-1.5 text-left font-medium"
>
{formatDay(s.date)}
</th>
{liveMembers.map((m) => {
const k = effective.find(
(e) => e.userId === m.id && e.date === s.date,
)?.kind
const busy = blockAt.get(`${m.id}|${s.date}`)
return (
<td key={m.id} className="px-1 py-1 text-center">
<span
title={busy?.label}
className={`inline-flex h-7 min-w-12 items-center justify-center rounded font-mono text-xs font-bold ${busy ? 'ring-2 ring-inset ring-text/40 ' : ''}${
k === 'OUT'
? 'bg-bad-bg text-bad-fg'
: k === 'PM_OUT'
? 'bg-warn-bg text-warn-fg'
: k === 'PREFER_NOT'
? 'bg-info-bg text-info-fg'
: m.answered
? 'bg-good-bg text-good-fg'
: 'border border-dashed border-line-2 text-faint'
}`}
>
{k === 'OUT'
? 'OUT'
: k === 'PM_OUT'
? 'PM'
: k === 'PREFER_NOT'
? 'PREF'
: m.answered
? ''
: '?'}
</span>
</td>
)
})}
</tr>
))}
</tbody>
</table>
</div>
{gridDays < horizon.length && (
<button
type="button"
onClick={() => setGridDays(gridDays + 28)}
className="mt-2 min-h-11 w-full rounded-lg border border-line-2 text-sm font-semibold"
>
Show 4 more weeks
</button>
)}
<p className="mt-2 text-[13px] text-faint">
Blank = free · PREF = would rather not · PM = out in the
afternoon · OUT = out all day · ? = hasn’t answered
{blocks.length > 0 && ' · outlined = busy with another band'}
</p>
</section>
</div>
</>
) : (
<>
{!rehearsals.length && (
<p className="mt-4 text-muted">No rehearsals set yet.</p>
)}
<AddRehearsal onDone={() => router.refresh()} />
</>
)}
</main>
)
}
const monthFmt = new Intl.DateTimeFormat('en-US', {
month: 'long',
year: 'numeric',
timeZone: 'UTC',
})
function monthName(key: string) {
return monthFmt.format(new Date(key + 'T00:00:00Z'))
}
const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
/** Mark a stretch at once: "away Dec 18 – Jan 4", "out every Tuesday through March". */
function RangeForm({
onApplied,
}: {
onApplied: (days: string[], kind: Kind | null) => void
}) {
const [from, setFrom] = useState('')
const [to, setTo] = useState('')
const [kind, setKind] = useState<Kind | null>('OUT')
const [weekdays, setWeekdays] = useState<number[]>([])
const [error, setError] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
async function submit(e: React.FormEvent) {
e.preventDefault()
setBusy(true)
setError(null)
const r = await fetch('/api/availability/range', {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
from,
to,
kind,
...(weekdays.length ? {weekdays} : {}),
}),
})
setBusy(false)
if (!r.ok)
return setError(
(await r.json().catch(() => ({}))).error ?? 'Couldn’t save that.',
)
onApplied((await r.json()).days, kind)
}
const toggleDay = (d: number) =>
setWeekdays(
weekdays.includes(d) ? weekdays.filter((x) => x !== d) : [...weekdays, d],
)
return (
<form
onSubmit={submit}
className="mt-3 flex flex-col gap-3 rounded-xl border border-line-2 bg-panel p-3"
>
<div className="grid grid-cols-2 gap-2">
<label className="flex flex-col gap-1 text-xs text-muted">
From
<input
type="date"
required
value={from}
onChange={(e) => setFrom(e.target.value)}
className="min-h-11 rounded-lg border border-line-2 bg-ink px-2 text-base text-text"
/>
</label>
<label className="flex flex-col gap-1 text-xs text-muted">
Through
<input
type="date"
required
min={from}
value={to}
onChange={(e) => setTo(e.target.value)}
className="min-h-11 rounded-lg border border-line-2 bg-ink px-2 text-base text-text"
/>
</label>
</div>
<fieldset>
<legend className="mb-1 text-xs text-muted">Only on (optional)</legend>
<div className="flex flex-wrap gap-1">
{WEEKDAYS.map((w, i) => (
<button
key={w}
type="button"
aria-pressed={weekdays.includes(i)}
onClick={() => toggleDay(i)}
className={`min-h-10 rounded-lg px-2.5 text-sm ${weekdays.includes(i) ? 'bg-text font-semibold text-ink' : 'border border-line-2'}`}
>
{w}
</button>
))}
</div>
</fieldset>
<div
role="radiogroup"
aria-label="Mark as"
className="grid grid-cols-4 overflow-hidden rounded-lg border border-line-2"
>
{STATES.map((st) => (
<button
key={st.label}
type="button"
role="radio"
aria-checked={kind === st.kind}
onClick={() => setKind(st.kind)}
className={`min-h-10 text-[13px] font-semibold ${kind === st.kind ? st.on : 'text-faint'}`}
>
{st.label}
</button>
))}
</div>
<button
type="submit"
disabled={busy || !from || !to}
className="min-h-11 rounded-lg bg-accent font-bold text-on-accent disabled:opacity-40"
>
{busy ? 'Saving…' : 'Mark these days'}
</button>
{error && (
<p role="alert" className="text-sm text-bad">
{error}
</p>
)}
</form>
)
}
function PlanForm({date, onDone}: {date: string; onDone: () => void}) {
const [time, setTime] = useState('7pm')
const [place, setPlace] = useState('')
const [note, setNote] = useState('')
const [busy, setBusy] = useState(false)
async function submit(e: React.FormEvent) {
e.preventDefault()
setBusy(true)
const r = await fetch('/api/rehearsals', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({date, time, place, note}),
})
setBusy(false)
if (r.ok) onDone()
}
return (
<form
onSubmit={submit}
className="mt-2 grid gap-2 rounded-xl border border-line-2 p-3 sm:grid-cols-[8rem_1fr_auto]"
>
<label className="flex flex-col text-xs text-muted">
Time
<input
value={time}
onChange={(e) => setTime(e.target.value)}
className="min-h-11 rounded-lg border border-line-2 bg-ink px-3 text-base text-text"
/>
</label>
<label className="flex flex-col text-xs text-muted">
Where
<input
value={place}
onChange={(e) => setPlace(e.target.value)}
className="min-h-11 rounded-lg border border-line-2 bg-ink px-3 text-base text-text"
/>
</label>
<button
type="submit"
disabled={busy}
className="min-h-11 self-end rounded-lg bg-accent px-4 font-bold text-on-accent disabled:opacity-50"
>
{busy ? 'Saving…' : `Set for ${formatDay(date)}`}
</button>
<label className="flex flex-col text-xs text-muted sm:col-span-3">
Note (optional)
<input
value={note}
onChange={(e) => setNote(e.target.value)}
className="min-h-11 rounded-lg border border-line-2 bg-ink px-3 text-base text-text"
/>
</label>
</form>
)
}
/** No scheduling tool: pick the day yourself, then the same form. */
function AddRehearsal({onDone}: {onDone: () => void}) {
const [open, setOpen] = useState(false)
const [date, setDate] = useState('')
if (!open)
return (
<button
type="button"
onClick={() => setOpen(true)}
className="mt-4 min-h-12 w-full rounded-xl border border-dashed border-line-2 font-semibold"
>
+ Add a rehearsal
</button>
)
return (
<section className="mt-4 rounded-2xl bg-panel p-4">
<div className="mb-2 flex items-center justify-between">
<h2 className="text-lg font-bold">Add a rehearsal</h2>
<button
type="button"
onClick={() => (setOpen(false), setDate(''))}
className="min-h-11 px-2 text-sm text-muted"
>
Cancel
</button>
</div>
<label className="flex flex-col gap-1 text-xs text-muted">
Day
<input
type="date"
value={date}
onChange={(e) => setDate(e.target.value)}
className="min-h-11 rounded-lg border border-line-2 bg-ink px-3 text-base text-text"
/>
</label>
{date && (
<PlanForm
date={date}
onDone={() => {
setOpen(false)
setDate('')
onDone()
}}
/>
)}
</section>
)
}
|