Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app/api/companies/[slug]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
31 changes: 21 additions & 10 deletions app/dashboard/company/events/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down Expand Up @@ -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',
})
Expand All @@ -76,7 +76,7 @@ export default function CompanyEventsPage() {
}

toast.success('Event deleted successfully')

// Refresh the events list
await fetchEvents()
} catch (error) {
Expand Down Expand Up @@ -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 <Badge className="bg-blue-500/10 text-blue-600 border-blue-500/20">Live</Badge>
} else if (approvalStatus === 'pending') {
return <Badge className="bg-yellow-500/10 text-yellow-600 border-yellow-500/20">Pending Review</Badge>
} else if (approvalStatus === 'rejected') {
return <Badge className="bg-red-500/10 text-red-600 border-red-500/20">Rejected</Badge>
} else if (approvalStatus === 'changes_requested') {
return <Badge className="bg-orange-500/10 text-orange-600 border-orange-500/20">Changes Requested</Badge>
}
}

// For other statuses, use the original logic
switch (status) {
case 'draft':
return <Badge variant="outline">Draft</Badge>
case 'cancelled':
Expand Down Expand Up @@ -289,7 +300,7 @@ export default function CompanyEventsPage() {
<TableCell>
<Badge variant="outline">{event.category}</Badge>
</TableCell>
<TableCell>{getStatusBadge(event.status)}</TableCell>
<TableCell>{getStatusBadge(event.status, event.approval_status)}</TableCell>
<TableCell>{getApprovalBadge(event.approval_status)}</TableCell>
<TableCell>
<div className="flex items-center gap-1">
Expand All @@ -314,8 +325,8 @@ export default function CompanyEventsPage() {
)}
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant="outline"
<Button
variant="outline"
size="sm"
disabled={deletingEventSlug === event.slug}
>
Expand Down
10 changes: 5 additions & 5 deletions components/companies/CompanyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Link href={`/companies/${company.slug}`}>
Expand Down Expand Up @@ -81,7 +81,7 @@ export function CompanyCard({
<div className="flex items-center justify-between w-full text-xs text-muted-foreground">
<div className="flex items-center gap-1">
<Calendar className="h-3.5 w-3.5" />
<span>{company.total_events} events</span>
<span>{company.approved_events_count ?? company.total_events ?? 0} events</span>
</div>
<div className="flex items-center gap-1">
<Users className="h-3.5 w-3.5" />
Expand Down
28 changes: 14 additions & 14 deletions components/companies/CompanyProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
{/* Banner and Logo Section */}
<Card className="overflow-hidden">
{/* Banner */}
<div
<div
className="h-56 sm:h-64 bg-gradient-to-r from-primary/20 via-primary/10 to-primary/20"
style={company.banner_url ? {
backgroundImage: `url(${company.banner_url})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
} : undefined}
/>

<CardHeader className="relative -mt-20 pb-4">
<div className="flex flex-col sm:flex-row items-start sm:items-end gap-4">
{/* Logo */}
Expand All @@ -51,10 +51,10 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
<div className="flex-1 space-y-2">
<div className="flex flex-wrap items-center gap-3">
<CardTitle className="text-3xl">{company.name}</CardTitle>
<VerificationBadge
status={company.verification_status}
size="lg"
showLabel
<VerificationBadge
status={company.verification_status}
size="lg"
showLabel
/>
</div>
{company.legal_name && company.legal_name !== company.name && (
Expand Down Expand Up @@ -120,7 +120,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
<div className="grid grid-cols-3 gap-4 text-center">
<div className="space-y-1">
<p className="text-2xl font-bold text-primary">
{company.total_events || 0}
{company.approved_events_count ?? company.total_events ?? 0}
</p>
<p className="text-xs text-muted-foreground">Events Hosted</p>
</div>
Expand Down Expand Up @@ -151,7 +151,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
<Globe className="h-4 w-4 mt-0.5 text-muted-foreground" />
<div className="flex-1 min-w-0">
<p className="text-xs text-muted-foreground mb-1">Website</p>
<a
<a
href={company.website}
target="_blank"
rel="noopener noreferrer"
Expand All @@ -168,7 +168,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
<Mail className="h-4 w-4 mt-0.5 text-muted-foreground" />
<div className="flex-1 min-w-0">
<p className="text-xs text-muted-foreground mb-1">Email</p>
<a
<a
href={`mailto:${company.email}`}
className="text-sm text-primary hover:underline break-all"
>
Expand All @@ -183,7 +183,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
<Phone className="h-4 w-4 mt-0.5 text-muted-foreground" />
<div className="flex-1 min-w-0">
<p className="text-xs text-muted-foreground mb-1">Phone</p>
<a
<a
href={`tel:${company.phone}`}
className="text-sm text-primary hover:underline"
>
Expand Down Expand Up @@ -230,7 +230,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
<div className="flex flex-wrap gap-2">
{company.socials.linkedin && (
<Button variant="outline" size="sm" asChild>
<a
<a
href={company.socials.linkedin}
target="_blank"
rel="noopener noreferrer"
Expand All @@ -241,7 +241,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
)}
{company.socials.twitter && (
<Button variant="outline" size="sm" asChild>
<a
<a
href={company.socials.twitter}
target="_blank"
rel="noopener noreferrer"
Expand All @@ -252,7 +252,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
)}
{company.socials.facebook && (
<Button variant="outline" size="sm" asChild>
<a
<a
href={company.socials.facebook}
target="_blank"
rel="noopener noreferrer"
Expand All @@ -263,7 +263,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
)}
{company.socials.instagram && (
<Button variant="outline" size="sm" asChild>
<a
<a
href={company.socials.instagram}
target="_blank"
rel="noopener noreferrer"
Expand Down
18 changes: 17 additions & 1 deletion lib/services/company-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,27 @@ class CompanyService {
)
}

// For each company, get the count of approved events
const companiesWithApprovedCount = await Promise.all(
(companies || []).map(async (company) => {
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,
}
Expand Down
1 change: 1 addition & 0 deletions types/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading