From 37b3cab6ad9ee9dafce80b368c84a9cc732df2c5 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 19 Nov 2025 10:17:30 +0530 Subject: [PATCH 1/2] feat: Add total views and registrations statistics to the company event dashboard and refine the stats card layout. --- app/dashboard/company/[slug]/events/page.tsx | 52 ++++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/app/dashboard/company/[slug]/events/page.tsx b/app/dashboard/company/[slug]/events/page.tsx index 949d75e7..35b27c0f 100644 --- a/app/dashboard/company/[slug]/events/page.tsx +++ b/app/dashboard/company/[slug]/events/page.tsx @@ -41,7 +41,7 @@ export default function CompanyEventsPage() { setLoading(true) // Fetch all events (not just approved) for company members const response = await fetch(`/api/companies/${currentCompany.slug}/events?status=all&limit=100`) - + if (!response.ok) { throw new Error('Failed to fetch events') } @@ -78,7 +78,7 @@ export default function CompanyEventsPage() { const handleDeleteEvent = async (eventSlug: string) => { try { setDeletingEventSlug(eventSlug) - + const response = await fetch(`/api/events/${eventSlug}`, { method: 'DELETE', }) @@ -88,7 +88,7 @@ export default function CompanyEventsPage() { } toast.success('Event deleted successfully') - + // Refresh the events list await fetchEvents() } catch (error) { @@ -104,40 +104,42 @@ export default function CompanyEventsPage() { approved: events.filter(e => e.approval_status === 'approved').length, pending: events.filter(e => e.approval_status === 'pending').length, draft: events.filter(e => e.status === 'draft').length, + totalViews: events.reduce((sum, e) => sum + (e.views || 0), 0), + totalRegistrations: events.reduce((sum, e) => sum + (e.registered || 0), 0), } const getApprovalBadge = (status: string) => { switch (status) { case 'approved': return ( - + Approved ) case 'pending': return ( - + Pending ) case 'rejected': return ( - + Rejected ) case 'changes_requested': return ( - + Changes Requested ) default: - return {status} + return {status} } } @@ -145,15 +147,15 @@ export default function CompanyEventsPage() { switch (status) { case 'live': case 'published': - return Live + return Live case 'draft': - return Draft + return Draft case 'cancelled': - return Cancelled + return Cancelled case 'completed': - return Completed + return Completed default: - return {status} + return {status} } } @@ -186,7 +188,7 @@ export default function CompanyEventsPage() { {/* Stats Cards */} -
+
Total Events @@ -223,6 +225,24 @@ export default function CompanyEventsPage() {
{stats.draft}
+ + + Total Views + + + +
{stats.totalViews}
+
+
+ + + Total Registrations + + + +
{stats.totalRegistrations}
+
+
{/* Search */} @@ -329,8 +349,8 @@ export default function CompanyEventsPage() { )} - + +
+

Event Registrations

+

+ {eventTitle} +

+
+
+ + + + {/* Stats Card */} + + + Total Registrations + + + +
{total}
+
+
+ + {/* Filters */} +
+
+ + setSearchTerm(e.target.value)} + className="pl-10" + /> +
+ + +
+ + {/* Registrations Table */} + + + Registrations ({registrations.length}) + + Manage and view all event registrations + + + + {loading ? ( +
+
+
+ ) : registrations.length === 0 ? ( +
+ +

+ No registrations found +

+

+ {searchTerm || statusFilter !== 'all' || paymentFilter !== 'all' + ? 'Try adjusting your filters' + : 'No one has registered for this event yet'} +

+
+ ) : ( +
+ + + + Participant + Email + Phone + Status + Payment + Registered + Actions + + + + {registrations.map((registration) => ( + + +
+ + {registration.profile_name || registration.full_name || registration.email || `User ${registration.user_id.substring(0, 8)}`} + + {registration.experience_level && ( + + {registration.experience_level} + + )} +
+
+ + {registration.email ? ( + {registration.email} + ) : ( + - + )} + + + {registration.phone ? ( + {registration.phone} + ) : ( + - + )} + + {getStatusBadge(registration.status)} + +
+ {getPaymentBadge(registration.payment_status)} + {registration.payment_amount && ( + + ₹{registration.payment_amount / 100} + + )} +
+
+ +
+ + {new Date(registration.created_at).toLocaleDateString()} +
+
+ + + +
+ ))} +
+
+
+ )} +
+
+ + ) +} diff --git a/app/dashboard/company/[slug]/events/page.tsx b/app/dashboard/company/[slug]/events/page.tsx index 35b27c0f..8240e031 100644 --- a/app/dashboard/company/[slug]/events/page.tsx +++ b/app/dashboard/company/[slug]/events/page.tsx @@ -331,7 +331,18 @@ export default function CompanyEventsPage() { {event.views || 0} - {event.registered || 0} + + {event.registered && event.registered > 0 ? ( + + {event.registered} + + ) : ( + 0 + )} + {canManageEvents ? (