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() { )} - diff --git a/components/companies/CompanyCard.tsx b/components/companies/CompanyCard.tsx index b187a645..675f1a45 100644 --- a/components/companies/CompanyCard.tsx +++ b/components/companies/CompanyCard.tsx @@ -14,11 +14,11 @@ interface CompanyCardProps { className?: string } -export function CompanyCard({ - company, - showStats = true, +export function CompanyCard({ + company, + showStats = true, showVerificationBadge = true, - className + className }: CompanyCardProps) { return ( @@ -81,7 +81,7 @@ export function CompanyCard({ - {company.total_events} events + {company.approved_events_count ?? company.total_events ?? 0} events diff --git a/components/companies/CompanyProfile.tsx b/components/companies/CompanyProfile.tsx index 77bb653a..6034f094 100644 --- a/components/companies/CompanyProfile.tsx +++ b/components/companies/CompanyProfile.tsx @@ -28,7 +28,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP {/* Banner and Logo Section */} {/* Banner */} - - + {/* Logo */} @@ -51,10 +51,10 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP {company.name} - {company.legal_name && company.legal_name !== company.name && ( @@ -120,7 +120,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP - {company.total_events || 0} + {company.approved_events_count ?? company.total_events ?? 0} Events Hosted @@ -151,7 +151,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP Website - Email - @@ -183,7 +183,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP Phone - @@ -230,7 +230,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP {company.socials.linkedin && ( - - - - { + const { count: approvedCount } = await supabase + .from('events') + .select('*', { count: 'exact', head: true }) + .eq('company_id', company.id) + .eq('approval_status', 'approved') + + return { + ...company, + approved_events_count: approvedCount || 0, + } + }) + ) + const total = count || 0 const hasMore = offset + limit < total const result = { - companies: (companies || []) as Company[], + companies: companiesWithApprovedCount as Company[], total, hasMore, } diff --git a/types/company.ts b/types/company.ts index 8e6f6665..c60ae63f 100644 --- a/types/company.ts +++ b/types/company.ts @@ -43,6 +43,7 @@ export interface Company { total_hackathons: number total_participants: number total_registrations: number + approved_events_count?: number // Count of approved events only (for public display) } export interface CompanyAddress {
- {company.total_events || 0} + {company.approved_events_count ?? company.total_events ?? 0}
Events Hosted
Website
Email
Phone