Initial commit: PodcastYes — AI podcast platform

This commit is contained in:
Leon Serfaty
2026-06-07 03:58:32 -04:00
commit 155507f21a
151 changed files with 19826 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
import type { Metadata } from "next";
import { prisma } from "@/lib/db";
import { PageHeader } from "@/components/app/page-header";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { PLANS, type PlanKey } from "@/lib/billing/plans";
import { formatPrice } from "@/lib/utils";
export const metadata: Metadata = { title: "Admin · Subscriptions" };
export default async function AdminSubscriptionsPage() {
const subs = await prisma.subscription.findMany({ orderBy: { createdAt: "desc" }, take: 200 });
const refIds = subs.map((s) => s.referenceId);
const [users, orgs] = await Promise.all([
prisma.user.findMany({ where: { id: { in: refIds } }, select: { id: true, name: true, email: true } }),
prisma.organization.findMany({ where: { id: { in: refIds } }, select: { id: true, name: true } }),
]);
const nameByRef = new Map<string, string>();
for (const u of users) nameByRef.set(u.id, u.email);
for (const o of orgs) nameByRef.set(o.id, o.name);
const active = subs.filter((s) => ["active", "trialing"].includes(s.status));
const mrr = active.reduce((sum, s) => sum + (PLANS[s.plan as PlanKey]?.priceMonthly ?? 0), 0);
const stripeCount = active.filter((s) => s.provider === "stripe").length;
const paypalCount = active.filter((s) => s.provider === "paypal").length;
return (
<>
<PageHeader title="Subscriptions" description="Revenue and active subscriptions." />
<div className="mb-6 grid gap-4 sm:grid-cols-4">
<Stat label="MRR" value={formatPrice(mrr)} />
<Stat label="ARR" value={formatPrice(mrr * 12)} />
<Stat label="Stripe" value={String(stripeCount)} />
<Stat label="PayPal" value={String(paypalCount)} />
</div>
<div className="overflow-x-auto rounded-lg border">
<table className="w-full text-sm">
<thead className="border-b bg-muted/40 text-left text-xs uppercase text-muted-foreground">
<tr>
<th className="p-3 font-medium">Customer</th>
<th className="p-3 font-medium">Plan</th>
<th className="p-3 font-medium">Provider</th>
<th className="p-3 font-medium">Status</th>
<th className="p-3 font-medium">Renews</th>
</tr>
</thead>
<tbody className="divide-y">
{subs.map((s) => (
<tr key={s.id} className="hover:bg-muted/20">
<td className="p-3">{nameByRef.get(s.referenceId) ?? s.referenceId}</td>
<td className="p-3 capitalize">{s.plan}</td>
<td className="p-3 capitalize">{s.provider}</td>
<td className="p-3">
<Badge variant={["active", "trialing"].includes(s.status) ? "success" : "secondary"}>
{s.cancelAtPeriodEnd ? "cancels soon" : s.status}
</Badge>
</td>
<td className="p-3 text-muted-foreground">
{s.periodEnd ? s.periodEnd.toLocaleDateString() : "—"}
</td>
</tr>
))}
{subs.length === 0 && (
<tr>
<td colSpan={5} className="p-8 text-center text-muted-foreground">
No subscriptions yet.
</td>
</tr>
)}
</tbody>
</table>
</div>
</>
);
}
function Stat({ label, value }: { label: string; value: string }) {
return (
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">{label}</CardTitle>
</CardHeader>
<CardContent>
<p className="font-display text-3xl font-extrabold tracking-tight">{value}</p>
</CardContent>
</Card>
);
}