From edbaf555c27f4354dea5b09d0d8f83815788e8ed Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 19 Nov 2025 09:49:25 +0530 Subject: [PATCH] feat: Implement approved event count for companies and update event status badges to reflect approval status. --- app/api/companies/[slug]/route.ts | 18 ++++++++++++-- app/dashboard/company/events/page.tsx | 31 +++++++++++++++++-------- components/companies/CompanyCard.tsx | 10 ++++---- components/companies/CompanyProfile.tsx | 28 +++++++++++----------- lib/services/company-service.ts | 18 +++++++++++++- types/company.ts | 1 + 6 files changed, 74 insertions(+), 32 deletions(-) diff --git a/app/api/companies/[slug]/route.ts b/app/api/companies/[slug]/route.ts index 2e459c5f..a8c5a38d 100644 --- a/app/api/companies/[slug]/route.ts +++ b/app/api/companies/[slug]/route.ts @@ -71,10 +71,24 @@ export async function GET( } } + // Get count of approved events for this company + const supabase = await createClient() + const { count: approvedCount } = await supabase + .from('events') + .select('*', { count: 'exact', head: true }) + .eq('company_id', company.id) + .eq('approval_status', 'approved') + + // Add approved_events_count to company object + const companyWithApprovedCount = { + ...company, + approved_events_count: approvedCount || 0, + } + // Cache the result - await UnifiedCache.set(cacheKey, { company }, 'API_STANDARD') + await UnifiedCache.set(cacheKey, { company: companyWithApprovedCount }, 'API_STANDARD') - return UnifiedCache.createResponse({ company }, 'API_STANDARD') + return UnifiedCache.createResponse({ company: companyWithApprovedCount }, 'API_STANDARD') } catch (error) { console.error('Error in GET /api/companies/[slug]:', error) diff --git a/app/dashboard/company/events/page.tsx b/app/dashboard/company/events/page.tsx index e46252cf..36d5fc58 100644 --- a/app/dashboard/company/events/page.tsx +++ b/app/dashboard/company/events/page.tsx @@ -37,7 +37,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') } @@ -66,7 +66,7 @@ export default function CompanyEventsPage() { const handleDeleteEvent = async (eventSlug: string) => { try { setDeletingEventSlug(eventSlug) - + const response = await fetch(`/api/events/${eventSlug}`, { method: 'DELETE', }) @@ -76,7 +76,7 @@ export default function CompanyEventsPage() { } toast.success('Event deleted successfully') - + // Refresh the events list await fetchEvents() } catch (error) { @@ -129,11 +129,22 @@ export default function CompanyEventsPage() { } } - const getStatusBadge = (status: string) => { - switch (status) { - case 'live': - case 'published': + const getStatusBadge = (status: string, approvalStatus: string) => { + // Only show "Live" if the event is published AND approved + if ((status === 'live' || status === 'published')) { + if (approvalStatus === 'approved') { return Live + } else if (approvalStatus === 'pending') { + return Pending Review + } else if (approvalStatus === 'rejected') { + return Rejected + } else if (approvalStatus === 'changes_requested') { + return Changes Requested + } + } + + // For other statuses, use the original logic + switch (status) { case 'draft': return Draft case 'cancelled': @@ -289,7 +300,7 @@ export default function CompanyEventsPage() { {event.category} - {getStatusBadge(event.status)} + {getStatusBadge(event.status, event.approval_status)} {getApprovalBadge(event.approval_status)}
@@ -314,8 +325,8 @@ export default function CompanyEventsPage() { )} -