| 1 | "use client"; |
| 2 | |
| 3 | import Link from "next/link" |
| 4 | import { useQuery } |
| 5 | import { useTranslations } |
| 6 | import { Layers } |
| 7 | import { orpc } |
| 8 | |
| 9 | function CategoryCard({ |
| 10 | name, |
| 11 | description, |
| 12 | iconUrl, |
| 13 | bannerUrl, |
| 14 | planCount, |
| 15 | href, |
| 16 | }: { |
| 17 | name: string |
| 18 | description: string |
| 19 | iconUrl: string |
| 20 | bannerUrl: string |
| 21 | planCount: number |
| 22 | href: string |
| 23 | }) { |
| 24 | const t = |
| 25 | return ( |
| 26 | <Link href={ |
| 27 | <div className="relative h-32 overflow-hidden |
| 28 | {bannerUrl |
| 29 | ? <img src= |
| 30 | : <div className= |
| 31 | } |
| 32 | <div className="absolute inset-x-0 bottom-0 h-20 bg-gradient-to-t from-card to-transparent |
| 33 | </div> |
| 34 | |
| 35 | <div className="relative -mt-8 flex items-end gap-3 px-4 pb-4 |
| 36 | <div className="flex h-14 w-14 shrink-0 items-center justify-center overflow-hidden rounded-xl bg-muted |
| 37 | {iconUrl |
| 38 | ? <img src= |
| 39 | : <Layers className |
| 40 | } |
| 41 | </div> |
| 42 | <div className="min-w-0 flex-1 pb-0.5 |
| 43 | <p className="truncate text-sm font-semibold text-foreground |
| 44 | {description && <p |
| 45 | </div> |
| 46 | </div> |
| 47 | |
| 48 | <div className="border-t border-border/60 px-4 py-2.5 flex items-center justify-between |
| 49 | <span className="text-xs text-muted-foreground |
| 50 | {planCount} {planCount |
| 51 | </span> |
| 52 | <span className="text-xs font-medium text-primary opacity-0 transition-opacity group-hover:opacity-100 |
| 53 | {t("getStarted") |
| 54 | </span> |
| 55 | </div> |
| 56 | </Link> |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | export default function BillingPage |
| 61 | const t = |
| 62 | |
| 63 | const { data: |
| 64 | orpc.billing.listCategories |
| 65 | ); |
| 66 | const { data: |
| 67 | orpc.billing.listProducts |
| 68 | ); |
| 69 | |
| 70 | const isLoading = |
| 71 | |
| 72 | const planCountByCategory = |
| 73 | for (const p |
| 74 | planCountByCategory.set(p |
| 75 | } |
| 76 | |
| 77 | const visibleCategories = |
| 78 | |
| 79 | return ( |
| 80 | <div className="flex-1 overflow-auto px-4 py-5 sm:px-6 |
| 81 | <div className="mx-auto max-w-5xl flex flex-col gap-6 |
| 82 | <div> |
| 83 | <h1 className="text-sm font-semibold text-foreground |
| 84 | <p className="mt-0.5 text-xs text-muted-foreground |
| 85 | </div> |
| 86 | |
| 87 | {isLoading ? ( |
| 88 | <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 |
| 89 | {Array.from({ |
| 90 | <div key={i |
| 91 | ))} |
| 92 | </div> |
| 93 | ) : visibleCategories.length |
| 94 | <div className="flex flex-col items-center gap-3 py-20 text-center |
| 95 | <Layers className=" |
| 96 | <p className="text-sm text-muted-foreground |
| 97 | </div> |
| 98 | ) : ( |
| 99 | <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 |
| 100 | {visibleCategories.map(( |
| 101 | <CategoryCard |
| 102 | key={cat.id |
| 103 | name={cat.name |
| 104 | description={cat.description |
| 105 | iconUrl={cat.icon |
| 106 | bannerUrl={cat.bannerUrl |
| 107 | planCount={planCountByCategory.get |
| 108 | href={`/billing/${cat |
| 109 | /> |
| 110 | ))} |
| 111 | </div> |
| 112 | )} |
| 113 | </div> |
| 114 | </div> |
| 115 | ); |
| 116 | } |