'use client'; import React, { useState, useEffect, useCallback } from 'react'; import Link from 'next/link'; import { useAuth } from '@/contexts/AuthContext'; import { useRouter } from 'next/navigation'; const FLIGHT_COLORS: Record = { active: 'bg-green-400/10 text-green-400 border-green-400/20', scheduled: 'bg-blue-400/10 text-blue-400 border-blue-400/20', paused: 'bg-gray-600/20 text-gray-400 border-gray-600/20', expired: 'bg-red-400/10 text-red-400 border-red-400/20', cancelled: 'bg-[#1a1a1a] text-[#555] border-[#252525]', }; export default function AdOpsDashboardPage() { const { user, loading } = useAuth(); const router = useRouter(); const [stats, setStats] = useState(null); const [flights, setFlights] = useState([]); const [emailSchedule, setEmailSchedule] = useState([]); const [loadingData, setLoadingData] = useState(true); const [filterSite, setFilterSite] = useState(''); const [filterStatus, setFilterStatus] = useState(''); useEffect(() => { if (!loading && !user) router.push('/login?next=' + encodeURIComponent(window.location.pathname)); }, [user, loading, router]); const load = useCallback(async () => { setLoadingData(true); const params = new URLSearchParams(); if (filterSite) params.set('site', filterSite); if (filterStatus) params.set('status', filterStatus); const [statsR, flightsR, emailR] = await Promise.all([ fetch('/api/adops/rmp/stats'), fetch(`/api/adops/rmp/flights?${params}`), fetch('/api/adops/rmp/email-schedule'), ]); const [sd, fd, ed] = await Promise.all([statsR.json(), flightsR.json(), emailR.json()]); setStats(sd); setFlights(fd.flights ?? []); setEmailSchedule(ed.schedule ?? []); setLoadingData(false); }, [filterSite, filterStatus]); useEffect(() => { if (user) load(); }, [user, load]); if (loading) return
; if (!user) return null; return (

Ad Operations

Relevant Media Properties, LLC

{/* Stat Cards */}
{[ { label: 'Active Flights', key: 'active', color: 'text-green-400' }, { label: 'Expiring 30d', key: 'expiring_30d', color: 'text-yellow-400' }, { label: 'Expired This Month', key: 'expired_month', color: 'text-red-400' }, { label: 'Comped Running', key: 'comped', color: 'text-blue-400' }, { label: 'Unpaid Active', key: 'unpaid_active', color: 'text-orange-400' }, { label: 'Email Blasts Scheduled', key: 'email_scheduled', color: 'text-purple-400' }, ].map(c => (

{stats?.[c.key] ?? 0}

{c.label}

))}
{/* Filters */}
{/* Active Flights Table */}

Active Flights

View All IOs →
{['Client','Product','Site','Start','End','Status','Salesperson','Paid',''].map(h => ( ))} {loadingData ? ( ) : flights.length === 0 ? ( ) : flights.map((f: any) => ( ))}
{h}
Loading…
No flights found
{f.rmp_clients?.company_name ?? '—'} {f.rmp_products?.name ?? '—'} {f.rmp_orders?.site ?? '—'} {f.start_date} {f.end_date ?? '∞'} {f.flight_status} {f.rmp_sales_staff?.full_name ?? '—'} {f.is_comp ? 'Comp' : f.is_paid ? 'Paid' : 'Unpaid'} View
{/* Email Schedule */}

Email Distribution Schedule

{['Client','Type','Site','Scheduled Date','Status',''].map(h => ( ))} {emailSchedule.length === 0 ? ( ) : emailSchedule.map((e: any) => ( ))}
{h}
No email blasts scheduled
{e.rmp_clients?.company_name ?? '—'} {e.rmp_products?.product_type?.replace(/_/g, ' ')} {e.rmp_orders?.site ?? '—'} {e.email_scheduled_date ?? '—'} {e.email_sent_at ? 'Sent' : 'Pending'} {e.email_html_url && Preview}
); }