import { Avatar, AvatarFallback, AvatarImage } from '@workspace/ui/components/avatar'; import { Card, CardDescription, CardHeader, CardTitle } from '@workspace/ui/components/card'; import { getTranslations } from 'next-intl/server'; import Link from 'next/link'; interface BillingProps { type: 'dashboard' | 'payment'; } interface ItemType { logo: string; title: string; description: string; expiryDate: string; href: string; } async function getBillingURL() { try { const response = await fetch( 'https://api.github.com/repos/perfect-panel/ppanel-assets/commits', ); const json = await response.json(); const version = json[0]?.sha; const url = new URL('https://cdn.jsdelivr.net/gh/perfect-panel/ppanel-assets'); url.pathname += `@${version}/billing/index.json`; return url.toString(); } catch (error) { return 'https://cdn.jsdelivr.net/gh/perfect-panel/ppanel-assets/billing/index.json'; } } export default async function Billing({ type }: BillingProps) { const t = await getTranslations('common.billing'); let list: ItemType[] = []; try { const url = await getBillingURL(); const response = await fetch(url, { headers: { Accept: 'application/json', }, }); const data = await response.json(); const now = Date.now(); list = Array.isArray(data[type]) ? data[type].filter((item: { expiryDate: string }) => { const expiryDate = Date.parse(item.expiryDate); return !isNaN(expiryDate) && expiryDate > now; }) : []; } catch (error) { console.log(error); return null; } if (!list?.length) return null; return ( <>

{t('title')} {t('description')}

{list.map((item, index) => ( {item.title}
{item.title} {item.description}
))}
); }