nextjs-dashboard/app/ui/dashboard/cards.tsx

67 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-04-18 01:57:35 -07:00
import {
BanknotesIcon,
ClockIcon,
UserGroupIcon,
InboxIcon,
} from '@heroicons/react/24/outline';
import { lusitana } from '@/app/ui/fonts';
2024-04-18 06:05:21 -07:00
import { fetchCardData } from '@/app/lib/data';
2024-04-18 01:57:35 -07:00
const iconMap = {
collected: BanknotesIcon,
customers: UserGroupIcon,
pending: ClockIcon,
invoices: InboxIcon,
};
export default async function CardWrapper() {
2024-04-18 06:05:21 -07:00
const {
numberOfInvoices,
numberOfCustomers,
totalPaidInvoices,
totalPendingInvoices,
} = await fetchCardData();
2024-04-18 01:57:35 -07:00
return (
<>
{/* NOTE: comment in this code when you get to this point in the course */}
2024-04-18 06:05:21 -07:00
<Card title="Collected" value={totalPaidInvoices} type="collected" />
2024-04-18 01:57:35 -07:00
<Card title="Pending" value={totalPendingInvoices} type="pending" />
<Card title="Total Invoices" value={numberOfInvoices} type="invoices" />
<Card
title="Total Customers"
value={numberOfCustomers}
type="customers"
2024-04-18 06:05:21 -07:00
/>
2024-04-18 01:57:35 -07:00
</>
);
}
export function Card({
title,
value,
type,
}: {
title: string;
value: number | string;
type: 'invoices' | 'customers' | 'pending' | 'collected';
}) {
const Icon = iconMap[type];
return (
<div className="rounded-xl bg-gray-50 p-2 shadow-sm">
<div className="flex p-4">
{Icon ? <Icon className="h-5 w-5 text-gray-700" /> : null}
<h3 className="ml-2 text-sm font-medium">{title}</h3>
</div>
<p
className={`${lusitana.className}
truncate rounded-xl bg-white px-4 py-8 text-center text-2xl`}
>
{value}
</p>
</div>
);
}