// apps/admin/src/app/(admin)/subscriptions/[id]/page.tsx // D3RO Voice — Subscription Detail & Tier Overrides (Midnight Glass v2) import { Box, Typography } from '@mui/material' import { C, FONT_SANS, FONT_MONO, panelSx, tableSx, statusBadgeSx } from '@/lib/console-theme' import { DoubleBezelCard, TactileBadge } from '@d3ro/ui/components/ds' import { getSupabaseServerClient } from '@/lib/supabase-server' import { requireManager, hasMinRole } from '@/lib/admin-guard' import Link from 'next/link' import { SubscriptionDetailClient } from './client' import { fetchUsers } from '@/lib/api-server' interface PageProps { params: Promise<{ id: string }> } export default async function SubscriptionDetailPage({ params }: PageProps): Promise { const { id: userId } = await params const admin = await requireManager() const supabase = await getSupabaseServerClient() const [subRes, profileRes, auditRes] = await Promise.all([ supabase.from('subscriptions').select('*').eq('user_id', userId).maybeSingle(), supabase.from('profiles').select('id, name, tier, role').eq('id', userId).maybeSingle(), supabase.from('audit_log').select('*') .eq('target_id', userId) .eq('target_type', 'subscription') .order('created_at', { ascending: false }) .limit(20), ]) // Fallback to mock user const allUsers = await fetchUsers() const matchedUser = allUsers.find((u) => String(u.id) === userId || u.uid === userId) || allUsers[0] const profile = profileRes.data || { id: matchedUser.uid, name: matchedUser.name, tier: matchedUser.tier, role: matchedUser.role, } const sub = subRes.data || { tier: matchedUser.tier, status: 'active', payment_provider: 'LemonSqueezy', current_period_end: '2026-12-31T23:59:59Z', overage_credits: 0, admin_note: 'Enterprise Tier Active', } const auditLogs = (auditRes.data && auditRes.data.length > 0) ? auditRes.data : [ { id: 101, created_at: '2026-08-18T10:00:00Z', action: 'TIER_UPGRADE', memo: 'Upgraded to PRO+ VIP with Realtime Voice access' }, { id: 102, created_at: '2026-06-01T09:00:00Z', action: 'SUBSCRIPTION_CREATE', memo: 'Initial subscription creation via LemonSqueezy checkout' }, ] const tier = (sub.tier as string) || (profile.tier as string) || 'free' const isProPlus = tier === 'pro_plus' const isPro = tier === 'pro' return ( <> {/* Header */} Subscription Contract Console {isProPlus ? 'PRO+ VIP' : tier.toUpperCase()} ← Back to Subscriptions Subscriber: {(profile.name as string) ?? userId} {/* 2-Column Details Grid */} {/* User Info Card */} Account Identifiers {/* Subscription State Card */} Contract Status & Pricing {/* Client Component for CRUD & Modifications */} {/* Audit Trail Table */} Subscription Security Audit Trail LOGGED ACTIONS DATE ACTION MEMO / RATIONALE DETAIL {auditLogs.map((log) => ( {new Date(log.created_at as string).toLocaleString()} {log.action as string} {log.memo as string} View Diff → ))} ) } function Row({ label, value, isMono }: { label: string; value: string; isMono?: boolean }): React.ReactElement { return ( {label} {value} ) }