Skip to content

Commit 328957b

Browse files
authored
Merge pull request #345 from codeunia-dev/fix/event
feat: Implement approved event count for companies and update event
2 parents 23c3e1d + edbaf55 commit 328957b

File tree

6 files changed

+74
-32
lines changed

6 files changed

+74
-32
lines changed

app/api/companies/[slug]/route.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,24 @@ export async function GET(
7171
}
7272
}
7373

74+
// Get count of approved events for this company
75+
const supabase = await createClient()
76+
const { count: approvedCount } = await supabase
77+
.from('events')
78+
.select('*', { count: 'exact', head: true })
79+
.eq('company_id', company.id)
80+
.eq('approval_status', 'approved')
81+
82+
// Add approved_events_count to company object
83+
const companyWithApprovedCount = {
84+
...company,
85+
approved_events_count: approvedCount || 0,
86+
}
87+
7488
// Cache the result
75-
await UnifiedCache.set(cacheKey, { company }, 'API_STANDARD')
89+
await UnifiedCache.set(cacheKey, { company: companyWithApprovedCount }, 'API_STANDARD')
7690

77-
return UnifiedCache.createResponse({ company }, 'API_STANDARD')
91+
return UnifiedCache.createResponse({ company: companyWithApprovedCount }, 'API_STANDARD')
7892
} catch (error) {
7993
console.error('Error in GET /api/companies/[slug]:', error)
8094

app/dashboard/company/events/page.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function CompanyEventsPage() {
3737
setLoading(true)
3838
// Fetch all events (not just approved) for company members
3939
const response = await fetch(`/api/companies/${currentCompany.slug}/events?status=all&limit=100`)
40-
40+
4141
if (!response.ok) {
4242
throw new Error('Failed to fetch events')
4343
}
@@ -66,7 +66,7 @@ export default function CompanyEventsPage() {
6666
const handleDeleteEvent = async (eventSlug: string) => {
6767
try {
6868
setDeletingEventSlug(eventSlug)
69-
69+
7070
const response = await fetch(`/api/events/${eventSlug}`, {
7171
method: 'DELETE',
7272
})
@@ -76,7 +76,7 @@ export default function CompanyEventsPage() {
7676
}
7777

7878
toast.success('Event deleted successfully')
79-
79+
8080
// Refresh the events list
8181
await fetchEvents()
8282
} catch (error) {
@@ -129,11 +129,22 @@ export default function CompanyEventsPage() {
129129
}
130130
}
131131

132-
const getStatusBadge = (status: string) => {
133-
switch (status) {
134-
case 'live':
135-
case 'published':
132+
const getStatusBadge = (status: string, approvalStatus: string) => {
133+
// Only show "Live" if the event is published AND approved
134+
if ((status === 'live' || status === 'published')) {
135+
if (approvalStatus === 'approved') {
136136
return <Badge className="bg-blue-500/10 text-blue-600 border-blue-500/20">Live</Badge>
137+
} else if (approvalStatus === 'pending') {
138+
return <Badge className="bg-yellow-500/10 text-yellow-600 border-yellow-500/20">Pending Review</Badge>
139+
} else if (approvalStatus === 'rejected') {
140+
return <Badge className="bg-red-500/10 text-red-600 border-red-500/20">Rejected</Badge>
141+
} else if (approvalStatus === 'changes_requested') {
142+
return <Badge className="bg-orange-500/10 text-orange-600 border-orange-500/20">Changes Requested</Badge>
143+
}
144+
}
145+
146+
// For other statuses, use the original logic
147+
switch (status) {
137148
case 'draft':
138149
return <Badge variant="outline">Draft</Badge>
139150
case 'cancelled':
@@ -289,7 +300,7 @@ export default function CompanyEventsPage() {
289300
<TableCell>
290301
<Badge variant="outline">{event.category}</Badge>
291302
</TableCell>
292-
<TableCell>{getStatusBadge(event.status)}</TableCell>
303+
<TableCell>{getStatusBadge(event.status, event.approval_status)}</TableCell>
293304
<TableCell>{getApprovalBadge(event.approval_status)}</TableCell>
294305
<TableCell>
295306
<div className="flex items-center gap-1">
@@ -314,8 +325,8 @@ export default function CompanyEventsPage() {
314325
)}
315326
<AlertDialog>
316327
<AlertDialogTrigger asChild>
317-
<Button
318-
variant="outline"
328+
<Button
329+
variant="outline"
319330
size="sm"
320331
disabled={deletingEventSlug === event.slug}
321332
>

components/companies/CompanyCard.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ interface CompanyCardProps {
1414
className?: string
1515
}
1616

17-
export function CompanyCard({
18-
company,
19-
showStats = true,
17+
export function CompanyCard({
18+
company,
19+
showStats = true,
2020
showVerificationBadge = true,
21-
className
21+
className
2222
}: CompanyCardProps) {
2323
return (
2424
<Link href={`/companies/${company.slug}`}>
@@ -81,7 +81,7 @@ export function CompanyCard({
8181
<div className="flex items-center justify-between w-full text-xs text-muted-foreground">
8282
<div className="flex items-center gap-1">
8383
<Calendar className="h-3.5 w-3.5" />
84-
<span>{company.total_events} events</span>
84+
<span>{company.approved_events_count ?? company.total_events ?? 0} events</span>
8585
</div>
8686
<div className="flex items-center gap-1">
8787
<Users className="h-3.5 w-3.5" />

components/companies/CompanyProfile.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
2828
{/* Banner and Logo Section */}
2929
<Card className="overflow-hidden">
3030
{/* Banner */}
31-
<div
31+
<div
3232
className="h-56 sm:h-64 bg-gradient-to-r from-primary/20 via-primary/10 to-primary/20"
3333
style={company.banner_url ? {
3434
backgroundImage: `url(${company.banner_url})`,
3535
backgroundSize: 'cover',
3636
backgroundPosition: 'center',
3737
} : undefined}
3838
/>
39-
39+
4040
<CardHeader className="relative -mt-20 pb-4">
4141
<div className="flex flex-col sm:flex-row items-start sm:items-end gap-4">
4242
{/* Logo */}
@@ -51,10 +51,10 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
5151
<div className="flex-1 space-y-2">
5252
<div className="flex flex-wrap items-center gap-3">
5353
<CardTitle className="text-3xl">{company.name}</CardTitle>
54-
<VerificationBadge
55-
status={company.verification_status}
56-
size="lg"
57-
showLabel
54+
<VerificationBadge
55+
status={company.verification_status}
56+
size="lg"
57+
showLabel
5858
/>
5959
</div>
6060
{company.legal_name && company.legal_name !== company.name && (
@@ -120,7 +120,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
120120
<div className="grid grid-cols-3 gap-4 text-center">
121121
<div className="space-y-1">
122122
<p className="text-2xl font-bold text-primary">
123-
{company.total_events || 0}
123+
{company.approved_events_count ?? company.total_events ?? 0}
124124
</p>
125125
<p className="text-xs text-muted-foreground">Events Hosted</p>
126126
</div>
@@ -151,7 +151,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
151151
<Globe className="h-4 w-4 mt-0.5 text-muted-foreground" />
152152
<div className="flex-1 min-w-0">
153153
<p className="text-xs text-muted-foreground mb-1">Website</p>
154-
<a
154+
<a
155155
href={company.website}
156156
target="_blank"
157157
rel="noopener noreferrer"
@@ -168,7 +168,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
168168
<Mail className="h-4 w-4 mt-0.5 text-muted-foreground" />
169169
<div className="flex-1 min-w-0">
170170
<p className="text-xs text-muted-foreground mb-1">Email</p>
171-
<a
171+
<a
172172
href={`mailto:${company.email}`}
173173
className="text-sm text-primary hover:underline break-all"
174174
>
@@ -183,7 +183,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
183183
<Phone className="h-4 w-4 mt-0.5 text-muted-foreground" />
184184
<div className="flex-1 min-w-0">
185185
<p className="text-xs text-muted-foreground mb-1">Phone</p>
186-
<a
186+
<a
187187
href={`tel:${company.phone}`}
188188
className="text-sm text-primary hover:underline"
189189
>
@@ -230,7 +230,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
230230
<div className="flex flex-wrap gap-2">
231231
{company.socials.linkedin && (
232232
<Button variant="outline" size="sm" asChild>
233-
<a
233+
<a
234234
href={company.socials.linkedin}
235235
target="_blank"
236236
rel="noopener noreferrer"
@@ -241,7 +241,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
241241
)}
242242
{company.socials.twitter && (
243243
<Button variant="outline" size="sm" asChild>
244-
<a
244+
<a
245245
href={company.socials.twitter}
246246
target="_blank"
247247
rel="noopener noreferrer"
@@ -252,7 +252,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
252252
)}
253253
{company.socials.facebook && (
254254
<Button variant="outline" size="sm" asChild>
255-
<a
255+
<a
256256
href={company.socials.facebook}
257257
target="_blank"
258258
rel="noopener noreferrer"
@@ -263,7 +263,7 @@ export function CompanyProfile({ company, isOwner = false, className }: CompanyP
263263
)}
264264
{company.socials.instagram && (
265265
<Button variant="outline" size="sm" asChild>
266-
<a
266+
<a
267267
href={company.socials.instagram}
268268
target="_blank"
269269
rel="noopener noreferrer"

lib/services/company-service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,27 @@ class CompanyService {
371371
)
372372
}
373373

374+
// For each company, get the count of approved events
375+
const companiesWithApprovedCount = await Promise.all(
376+
(companies || []).map(async (company) => {
377+
const { count: approvedCount } = await supabase
378+
.from('events')
379+
.select('*', { count: 'exact', head: true })
380+
.eq('company_id', company.id)
381+
.eq('approval_status', 'approved')
382+
383+
return {
384+
...company,
385+
approved_events_count: approvedCount || 0,
386+
}
387+
})
388+
)
389+
374390
const total = count || 0
375391
const hasMore = offset + limit < total
376392

377393
const result = {
378-
companies: (companies || []) as Company[],
394+
companies: companiesWithApprovedCount as Company[],
379395
total,
380396
hasMore,
381397
}

types/company.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface Company {
4343
total_hackathons: number
4444
total_participants: number
4545
total_registrations: number
46+
approved_events_count?: number // Count of approved events only (for public display)
4647
}
4748

4849
export interface CompanyAddress {

0 commit comments

Comments
 (0)