diff --git a/app/(landing)/hackathons/[slug]/components/header/ActionButtons.tsx b/app/(landing)/hackathons/[slug]/components/header/ActionButtons.tsx index e422e1f6..236d204a 100644 --- a/app/(landing)/hackathons/[slug]/components/header/ActionButtons.tsx +++ b/app/(landing)/hackathons/[slug]/components/header/ActionButtons.tsx @@ -38,7 +38,8 @@ const ActionButtons = () => { const isParticipant = user ? !!hackathon?.isParticipant || (hackathon?.participants || []).some( - (p: Participant) => p.userId === user.id + (p: Participant) => + (p as any).userId === user.id || p.user?.id === user.id ) : false; diff --git a/app/(landing)/hackathons/[slug]/components/tabs/contents/Participants.tsx b/app/(landing)/hackathons/[slug]/components/tabs/contents/Participants.tsx index e935ee23..f82da490 100644 --- a/app/(landing)/hackathons/[slug]/components/tabs/contents/Participants.tsx +++ b/app/(landing)/hackathons/[slug]/components/tabs/contents/Participants.tsx @@ -6,6 +6,7 @@ import { useHackathon, useHackathonParticipants, } from '@/hooks/hackathon/use-hackathon-queries'; +import { useDebounce } from '@/hooks/use-debounce'; import { TabsContent } from '@/components/ui/tabs'; import { ChevronDown, Search, Filter, Loader2 } from 'lucide-react'; import { cn } from '@/lib/utils'; @@ -53,6 +54,12 @@ const Participants = () => { 'all' | 'submitted' | 'in_progress' >('all'); const [skillFilter, setSkillFilter] = useState('all'); + const [participationType, setParticipationType] = useState< + 'all' | 'individual' | 'team' + >('all'); + const [searchQuery, setSearchQuery] = useState(''); + const debouncedSearch = useDebounce(searchQuery, 300); + const [page, setPage] = useState(1); const [accumulatedParticipants, setAccumulatedParticipants] = useState< Participant[] @@ -68,13 +75,15 @@ const Participants = () => { limit, status: statusFilter === 'all' ? undefined : statusFilter, skill: skillFilter === 'all' ? undefined : skillFilter, + type: participationType === 'all' ? undefined : participationType, + search: debouncedSearch || undefined, }); // Reset page and list when filters change React.useEffect(() => { setPage(1); setAccumulatedParticipants([]); - }, [statusFilter, skillFilter]); + }, [statusFilter, skillFilter, participationType, debouncedSearch]); // Accumulate participants as they are fetched React.useEffect(() => { @@ -133,14 +142,28 @@ const Participants = () => { > {/* Header with Count and Filters */}
-
-

Participants

-

- - {totalBuilders.toLocaleString()} - {' '} - builders competing in {hackathon.name} -

+
+
+

Participants

+

+ + {totalBuilders.toLocaleString()} + {' '} + builders competing in {hackathon.name} +

+
+ + {/* Search Bar */} +
+ setSearchQuery(e.target.value)} + className='hover:border-primary/20 focus:border-primary/30 h-10 w-full rounded-xl border border-white/5 bg-[#141517] pr-4 pl-10 text-sm text-white transition-all outline-none placeholder:text-gray-500' + /> + +
@@ -175,6 +198,38 @@ const Participants = () => { + {/* Type Filter */} + + + + + + setParticipationType('all')}> + All Types + + setParticipationType('individual')} + > + Individual + + setParticipationType('team')}> + Team + + + + {/* Status Filter */} @@ -222,7 +277,7 @@ const Participants = () => { key={p.id} name={p.user.profile.name} username={p.user.profile.username} - image={p.user.profile.image} + image={p.user.profile.image || undefined} submitted={!!p.submittedAt} skills={p.user.profile.skills} userId={p.userId ?? p.user?.id} diff --git a/app/(landing)/organizations/[id]/hackathons/[hackathonId]/participants/page.tsx b/app/(landing)/organizations/[id]/hackathons/[hackathonId]/participants/page.tsx index e475a6a9..ce74910f 100644 --- a/app/(landing)/organizations/[id]/hackathons/[hackathonId]/participants/page.tsx +++ b/app/(landing)/organizations/[id]/hackathons/[hackathonId]/participants/page.tsx @@ -228,45 +228,11 @@ const ParticipantsPage: React.FC = () => { } }; - // Frontend-side filtering as per requirement - const filteredParticipants = useMemo(() => { - return participants.filter(participant => { - // Search: filter by name or username - const search = filters.search.toLowerCase(); - const matchesSearch = search - ? (participant.user?.profile?.name || '') - .toLowerCase() - .includes(search) || - (participant.user?.profile?.username || '') - .toLowerCase() - .includes(search) - : true; - - // Status: filter by participant.submission.status - // Filter values are 'submitted', 'not_submitted', etc. - // ParticipantSubmission.status values are 'submitted', 'shortlisted', etc. - const matchesStatus = - filters.status === 'all' - ? true - : filters.status === 'not_submitted' - ? !participant.submission - : participant.submission?.status?.toLowerCase() === - filters.status.toLowerCase(); - - // Type: filter by participant.participationType - const matchesType = - filters.type === 'all' - ? true - : participant.participationType?.toLowerCase() === - filters.type.toLowerCase(); - - return matchesSearch && matchesStatus && matchesType; - }); - }, [participants, filters.search, filters.status, filters.type]); + // Removed redundant frontend-side filtering as backend now handles it. // Mock table instance for DataTablePagination const table = useReactTable({ - data: filteredParticipants, + data: participants, columns: [], // Not used for rendering here getCoreRowModel: getCoreRowModel(), manualPagination: true, @@ -352,7 +318,7 @@ const ParticipantsPage: React.FC = () => {
{view === 'table' ? ( { /> ) : ( { - return allSubmissions.filter(sub => { - const search = filters.search?.toLowerCase() || ''; - const matchesSearch = search - ? (sub.projectName || '').toLowerCase().includes(search) || - (sub.participant?.name || '').toLowerCase().includes(search) || - (sub.participant?.username || '').toLowerCase().includes(search) - : true; - - const matchesStatus = !filters.status || sub.status === filters.status; - - const matchesType = - !filters.type || sub.participationType === filters.type; - - return matchesSearch && matchesStatus && matchesType; - }); - }, [allSubmissions, filters.search, filters.status, filters.type]); - const table = useReactTable({ - data: filteredSubmissions, + data: allSubmissions, columns: [], getCoreRowModel: getCoreRowModel(), manualPagination: true, @@ -162,7 +143,7 @@ export default function SubmissionsPage() { ) : (
= ({
- + {userName.charAt(0).toUpperCase()}

{userName}

diff --git a/components/organization/cards/ReviewSubmissionModal/SubmissionVotesTab.tsx b/components/organization/cards/ReviewSubmissionModal/SubmissionVotesTab.tsx index fd67bbe8..b1105c1f 100644 --- a/components/organization/cards/ReviewSubmissionModal/SubmissionVotesTab.tsx +++ b/components/organization/cards/ReviewSubmissionModal/SubmissionVotesTab.tsx @@ -11,7 +11,7 @@ interface Voter { id: string; name: string; username: string; - avatar?: string; + avatar?: string | null; votedAt?: string; voteType?: 'positive' | 'negative'; } @@ -42,7 +42,10 @@ export const SubmissionVotesTab: React.FC = ({
- + {voter.name.charAt(0).toUpperCase()} diff --git a/components/organization/cards/ReviewSubmissionModal/TeamSection.tsx b/components/organization/cards/ReviewSubmissionModal/TeamSection.tsx index 627dffb8..99f3d6aa 100644 --- a/components/organization/cards/ReviewSubmissionModal/TeamSection.tsx +++ b/components/organization/cards/ReviewSubmissionModal/TeamSection.tsx @@ -11,7 +11,7 @@ interface TeamMember { id: string; name: string; role: string; - avatar?: string; + avatar?: string | null; username?: string; } @@ -37,7 +37,10 @@ export const TeamSection: React.FC = ({ teamMembers }) => { className='group bg-background-card/20 hover:bg-background-card/40 flex items-center gap-4 rounded-xl border border-gray-900/60 p-4 transition-all hover:border-gray-800' > - + {member.name.charAt(0).toUpperCase()} diff --git a/components/organization/cards/ReviewSubmissionModal/types.ts b/components/organization/cards/ReviewSubmissionModal/types.ts index 76f80aa9..f7e3752e 100644 --- a/components/organization/cards/ReviewSubmissionModal/types.ts +++ b/components/organization/cards/ReviewSubmissionModal/types.ts @@ -2,7 +2,7 @@ export interface TeamMember { id: string; name: string; role: string; - avatar?: string; + avatar?: string | null; username?: string; } @@ -10,7 +10,7 @@ export interface Voter { id: string; name: string; username: string; - avatar?: string; + avatar?: string | null; votedAt?: string; voteType?: 'positive' | 'negative'; } @@ -21,7 +21,7 @@ export interface Comment { author: { name: string; username: string; - avatar?: string; + avatar?: string | null; }; createdAt: string; reactions?: { diff --git a/components/organization/cards/TeamModal.tsx b/components/organization/cards/TeamModal.tsx index 21adea3e..f3524345 100644 --- a/components/organization/cards/TeamModal.tsx +++ b/components/organization/cards/TeamModal.tsx @@ -19,7 +19,7 @@ interface TeamMember { id: string; name: string; role: string; - avatar?: string; + avatar?: string | null; } type ParticipationType = 'team' | 'individual' | 'no-submission'; @@ -168,7 +168,10 @@ export default function TeamModal({ className='group flex cursor-pointer items-center gap-3 rounded-lg p-3 transition-colors hover:bg-gray-900/50' > - + {member.name.charAt(0).toUpperCase()} diff --git a/components/organization/hackathons/ParticipantsTable.tsx b/components/organization/hackathons/ParticipantsTable.tsx index c1e141b8..69591e93 100644 --- a/components/organization/hackathons/ParticipantsTable.tsx +++ b/components/organization/hackathons/ParticipantsTable.tsx @@ -57,7 +57,10 @@ export function ParticipantsTable({ return (
- + {user.profile.name?.substring(0, 2).toUpperCase()} diff --git a/hooks/hackathon/use-hackathon-queries.ts b/hooks/hackathon/use-hackathon-queries.ts index e8972915..bc7589e2 100644 --- a/hooks/hackathon/use-hackathon-queries.ts +++ b/hooks/hackathon/use-hackathon-queries.ts @@ -43,6 +43,8 @@ export interface ParticipantsQueryParams { page?: number; limit?: number; status?: string; + search?: string; + type?: string; skill?: string; } @@ -50,6 +52,7 @@ export interface SubmissionsQueryParams { page?: number; limit?: number; status?: string; + search?: string; sort?: string; } diff --git a/hooks/hackathon/use-organizer-submissions.ts b/hooks/hackathon/use-organizer-submissions.ts index f0b402fd..7030cef8 100644 --- a/hooks/hackathon/use-organizer-submissions.ts +++ b/hooks/hackathon/use-organizer-submissions.ts @@ -76,7 +76,7 @@ export function useOrganizerSubmissions( const currentPage = rawPag?.page || page; const limit = rawPag?.limit || pagination.limit || initialLimit; const total = rawPag?.total || 0; - const totalPages = rawPag?.totalPages || Math.ceil(total / limit) || 1; + const totalPages = Math.ceil(total / limit) || 1; setSubmissions(list); setPagination({ diff --git a/hooks/hackathon/use-register-hackathon.ts b/hooks/hackathon/use-register-hackathon.ts index 4e7cb921..75ddc226 100644 --- a/hooks/hackathon/use-register-hackathon.ts +++ b/hooks/hackathon/use-register-hackathon.ts @@ -122,6 +122,9 @@ export function useRegisterHackathon({ hasCheckedInitially, // Expose setters for immediate updates setParticipant, - hasSubmitted: participant?.submission?.status === 'SUBMITTED', + hasSubmitted: + participant?.submission?.status === 'SUBMITTED' || + participant?.submission?.status === 'SHORTLISTED' || + participant?.submission?.status === 'DISQUALIFIED', }; } diff --git a/hooks/use-hackathons.ts b/hooks/use-hackathons.ts index f6a79a58..f3c6709e 100644 --- a/hooks/use-hackathons.ts +++ b/hooks/use-hackathons.ts @@ -582,8 +582,7 @@ export function useHackathons( const responsePage = pagination?.page || 1; const totalItems = pagination?.total || 0; const itemsPerPage = pagination?.limit || pageSize; - const totalPages = - pagination?.totalPages || Math.ceil(totalItems / itemsPerPage) || 1; + const totalPages = Math.ceil(totalItems / itemsPerPage) || 1; setParticipants(response.data?.participants || []); setParticipantsPagination({ diff --git a/hooks/use-participant-submission.ts b/hooks/use-participant-submission.ts index 37fc420b..930f08d3 100644 --- a/hooks/use-participant-submission.ts +++ b/hooks/use-participant-submission.ts @@ -16,7 +16,7 @@ export interface SubmissionData { id: string; name: string; role: string; - avatar?: string; + avatar?: string | null; username?: string; }>; links?: Array<{ type: string; url: string }>; @@ -24,7 +24,7 @@ export interface SubmissionData { id: string; name: string; username: string; - avatar?: string; + avatar?: string | null; votedAt?: string; voteType: 'positive' | 'negative'; }>; @@ -34,7 +34,7 @@ export interface SubmissionData { author: { name: string; username: string; - avatar?: string; + avatar?: string | null; }; createdAt: string; reactions?: { diff --git a/lib/api/hackathon.ts b/lib/api/hackathon.ts index 2501f4df..e7b77408 100644 --- a/lib/api/hackathon.ts +++ b/lib/api/hackathon.ts @@ -71,13 +71,22 @@ export const getFeaturedHackathons = // Get participants for a hackathon export const getHackathonParticipants = async ( slug: string, - params?: { page?: number; limit?: number; status?: string; skill?: string } + params?: { + page?: number; + limit?: number; + status?: string; + skill?: string; + search?: string; + type?: string; + } ): Promise => { const queryParams = new URLSearchParams(); if (params?.page) queryParams.append('page', params.page.toString()); if (params?.limit) queryParams.append('limit', params.limit.toString()); if (params?.status) queryParams.append('status', params.status); if (params?.skill) queryParams.append('skill', params.skill); + if (params?.search) queryParams.append('search', params.search); + if (params?.type) queryParams.append('type', params.type); const response = await api.get( `/hackathons/${slug}/participants?${queryParams.toString()}` @@ -97,12 +106,19 @@ export const getHackathonAnalytics = async ( // Get submissions for a hackathon export const getHackathonSubmissions = async ( slug: string, - params?: { page?: number; limit?: number; status?: string; sort?: string } + params?: { + page?: number; + limit?: number; + status?: string; + search?: string; + sort?: string; + } ): Promise => { const queryParams = new URLSearchParams(); if (params?.page) queryParams.append('page', params.page.toString()); if (params?.limit) queryParams.append('limit', params.limit.toString()); if (params?.status) queryParams.append('status', params.status); + if (params?.search) queryParams.append('search', params.search); if (params?.sort) queryParams.append('sort', params.sort); const response = await api.get( diff --git a/lib/api/hackathons.ts b/lib/api/hackathons.ts index a105755c..ec935a13 100644 --- a/lib/api/hackathons.ts +++ b/lib/api/hackathons.ts @@ -636,7 +636,7 @@ export interface ParticipantTeamMember { name: string; username: string; role: string; - avatar?: string; + avatar?: string | null; } export interface ParticipantVote { @@ -698,7 +698,7 @@ export interface ParticipantSubmission { id: string; name: string; username: string; - image?: string; + image?: string | null; }; disqualificationReason?: string | null; reviewedBy?: { @@ -772,7 +772,7 @@ export interface Participant { profile: { name: string; username: string; - image?: string; + image?: string | null; }; email: string; }; @@ -2403,7 +2403,7 @@ export interface TeamMember { username: string; name: string; role: string; - image?: string; + image?: string | null; joinedAt: string; } diff --git a/types/hackathon/participant.ts b/types/hackathon/participant.ts index 0346f572..cda60e9f 100644 --- a/types/hackathon/participant.ts +++ b/types/hackathon/participant.ts @@ -26,7 +26,7 @@ export interface ParticipantTeamMember { name: string; username: string; role: string; - avatar?: string; + avatar?: string | null; } export interface ParticipantVote { @@ -38,7 +38,7 @@ export interface ParticipantVote { firstName: string; lastName: string; username: string; - avatar?: string; + avatar?: string | null; }; email: string; }; @@ -55,7 +55,7 @@ export interface ParticipantComment { firstName: string; lastName: string; username: string; - avatar?: string; + avatar?: string | null; }; email: string; }; @@ -89,7 +89,7 @@ export interface ParticipantSubmission { firstName: string; lastName: string; username: string; - avatar?: string; + avatar?: string | null; }; email: string; } | null; @@ -106,7 +106,7 @@ export interface Participant { profile: { name: string; username: string; - image?: string; + image?: string | null; skills?: string[]; }; email: string; @@ -150,7 +150,7 @@ export interface CreateSubmissionRequest { name: string; username?: string; role: string; - avatar?: string; + avatar?: string | null; }>; projectName: string; category: string; @@ -181,7 +181,7 @@ export interface SubmissionCardProps { projectName: string; description: string; submitterName: string; - submitterAvatar?: string; + submitterAvatar?: string | null; category?: string; categories?: string[]; status?: 'Pending' | 'Approved' | 'Rejected';