import { supabase } from "@/lib/supabase"; import StopEditForm from "@/components/admin/StopEditForm"; import StopProductAssignment from "@/components/admin/StopProductAssignment"; import MessageCustomersSection from "@/components/admin/MessageCustomersSection"; import { getAdminUser } from "@/lib/admin-permissions"; import AdminAccessDenied from "@/components/admin/AdminAccessDenied"; import { redirect } from "next/navigation"; type StopDetailPageProps = { params: Promise<{ id: string; }>; }; export default async function StopDetailPage({ params }: StopDetailPageProps) { const { id } = await params; const [{ data: stop, error }, { data: brands }] = await Promise.all([ supabase .from("stops") .select("*, brands(name, slug)") .eq("id", id) .single(), supabase.from("brands").select("id, name, slug"), ]); const adminUser = await getAdminUser(); if (!adminUser) { return ; } if (!adminUser.can_manage_stops) redirect("/admin/pickup"); if (adminUser.brand_id && stop?.brand_id !== adminUser.brand_id) { return ; } if (error || !stop) { return (

Stop not found

            {error?.message ?? "Stop not found"}
          
← Back to Stops
); } const [{ data: allProducts }, { data: productStops }] = await Promise.all([ supabase .from("products") .select("id, name, type, price") .eq("brand_id", stop.brand_id) .eq("active", true), supabase .from("product_stops") .select("id, product_id, products(id, name, type, price)") .eq("stop_id", id), ]); const assignedProducts = (productStops ?? []) .map((ps: any) => ps) .filter(Boolean); return (
← Back to Stops

{stop.brands?.name}

{stop.city}, {stop.state}

{stop.location}

{stop.active ? "Active" : "Inactive"}

Date

{stop.date}

Time

{stop.time}

{stop.address && (

Address

{stop.address} {stop.zip ? `, ${stop.zip}` : ""}

)} {stop.cutoff_time && (

Cutoff

{new Date(stop.cutoff_time).toLocaleString()}

)}
Duplicate Stop

Assigned Products

Manage which products are available at this stop.

Edit Stop

Update stop details, location, and availability.

{/* Message Customers */}

Message Customers

Send updates to customers with pending pickups at this stop.

); }