diff --git a/src/app/admin/leads/page.tsx b/src/app/admin/leads/page.tsx index 69b89d0..d0b6fe9 100644 --- a/src/app/admin/leads/page.tsx +++ b/src/app/admin/leads/page.tsx @@ -1,5 +1,7 @@ -import Link from 'next/link'; +'use client'; + +import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Card, @@ -7,6 +9,7 @@ import { CardDescription, CardHeader, CardTitle, + CardFooter, } from '@/components/ui/card'; import { Table, @@ -16,12 +19,48 @@ import { TableHeader, TableRow, } from '@/components/ui/table'; -import { getLeads } from '@/lib/actions/leads'; +import { getLeads, type Lead } from '@/lib/actions/leads'; import { format } from 'date-fns'; -import { ExternalLink } from 'lucide-react'; +import { Download } from 'lucide-react'; +import { Skeleton } from '@/components/ui/skeleton'; + +export default function LeadsPage() { + const [leads, setLeads] = useState([]); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + async function fetchLeads() { + setIsLoading(true); + const fetchedLeads = await getLeads(); + setLeads(fetchedLeads); + setIsLoading(false); + } + fetchLeads(); + }, []); + + const handleExportCsv = () => { + const headers = ['Name', 'Email', 'Date Submitted']; + const csvContent = [ + headers.join(','), + ...leads.map(lead => + [ + `"${lead.name}"`, + `"${lead.email}"`, + `"${format(new Date(lead.createdAt), 'PPP p')}"` + ].join(',') + ) + ].join('\n'); + + const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.setAttribute('href', url); + link.setAttribute('download', 'leads.csv'); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + }; -export default async function LeadsPage() { - const leads = await getLeads(); return (
@@ -50,7 +89,17 @@ export default async function LeadsPage() { - {leads.length > 0 ? ( + {isLoading ? ( + <> + {[...Array(3)].map((_, i) => ( + + + + + + ))} + + ) : leads.length > 0 ? ( leads.map((lead) => ( {lead.name} @@ -70,6 +119,12 @@ export default async function LeadsPage() { + + +
);