From e85e545ef42e2530a8f8dcf10f702be49e357499 Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Wed, 27 Nov 2024 20:40:27 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(billing):=20ExpiryDate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/components/billing.tsx | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/admin/components/billing.tsx b/apps/admin/components/billing.tsx index a08ba0b..ac7bf4e 100644 --- a/apps/admin/components/billing.tsx +++ b/apps/admin/components/billing.tsx @@ -10,15 +10,32 @@ const BASE_URL = 'https://cdn.jsdelivr.net/gh/perfect-panel/ppanel-assets/billin interface BillingProps { type: 'dashboard' | 'payment'; } + +interface ItemType { + logo: string; + title: string; + description: string; + poster: string; + expiryDate: string; + href: string; +} + export default async function Billing({ type }: BillingProps) { const locale = await getLocale(); - const response = await fetch(BASE_URL, { cache: 'no-store' }); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + let list: ItemType[] = []; + try { + const response = await fetch(BASE_URL, { cache: 'no-store' }); + if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); + const data = await response.json(); + const now = new Date().getTime(); + list = data[type].filter((item) => { + const expiryDate = Date.parse(item.expiryDate); + return !isNaN(expiryDate) && expiryDate > now; + }); + } catch (error) { + return null; } - const data = await response.json(); - - if (data[type].length === 0) return null; + if (list && list.length === 0) return null; return (

@@ -30,7 +47,7 @@ export default async function Billing({ type }: BillingProps) {

- {data[type].map((item, index) => ( + {list.map((item, index) => (