From e1488115fae01fe1741a579c0034e3fd5c329799 Mon Sep 17 00:00:00 2001 From: Akshay Date: Mon, 24 Nov 2025 13:36:26 +0530 Subject: [PATCH] feat(events,hackathons): Display user registration status on event and hackathon cards - Add registration status check using useMasterRegistrations hook to both events and hackathons pages - Display "Registered" button with CheckCircle icon for users already registered to an activity - Replace "Join Now" button with green-styled "Registered" button when user has active registration - Import CheckCircle icon from lucide-react for visual registration indicator - Add isUserRegistered helper function to check if user is registered for specific activity - Fetch user registrations filtered by activity_type (event/hackathon) on page load - Improve user experience by providing clear visual feedback on registration status --- app/events/page.tsx | 43 ++++++++++---- app/hackathons/page.tsx | 123 ++++++++++++++++++++++++++++------------ 2 files changed, 120 insertions(+), 46 deletions(-) diff --git a/app/events/page.tsx b/app/events/page.tsx index f2262a15..70d513c1 100644 --- a/app/events/page.tsx +++ b/app/events/page.tsx @@ -19,6 +19,8 @@ import { cn } from "@/lib/utils"; import { useEvents } from "@/hooks/useEvents" import { CompanyBadge } from "@/components/companies/CompanyBadge" import type { Company } from "@/types/company" +import { useMasterRegistrations } from "@/hooks/useMasterRegistrations" +import { CheckCircle } from "lucide-react" // Event categories for dropdown const eventCategories = [ @@ -63,6 +65,9 @@ export default function EventsPage() { // const { loading: featuredLoading } = useFeaturedEvents(5) const featuredLoading = false + // Fetch user registrations to check registration status + const { registrations } = useMasterRegistrations({ activity_type: 'event' }) + // Fetch companies for filter useEffect(() => { const fetchCompanies = async () => { @@ -89,6 +94,11 @@ export default function EventsPage() { const events = eventsData?.events || [] const isLoading = eventsLoading || featuredLoading + // Helper function to check if user is registered for an event + const isUserRegistered = (eventId: string | number) => { + return registrations.some(reg => reg.activity_id === String(eventId)) + } + // Debug logging console.log('Events Page Debug:', { eventsLoading, @@ -589,16 +599,29 @@ export default function EventsPage() { {/* Action Button */}
- + {isUserRegistered(event.id) ? ( + + ) : ( + + )}
diff --git a/app/hackathons/page.tsx b/app/hackathons/page.tsx index b366ca8d..25b703ed 100644 --- a/app/hackathons/page.tsx +++ b/app/hackathons/page.tsx @@ -21,6 +21,8 @@ import { cn } from "@/lib/utils"; import { useHackathons, useFeaturedHackathons } from "@/hooks/useHackathons" import { CompanyBadge } from "@/components/companies/CompanyBadge" import type { Company } from "@/types/company" +import { useMasterRegistrations } from "@/hooks/useMasterRegistrations" +import { CheckCircle } from "lucide-react" // Hackathon categories for dropdown const hackathonCategories = [ @@ -72,6 +74,14 @@ export default function HackathonsPage() { const hackathons = hackathonsData?.hackathons || [] const isLoading = hackathonsLoading || featuredLoading + // Fetch user registrations to check registration status + const { registrations } = useMasterRegistrations({ activity_type: 'hackathon' }) + + // Helper function to check if user is registered for a hackathon + const isUserRegistered = (hackathonId: string | number) => { + return registrations.some(reg => reg.activity_id === String(hackathonId)) + } + // Fetch companies for filter useEffect(() => { const fetchCompanies = async () => { @@ -790,33 +800,61 @@ export default function HackathonsPage() { {hackathon.price} - + + Registered + + + ) : ( + + )} @@ -961,16 +999,29 @@ export default function HackathonsPage() { {/* Action Button */}
- + {isUserRegistered(hackathon.id) ? ( + + ) : ( + + )}