feat(admin): per-row badge preview with unconfigured tooltip, Excel-style column filters and search in Contacts/Registrations
- New shared BadgeRender module (resolveText/resolveQr/BadgeElementBody/BadgePagePreview/fitScale) reused by the badge editor and the new read-only preview modal - Registrations: Badge button on every row opens a live preview of that attendee's badge; grayed out with a Uiverse-style APPE-red tooltip when the event has no badge configured - Contacts + Registrations: per-column multi-select filters (LinkedIn/Visibility/Admin; Type/Ticket/Checked in) with Excel-style live counts, plus general search (contacts: first/last/email; registrations: +type) - New Tooltip and ColumnFilter primitives in ui.tsx (portal-based, escape/outside-click close) - e2e: registration-badge-preview.spec.ts (13) + table-filters.spec.ts (13), all green; docs synced
This commit is contained in:
1 parent
6b277a2a67
commit
3d4dc207ff
10 files changed
+988
-121
No files matched your search
@@ -2,13 +2,24 @@ import { useEffect, useMemo, useState } from 'react';
|
||||
import { adjustPoints, deleteContact, getAllContacts, updateContact, upsertContact } from '../lib/api';
|
||||
import type { Contact } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Avatar, Empty, Modal, Spinner, Toggle } from '../components/ui';
|
||||
import { Avatar, ColumnFilter, Empty, Modal, Spinner, Toggle, type ColumnFilterOption } from '../components/ui';
|
||||
|
||||
// Multi-select column filters are Excel-style: an empty selection means "all".
|
||||
const VIS_LABELS: Record<string, string> = { both: 'Both shown', email: 'Email only', linkedin: 'LinkedIn only', none: 'None shown' };
|
||||
const visKey = (c: Contact) => (c.show_email && c.show_linkedin ? 'both' : c.show_email ? 'email' : c.show_linkedin ? 'linkedin' : 'none');
|
||||
const ynOptions = (rows: Contact[], fn: (c: Contact) => boolean): ColumnFilterOption[] => [
|
||||
{ value: 'yes', label: 'Yes', count: rows.filter(fn).length },
|
||||
{ value: 'no', label: 'No', count: rows.filter((c) => !fn(c)).length },
|
||||
];
|
||||
|
||||
export function Contacts() {
|
||||
const { push } = useToast();
|
||||
const [contacts, setContacts] = useState<Contact[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [query, setQuery] = useState('');
|
||||
const [fLinkedin, setFLinkedin] = useState<string[]>([]);
|
||||
const [fVis, setFVis] = useState<string[]>([]);
|
||||
const [fAdmin, setFAdmin] = useState<string[]>([]);
|
||||
|
||||
const [editing, setEditing] = useState<Contact | null>(null);
|
||||
const [creating, setCreating] = useState(false);
|
||||
@@ -41,18 +52,37 @@ export function Contacts() {
|
||||
load();
|
||||
}, []);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
// General search: first name, last name or email address.
|
||||
const searched = useMemo(() => {
|
||||
if (!contacts) return [];
|
||||
const q = query.trim().toLowerCase();
|
||||
if (!q) return contacts;
|
||||
return contacts.filter(
|
||||
(c) =>
|
||||
c.full_name.toLowerCase().includes(q) ||
|
||||
c.email.toLowerCase().includes(q) ||
|
||||
(c.linkedin_url ?? '').toLowerCase().includes(q),
|
||||
);
|
||||
return contacts.filter((c) => {
|
||||
const name = c.full_name.toLowerCase();
|
||||
return name.split(/\s+/).some((part) => part.includes(q)) || name.includes(q) || c.email.toLowerCase().includes(q);
|
||||
});
|
||||
}, [contacts, query]);
|
||||
|
||||
const passLinkedin = (c: Contact) => fLinkedin.length === 0 || fLinkedin.includes(c.linkedin_url ? 'yes' : 'no');
|
||||
const passVis = (c: Contact) => fVis.length === 0 || fVis.includes(visKey(c));
|
||||
const passAdmin = (c: Contact) => fAdmin.length === 0 || fAdmin.includes(c.is_admin ? 'yes' : 'no');
|
||||
const filtered = useMemo(
|
||||
() => searched.filter((c) => passLinkedin(c) && passVis(c) && passAdmin(c)),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[searched, fLinkedin, fVis, fAdmin],
|
||||
);
|
||||
// Option counts follow Excel: each column counts what the OTHER filters leave.
|
||||
const linkedinOptions = ynOptions(searched.filter((c) => passVis(c) && passAdmin(c)), (c) => !!c.linkedin_url);
|
||||
const adminOptions = ynOptions(searched.filter((c) => passLinkedin(c) && passVis(c)), (c) => c.is_admin);
|
||||
const visCounts = new Map<string, number>();
|
||||
for (const c of searched.filter((c) => passLinkedin(c) && passAdmin(c))) {
|
||||
const k = visKey(c);
|
||||
visCounts.set(k, (visCounts.get(k) ?? 0) + 1);
|
||||
}
|
||||
const visOptions = ['both', 'email', 'linkedin', 'none']
|
||||
.filter((k) => visCounts.has(k))
|
||||
.map((k) => ({ value: k, label: VIS_LABELS[k], count: visCounts.get(k)! }));
|
||||
|
||||
if (error) return <Empty icon="⚠️" text={error} />;
|
||||
if (!contacts)
|
||||
return (
|
||||
@@ -72,7 +102,7 @@ export function Contacts() {
|
||||
<input
|
||||
className="input"
|
||||
style={{ maxWidth: 260 }}
|
||||
placeholder="Search name, email…"
|
||||
placeholder="Search first name, last name, email…"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
@@ -87,9 +117,9 @@ export function Contacts() {
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>LinkedIn</th>
|
||||
<th>Visibility</th>
|
||||
<th>Admin</th>
|
||||
<th>LinkedIn <ColumnFilter label="LinkedIn" options={linkedinOptions} selected={fLinkedin} onChange={setFLinkedin} /></th>
|
||||
<th>Visibility <ColumnFilter label="Visibility" options={visOptions} selected={fVis} onChange={setFVis} /></th>
|
||||
<th>Admin <ColumnFilter label="Admin" options={adminOptions} selected={fAdmin} onChange={setFAdmin} /></th>
|
||||
<th style={{ textAlign: 'right' }}>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
Reference in new issue
Block a user