fix: clean up admin bookings — add all contact fields, remove redundant NotifyToggle/filters

- Add phone to MC registrations display, instagram/telegram to group bookings
- Remove NotifyToggle from all 3 tabs (handled by Reminders tab)
- Remove FilterChips (Новые/Без напоминания) — redundant with Reminders tab
- Remove unused urgencyMap, mcItems fetch, MasterClassSlot/MasterClassItem types
- Fix delete button layout (pinned right, doesn't wrap)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 16:04:47 +03:00
parent 3458f88367
commit e617660467

View File

@@ -3,7 +3,6 @@
import { useState, useEffect, useMemo } from "react";
import { Loader2, Trash2, Phone, Instagram, Send, ChevronDown, ChevronRight, Bell, CheckCircle2, XCircle, Clock, Star, Calendar, DoorOpen } from "lucide-react";
import { adminFetch } from "@/lib/csrf";
import { NotifyToggle } from "../_components/NotifyToggle";
// --- Types ---
@@ -12,6 +11,8 @@ interface GroupBooking {
name: string;
phone: string;
groupInfo?: string;
instagram?: string;
telegram?: string;
notifiedConfirm: boolean;
notifiedReminder: boolean;
createdAt: string;
@@ -21,6 +22,7 @@ interface McRegistration {
id: number;
masterClassTitle: string;
name: string;
phone?: string;
instagram: string;
telegram?: string;
notifiedConfirm: boolean;
@@ -45,69 +47,13 @@ interface OpenDayBooking {
classHall?: string;
}
interface MasterClassSlot {
date: string;
startTime: string;
endTime: string;
}
interface MasterClassItem {
title: string;
slots: MasterClassSlot[];
}
type Tab = "reminders" | "classes" | "master-classes" | "open-day";
type NotifyFilter = "all" | "new" | "no-reminder";
// --- Filter Chips ---
function FilterChips({
filter,
setFilter,
newCount,
noReminderCount,
}: {
filter: NotifyFilter;
setFilter: (f: NotifyFilter) => void;
newCount: number;
noReminderCount: number;
}) {
const FILTERS: { key: NotifyFilter; label: string; count?: number }[] = [
{ key: "all", label: "Все" },
{ key: "new", label: "Новые", count: newCount },
{ key: "no-reminder", label: "Без напоминания", count: noReminderCount },
];
return (
<div className="flex items-center gap-2">
{FILTERS.map((f) => (
<button
key={f.key}
onClick={() => setFilter(f.key)}
className={`rounded-full px-3 py-1.5 text-xs font-medium transition-all ${
filter === f.key
? "bg-gold/20 text-gold border border-gold/40"
: "bg-neutral-800 text-neutral-400 border border-white/10 hover:text-white"
}`}
>
{f.label}
{f.count !== undefined && f.count > 0 && (
<span className="ml-1.5 rounded-full bg-red-500/20 text-red-400 px-1.5 py-0.5 text-[10px]">
{f.count}
</span>
)}
</button>
))}
</div>
);
}
// --- Group Bookings Tab ---
function GroupBookingsTab() {
const [bookings, setBookings] = useState<GroupBooking[]>([]);
const [loading, setLoading] = useState(true);
const [filter, setFilter] = useState<NotifyFilter>("all");
useEffect(() => {
adminFetch("/api/admin/group-bookings")
@@ -117,28 +63,6 @@ function GroupBookingsTab() {
.finally(() => setLoading(false));
}, []);
const newCount = bookings.filter((b) => !b.notifiedConfirm).length;
const noReminderCount = bookings.filter((b) => !b.notifiedReminder).length;
const filtered = useMemo(() => {
if (filter === "new") return bookings.filter((b) => !b.notifiedConfirm);
if (filter === "no-reminder") return bookings.filter((b) => !b.notifiedReminder);
return bookings;
}, [bookings, filter]);
async function handleToggle(id: number, field: "notified_confirm" | "notified_reminder") {
const b = bookings.find((x) => x.id === id);
if (!b) return;
const key = field === "notified_confirm" ? "notifiedConfirm" : "notifiedReminder";
const newValue = !b[key];
setBookings((prev) => prev.map((x) => x.id === id ? { ...x, [key]: newValue } : x));
await adminFetch("/api/admin/group-bookings", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "toggle-notify", id, field, value: newValue }),
});
}
async function handleDelete(id: number) {
await adminFetch(`/api/admin/group-bookings?id=${id}`, { method: "DELETE" });
setBookings((prev) => prev.filter((b) => b.id !== id));
@@ -147,41 +71,41 @@ function GroupBookingsTab() {
if (loading) return <LoadingSpinner />;
return (
<>
<FilterChips filter={filter} setFilter={setFilter} newCount={newCount} noReminderCount={noReminderCount} />
<div className="mt-3 space-y-2">
{filtered.length === 0 && <EmptyState total={bookings.length} />}
{filtered.map((b) => (
<div className="space-y-2">
{bookings.length === 0 && <EmptyState total={0} />}
{bookings.map((b) => (
<div
key={b.id}
className={`rounded-xl border p-4 space-y-2 transition-colors ${
!b.notifiedConfirm ? "border-gold/20 bg-gold/[0.03]" : "border-white/10 bg-neutral-900"
}`}
className="rounded-xl border border-white/10 bg-neutral-900 p-4"
>
<div className="flex items-center gap-3 flex-wrap">
<div className="flex items-start justify-between gap-3">
<div className="flex items-center gap-2 flex-wrap text-sm min-w-0">
<span className="font-medium text-white">{b.name}</span>
<a href={`tel:${b.phone.replace(/\D/g, "")}`} className="inline-flex items-center gap-1 text-emerald-400 hover:text-emerald-300 text-sm">
<Phone size={12} />{b.phone}
<a href={`tel:${b.phone.replace(/\D/g, "")}`} className="inline-flex items-center gap-1 text-emerald-400 hover:text-emerald-300 text-xs">
<Phone size={10} />{b.phone}
</a>
{b.instagram && (
<a href={`https://ig.me/m/${b.instagram.replace(/^@/, "")}`} target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-1 text-pink-400 hover:text-pink-300 text-xs">
<Instagram size={10} />{b.instagram}
</a>
{b.groupInfo && (
<>
<span className="text-neutral-600">·</span>
<span className="text-xs text-neutral-400 bg-neutral-800 rounded-full px-2 py-0.5">{b.groupInfo}</span>
</>
)}
<span className="text-neutral-600 text-xs ml-auto">{fmtDate(b.createdAt)}</span>
{b.telegram && (
<a href={`https://t.me/${b.telegram.replace(/^@/, "")}`} target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-1 text-blue-400 hover:text-blue-300 text-xs">
<Send size={10} />{b.telegram}
</a>
)}
{b.groupInfo && (
<span className="text-xs text-neutral-400 bg-neutral-800 rounded-full px-2 py-0.5">{b.groupInfo}</span>
)}
</div>
<div className="flex items-center gap-2 shrink-0">
<span className="text-neutral-600 text-xs">{fmtDate(b.createdAt)}</span>
<DeleteBtn onClick={() => handleDelete(b.id)} />
</div>
<NotifyToggle
confirmed={b.notifiedConfirm}
reminded={b.notifiedReminder}
onToggleConfirm={() => handleToggle(b.id, "notified_confirm")}
onToggleReminder={() => handleToggle(b.id, "notified_reminder")}
/>
</div>
</div>
))}
</div>
</>
);
}
@@ -189,76 +113,31 @@ function GroupBookingsTab() {
function McRegistrationsTab() {
const [regs, setRegs] = useState<McRegistration[]>([]);
const [mcItems, setMcItems] = useState<MasterClassItem[]>([]);
const [loading, setLoading] = useState(true);
const [filter, setFilter] = useState<NotifyFilter>("all");
useEffect(() => {
Promise.all([
adminFetch("/api/admin/mc-registrations").then((r) => r.json()),
adminFetch("/api/admin/sections/masterClasses").then((r) => r.json()),
])
.then(([regData, mcData]: [McRegistration[], { items: MasterClassItem[] }]) => {
setRegs(regData);
setMcItems(mcData.items || []);
})
adminFetch("/api/admin/mc-registrations")
.then((r) => r.json())
.then((data: McRegistration[]) => setRegs(data))
.catch(() => {})
.finally(() => setLoading(false));
}, []);
// Compute reminder urgency per MC title
const urgencyMap = useMemo(() => {
const map: Record<string, boolean> = {};
const now = Date.now();
const twoDays = 2 * 24 * 60 * 60 * 1000;
for (const mc of mcItems) {
map[mc.title] = (mc.slots || []).some((s) => {
if (!s.date) return false;
const slotTime = new Date(s.date + "T" + (s.startTime || "23:59")).getTime();
const diff = slotTime - now;
return diff >= 0 && diff <= twoDays;
});
}
return map;
}, [mcItems]);
const newCount = regs.filter((r) => !r.notifiedConfirm).length;
const noReminderCount = regs.filter((r) => !r.notifiedReminder).length;
const filtered = useMemo(() => {
if (filter === "new") return regs.filter((r) => !r.notifiedConfirm);
if (filter === "no-reminder") return regs.filter((r) => !r.notifiedReminder);
return regs;
}, [regs, filter]);
// Group by MC title
const grouped = useMemo(() => {
const map: Record<string, McRegistration[]> = {};
for (const r of filtered) {
for (const r of regs) {
if (!map[r.masterClassTitle]) map[r.masterClassTitle] = [];
map[r.masterClassTitle].push(r);
}
return map;
}, [filtered]);
}, [regs]);
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
function toggleExpand(key: string) {
setExpanded((prev) => ({ ...prev, [key]: !prev[key] }));
}
async function handleToggle(id: number, field: "notified_confirm" | "notified_reminder") {
const r = regs.find((x) => x.id === id);
if (!r) return;
const key = field === "notified_confirm" ? "notifiedConfirm" : "notifiedReminder";
const newValue = !r[key];
setRegs((prev) => prev.map((x) => x.id === id ? { ...x, [key]: newValue } : x));
await adminFetch("/api/admin/mc-registrations", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "toggle-notify", id, field, value: newValue }),
});
}
async function handleDelete(id: number) {
await adminFetch(`/api/admin/mc-registrations?id=${id}`, { method: "DELETE" });
setRegs((prev) => prev.filter((r) => r.id !== id));
@@ -267,13 +146,10 @@ function McRegistrationsTab() {
if (loading) return <LoadingSpinner />;
return (
<>
<FilterChips filter={filter} setFilter={setFilter} newCount={newCount} noReminderCount={noReminderCount} />
<div className="mt-3 space-y-2">
<div className="space-y-2">
{Object.keys(grouped).length === 0 && <EmptyState total={regs.length} />}
{Object.entries(grouped).map(([title, items]) => {
const isOpen = expanded[title] ?? false;
const groupNewCount = items.filter((r) => !r.notifiedConfirm).length;
return (
<div key={title} className="rounded-xl border border-white/10 overflow-hidden">
<button
@@ -283,58 +159,44 @@ function McRegistrationsTab() {
{isOpen ? <ChevronDown size={14} className="text-neutral-500 shrink-0" /> : <ChevronRight size={14} className="text-neutral-500 shrink-0" />}
<span className="font-medium text-white text-sm truncate">{title}</span>
<span className="text-[10px] text-neutral-500 bg-neutral-800 rounded-full px-2 py-0.5 shrink-0">{items.length}</span>
{urgencyMap[title] && (
<span className="text-[10px] text-red-400 bg-red-500/10 rounded-full px-2 py-0.5 shrink-0">скоро</span>
)}
{groupNewCount > 0 && (
<span className="text-[10px] text-gold bg-gold/10 rounded-full px-2 py-0.5 shrink-0">{groupNewCount} новых</span>
)}
</button>
{isOpen && (
<div className="px-4 pb-3 pt-1 space-y-1.5">
{items.map((r) => (
<div
key={r.id}
className={`rounded-lg border p-3 space-y-1.5 transition-colors ${
!r.notifiedConfirm ? "border-gold/20 bg-gold/[0.03]" : "border-white/5 bg-neutral-800/30"
}`}
className="rounded-lg border border-white/5 bg-neutral-800/30 p-3"
>
<div className="flex items-center gap-2 flex-wrap text-sm">
<span className="font-medium text-white">{r.name}</span>
<span className="text-neutral-500">·</span>
{r.phone && (
<a href={`tel:${r.phone.replace(/\D/g, "")}`} className="inline-flex items-center gap-1 text-emerald-400 hover:text-emerald-300 text-xs">
<Phone size={10} />{r.phone}
</a>
)}
{r.instagram && (
<a
href={`https://ig.me/m/${r.instagram.replace(/^@/, "")}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1 text-pink-400 hover:text-pink-300"
className="inline-flex items-center gap-1 text-pink-400 hover:text-pink-300 text-xs"
>
<Instagram size={12} />
<span className="text-neutral-300">{r.instagram}</span>
<Instagram size={10} />{r.instagram}
</a>
)}
{r.telegram && (
<>
<span className="text-neutral-600">·</span>
<a
href={`https://t.me/${r.telegram.replace(/^@/, "")}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1 text-blue-400 hover:text-blue-300"
className="inline-flex items-center gap-1 text-blue-400 hover:text-blue-300 text-xs"
>
<Send size={12} />
<span className="text-neutral-300">{r.telegram}</span>
<Send size={10} />{r.telegram}
</a>
</>
)}
<span className="text-neutral-600 text-xs ml-auto">{fmtDate(r.createdAt)}</span>
<DeleteBtn onClick={() => handleDelete(r.id)} />
</div>
<NotifyToggle
confirmed={r.notifiedConfirm}
reminded={r.notifiedReminder}
reminderUrgent={urgencyMap[r.masterClassTitle] && !r.notifiedReminder}
onToggleConfirm={() => handleToggle(r.id, "notified_confirm")}
onToggleReminder={() => handleToggle(r.id, "notified_reminder")}
/>
</div>
))}
</div>
@@ -343,7 +205,6 @@ function McRegistrationsTab() {
);
})}
</div>
</>
);
}
@@ -351,12 +212,9 @@ function McRegistrationsTab() {
function OpenDayBookingsTab() {
const [bookings, setBookings] = useState<OpenDayBooking[]>([]);
const [eventDate, setEventDate] = useState("");
const [loading, setLoading] = useState(true);
const [filter, setFilter] = useState<NotifyFilter>("all");
useEffect(() => {
// Get events to find active one
adminFetch("/api/admin/open-day")
.then((r) => r.json())
.then((events: { id: number; date: string }[]) => {
@@ -365,7 +223,6 @@ function OpenDayBookingsTab() {
return;
}
const ev = events[0];
setEventDate(ev.date);
return adminFetch(`/api/admin/open-day/bookings?eventId=${ev.id}`)
.then((r) => r.json())
.then((data: OpenDayBooking[]) => setBookings(data));
@@ -374,28 +231,10 @@ function OpenDayBookingsTab() {
.finally(() => setLoading(false));
}, []);
const reminderUrgent = useMemo(() => {
if (!eventDate) return false;
const now = Date.now();
const twoDays = 2 * 24 * 60 * 60 * 1000;
const eventTime = new Date(eventDate + "T10:00").getTime();
const diff = eventTime - now;
return diff >= 0 && diff <= twoDays;
}, [eventDate]);
const newCount = bookings.filter((b) => !b.notifiedConfirm).length;
const noReminderCount = bookings.filter((b) => !b.notifiedReminder).length;
const filtered = useMemo(() => {
if (filter === "new") return bookings.filter((b) => !b.notifiedConfirm);
if (filter === "no-reminder") return bookings.filter((b) => !b.notifiedReminder);
return bookings;
}, [bookings, filter]);
// Group by class — sorted by hall then time
const grouped = useMemo(() => {
const map: Record<string, { hall: string; time: string; style: string; trainer: string; items: OpenDayBooking[] }> = {};
for (const b of filtered) {
for (const b of bookings) {
const key = `${b.classHall}|${b.classTime}|${b.classStyle}`;
if (!map[key]) map[key] = { hall: b.classHall || "—", time: b.classTime || "—", style: b.classStyle || "—", trainer: b.classTrainer || "—", items: [] };
map[key].items.push(b);
@@ -405,26 +244,13 @@ function OpenDayBookingsTab() {
const hallCmp = a.hall.localeCompare(b.hall);
return hallCmp !== 0 ? hallCmp : a.time.localeCompare(b.time);
});
}, [filtered]);
}, [bookings]);
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
function toggleExpand(key: string) {
setExpanded((prev) => ({ ...prev, [key]: !prev[key] }));
}
async function handleToggle(id: number, field: "notified_confirm" | "notified_reminder") {
const b = bookings.find((x) => x.id === id);
if (!b) return;
const key = field === "notified_confirm" ? "notifiedConfirm" : "notifiedReminder";
const newValue = !b[key];
setBookings((prev) => prev.map((x) => x.id === id ? { ...x, [key]: newValue } : x));
await adminFetch("/api/admin/open-day/bookings", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "toggle-notify", id, field, value: newValue }),
});
}
async function handleDelete(id: number) {
await adminFetch(`/api/admin/open-day/bookings?id=${id}`, { method: "DELETE" });
setBookings((prev) => prev.filter((b) => b.id !== id));
@@ -433,13 +259,10 @@ function OpenDayBookingsTab() {
if (loading) return <LoadingSpinner />;
return (
<>
<FilterChips filter={filter} setFilter={setFilter} newCount={newCount} noReminderCount={noReminderCount} />
<div className="mt-3 space-y-2">
<div className="space-y-2">
{grouped.length === 0 && <EmptyState total={bookings.length} />}
{grouped.map(([key, group]) => {
const isOpen = expanded[key] ?? false;
const groupNewCount = group.items.filter((b) => !b.notifiedConfirm).length;
return (
<div key={key} className="rounded-xl border border-white/10 overflow-hidden">
<button
@@ -452,18 +275,13 @@ function OpenDayBookingsTab() {
<span className="text-xs text-neutral-500 truncate hidden sm:inline">· {group.trainer}</span>
<span className="text-[10px] text-neutral-500 bg-neutral-800 rounded-full px-2 py-0.5 shrink-0 ml-auto">{group.hall}</span>
<span className="text-[10px] text-neutral-500 bg-neutral-800 rounded-full px-2 py-0.5 shrink-0">{group.items.length} чел.</span>
{groupNewCount > 0 && (
<span className="text-[10px] text-gold bg-gold/10 rounded-full px-2 py-0.5 shrink-0">{groupNewCount} новых</span>
)}
</button>
{isOpen && (
<div className="px-4 pb-3 pt-1 space-y-1.5">
{group.items.map((b) => (
<div
key={b.id}
className={`rounded-lg border p-3 space-y-1.5 transition-colors ${
!b.notifiedConfirm ? "border-gold/20 bg-gold/[0.03]" : "border-white/5 bg-neutral-800/30"
}`}
className="rounded-lg border border-white/5 bg-neutral-800/30 p-3"
>
<div className="flex items-center gap-2 flex-wrap text-sm">
<span className="font-medium text-white">{b.name}</span>
@@ -493,13 +311,6 @@ function OpenDayBookingsTab() {
<span className="text-neutral-600 text-xs ml-auto">{fmtDate(b.createdAt)}</span>
<DeleteBtn onClick={() => handleDelete(b.id)} />
</div>
<NotifyToggle
confirmed={b.notifiedConfirm}
reminded={b.notifiedReminder}
reminderUrgent={reminderUrgent && !b.notifiedReminder}
onToggleConfirm={() => handleToggle(b.id, "notified_confirm")}
onToggleReminder={() => handleToggle(b.id, "notified_reminder")}
/>
</div>
))}
</div>
@@ -508,7 +319,6 @@ function OpenDayBookingsTab() {
);
})}
</div>
</>
);
}