From 2693491fee0fcc0653dd30770c67bd2a9bd4846d Mon Sep 17 00:00:00 2001 From: "diana.dolgolyova" Date: Tue, 24 Mar 2026 19:31:08 +0300 Subject: [PATCH] refactor: remove booking section from Open Day admin (managed in bookings page) --- src/app/admin/open-day/page.tsx | 170 +------------------------------- 1 file changed, 1 insertion(+), 169 deletions(-) diff --git a/src/app/admin/open-day/page.tsx b/src/app/admin/open-day/page.tsx index af786bc..b402b8b 100644 --- a/src/app/admin/open-day/page.tsx +++ b/src/app/admin/open-day/page.tsx @@ -2,11 +2,9 @@ import { useState, useEffect, useMemo, useCallback } from "react"; import { - Plus, X, Loader2, Calendar, Trash2, Ban, CheckCircle2, ChevronDown, ChevronUp, - Phone, Instagram, Send, + Plus, X, Loader2, Calendar, Trash2, Ban, CheckCircle2, } from "lucide-react"; import { adminFetch } from "@/lib/csrf"; -import { NotifyToggle } from "../_components/NotifyToggle"; // --- Types --- @@ -35,22 +33,6 @@ interface OpenDayClass { bookingCount: number; } -interface OpenDayBooking { - id: number; - classId: number; - eventId: number; - name: string; - phone: string; - instagram?: string; - telegram?: string; - notifiedConfirm: boolean; - notifiedReminder: boolean; - createdAt: string; - classStyle?: string; - classTrainer?: string; - classTime?: string; - classHall?: string; -} // --- Helpers --- @@ -411,155 +393,6 @@ function ScheduleGrid({ ); } -// --- Bookings Table --- - -function BookingsSection({ - eventId, - eventDate, -}: { - eventId: number; - eventDate: string; -}) { - const [open, setOpen] = useState(false); - const [bookings, setBookings] = useState([]); - const [loading, setLoading] = useState(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]); - - function load() { - setLoading(true); - adminFetch(`/api/admin/open-day/bookings?eventId=${eventId}`) - .then((r) => r.json()) - .then((data: OpenDayBooking[]) => setBookings(data)) - .catch(() => {}) - .finally(() => setLoading(false)); - } - - function toggle() { - if (!open) load(); - setOpen(!open); - } - - 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((x) => x.id !== id)); - } - - const newCount = bookings.filter((b) => !b.notifiedConfirm).length; - - return ( -
- - - {open && ( -
- {loading && ( -
- - Загрузка... -
- )} - - {!loading && bookings.length === 0 && ( -

Пока нет записей

- )} - - {bookings.map((b) => ( -
-
- {b.name} - - - {b.phone} - - {b.instagram && ( - - - {b.instagram} - - )} - {b.telegram && ( - - - {b.telegram} - - )} - - {b.classHall} {b.classTime} · {b.classStyle} - - -
- handleToggle(b.id, "notified_confirm")} - onToggleReminder={() => handleToggle(b.id, "notified_reminder")} - /> -
- ))} -
- )} -
- ); -} // --- Main Page --- @@ -705,7 +538,6 @@ export default function OpenDayAdminPage() { onClassesChange={() => loadClasses(event.id)} /> - ); }