This repository has been archived on 2026-11-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
hope-events/frontend/src/components/reports/EventsDropdown.tsx
T
joshuaandClaude Opus 5.5 8f6f90a151 Searchable event picker and webhook guide (1.50.2)
- EventPicker replaces the plain event dropdowns on staff/supervisor pages and the kiosk:
  upcoming first, past behind "Show past events", search across all, keyboard support.
- Reports events list can be searched ("Select these N").
- Site settings -> Webhooks: "How webhooks work" guide with headers, signature checking
  (Node.js/PHP) and an example of every event type (EVENT_TYPES[].example, shape-tested).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
2026-10-29 08:23:09 +02:00

98 lines
4.2 KiB
TypeScript

"use client";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { ChevronDown, Search } from "lucide-react";
// The reports sidebar's events multi-select. With many events, the search box narrows the list
// and "Select all" picks only what matches.
export default function EventsDropdown({ options, value, onChange }: {
// `hint`: shown beside the title (the date) and searched too.
options: { value: string; label: string; hint?: string }[];
value: string[];
onChange: (v: string[]) => void;
}) {
const [open, setOpen] = useState(false);
const [query, setQuery] = useState("");
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const onClick = (e: MouseEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
};
document.addEventListener("mousedown", onClick);
return () => document.removeEventListener("mousedown", onClick);
}, []);
const shown = useMemo(() => {
const words = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
if (!words.length) return options;
return options.filter(o => {
const hay = `${o.label} ${o.hint || ""}`.toLowerCase();
return words.every(w => hay.includes(w));
});
}, [options, query]);
const toggle = (v: string) => {
onChange(value.includes(v) ? value.filter(x => x !== v) : [...value, v]);
};
const selectShown = () => onChange(Array.from(new Set([...value, ...shown.map(o => o.value)])));
const clearShown = () => {
const drop = new Set(shown.map(o => o.value));
onChange(query.trim() ? value.filter(v => !drop.has(v)) : []);
};
const summary = value.length === 0
? "No events selected"
: options.length > 0 && value.length === options.length
? "All events"
: value.length === 1
? (options.find(o => o.value === value[0])?.label || "1 event selected")
: `${value.length} events selected`;
return (
<div className="relative" ref={ref}>
<button
type="button"
aria-expanded={open}
aria-label={`Events: ${summary}`}
onClick={() => setOpen(o => !o)}
className="w-full flex items-center justify-between gap-2 border rounded-lg px-3 py-2 text-sm bg-white hover:bg-gray-50"
>
<span className="truncate text-left">{summary}</span>
<ChevronDown className={"w-4 h-4 text-gray-500 shrink-0 transition-transform " + (open ? "rotate-180" : "")} aria-hidden />
</button>
{open && (
<div className="absolute z-20 mt-1 left-0 right-0 min-w-[16rem] bg-white border rounded-lg shadow-lg p-1">
<div className="flex items-center gap-2 px-2 border-b">
<Search className="w-3.5 h-3.5 text-gray-500 shrink-0" aria-hidden />
<input
autoFocus
type="text"
aria-label="Search events"
placeholder="Search events…"
className="flex-1 py-1.5 text-sm outline-none bg-transparent"
value={query}
onChange={e => setQuery(e.target.value)}
onKeyDown={e => { if (e.key === "Escape") setOpen(false); }}
/>
</div>
<div className="flex items-center justify-between px-2 py-1.5 text-xs text-gray-600 border-b mb-1">
<button type="button" className="hover:underline" onClick={selectShown}>{query.trim() ? `Select these ${shown.length}` : "Select all"}</button>
<button type="button" className="hover:underline" onClick={clearShown}>{query.trim() ? "Clear these" : "Clear"}</button>
</div>
<div className="max-h-64 overflow-auto">
{shown.map(opt => (
<label key={opt.value} className="flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-gray-50 cursor-pointer">
<input type="checkbox" checked={value.includes(opt.value)} onChange={() => toggle(opt.value)} />
<span className="truncate flex-1">{opt.label}</span>
{opt.hint && <span className="shrink-0 text-xs text-gray-500">{opt.hint}</span>}
</label>
))}
{shown.length === 0 && <div className="px-2 py-1.5 text-xs text-gray-500">{options.length ? "No events match." : "No events available."}</div>}
</div>
</div>
)}
</div>
);
}