Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
f4dcdc0
fix: modify api.ts
Benjtalkshow Oct 14, 2025
b90d4ed
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Oct 16, 2025
9ea81a5
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Oct 16, 2025
5be269f
fix: remove google auth buttom
Benjtalkshow Oct 16, 2025
490dcb2
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Oct 20, 2025
842fd48
fix: fixes responsive fixes on organization
Benjtalkshow Oct 20, 2025
596a7f8
fix: minor fixes
Benjtalkshow Nov 6, 2025
96fee24
fix: minor fixes
Benjtalkshow Nov 6, 2025
9dfb149
fix: modify create organization
Benjtalkshow Nov 7, 2025
a194d90
fix: modify create organization
Benjtalkshow Nov 7, 2025
b2ceee0
fix: fix organization permission
Benjtalkshow Nov 8, 2025
9ea97d1
fix: merge into main
Benjtalkshow Nov 8, 2025
adb4629
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 8, 2025
0c11420
fix: merge into main
Benjtalkshow Nov 8, 2025
1f5ec24
feat: hackathon overview page
Benjtalkshow Nov 11, 2025
bca1ef6
feat: hackathon overview page
Benjtalkshow Nov 11, 2025
9202b4f
feat: implement participant overview
Benjtalkshow Nov 12, 2025
096f265
feat: implement participant overview
Benjtalkshow Nov 12, 2025
b3478d0
feat: implement resources tab
Benjtalkshow Nov 12, 2025
e83a0be
feat: implement the submission tab
Benjtalkshow Nov 12, 2025
398be9b
feat: implement comment tab
Benjtalkshow Nov 12, 2025
de546b1
fix: implement provider for hackathon
Benjtalkshow Nov 14, 2025
0fd2690
fix: implement provider for hackathon
Benjtalkshow Nov 14, 2025
0d7417f
fix: minor fixes
Benjtalkshow Nov 15, 2025
4d3efee
fix: merge branch 'main' of https://github.com/Benjtalkshow/boundless…
Benjtalkshow Nov 15, 2025
83893e4
fix: hackathon banner
Benjtalkshow Nov 15, 2025
8013d62
fix: hackathon banner
Benjtalkshow Nov 15, 2025
3fb1323
fix: fix hackthon conflict
Benjtalkshow Nov 15, 2025
b7fc94f
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 15, 2025
0594ac8
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 15, 2025
7e08bc1
fix: fix organization page
Benjtalkshow Nov 15, 2025
22c12c1
fix: fix organization page
Benjtalkshow Nov 16, 2025
08e5be5
fix: fix organization page
Benjtalkshow Nov 16, 2025
8e6bded
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 16, 2025
5e6c9e6
fix: use transform
Benjtalkshow Nov 17, 2025
9135f2e
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 17, 2025
c2409f4
fix: add tagline
Benjtalkshow Nov 18, 2025
b08579a
fix: add tagline
Benjtalkshow Nov 18, 2025
4b8ef58
fix: fix conflict
Benjtalkshow Nov 18, 2025
0ee756e
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 19, 2025
ab0384d
fix: minor fixes
Benjtalkshow Nov 20, 2025
91b5c18
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 20, 2025
67c9fee
fix: minor fixes
Benjtalkshow Nov 21, 2025
9b2029b
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 21, 2025
1fca425
fix: fix timeline and prizes
Benjtalkshow Nov 23, 2025
3c057a0
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 23, 2025
a75f5ee
fix: correct timeline events
Benjtalkshow Nov 26, 2025
da0d27f
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 26, 2025
3a0c19b
fix: implement registration deadline policy
Benjtalkshow Nov 27, 2025
c616182
fix: implement registration deadline policy
Benjtalkshow Nov 27, 2025
9a98077
fix: implement registration deadline policy
Benjtalkshow Nov 27, 2025
3ac17f8
Merge branch 'main' of https://github.com/Benjtalkshow/boundless into…
Benjtalkshow Nov 28, 2025
386a338
feat: implement leave hackathon
Benjtalkshow Nov 28, 2025
f4ed466
feat: implement leave hackathon
Benjtalkshow Nov 28, 2025
12a1705
feat: implement leave hackathon
Benjtalkshow Nov 28, 2025
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
75 changes: 62 additions & 13 deletions app/(landing)/hackathons/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use client';

import { useState, useEffect, useMemo } from 'react';
import { useState, useEffect, useMemo, useCallback } from 'react';
import { useRouter, useSearchParams, useParams } from 'next/navigation';
import { useHackathonData } from '@/lib/providers/hackathonProvider';
import { useRegisterHackathon } from '@/hooks/hackathon/use-register-hackathon';
import { useLeaveHackathon } from '@/hooks/hackathon/use-leave-hackathon';
import { RegisterHackathonModal } from '@/components/hackathons/overview/RegisterHackathonModal';

import { HackathonBanner } from '@/components/hackathons/hackathonBanner';
Expand All @@ -16,6 +17,9 @@ import { HackathonDiscussions } from '@/components/hackathons/discussion/comment
import { TeamFormationTab } from '@/components/hackathons/team-formation/TeamFormationTab';
import LoadingScreen from '@/components/landing-page/project/CreateProjectModal/LoadingScreen';
import { useTimelineEvents } from '@/hooks/hackathon/use-timeline-events';
import { toast } from 'sonner';
import { Participant } from '@/lib/api/hackathons';
// import { HackathonResources } from '@/components/hackathons/resources/resources';

export default function HackathonPage() {
const router = useRouter();
Expand All @@ -28,14 +32,16 @@ export default function HackathonPage() {
submissions,
loading,
setCurrentHackathon,
refreshCurrentHackathon,
} = useHackathonData();

const timeline_Events = useTimelineEvents(currentHackathon, {
includeEndDate: false,
dateFormat: { month: 'short', day: 'numeric', year: 'numeric' },
});

const hackathonTabs = useMemo(() => {
const hasParticipants = participants.length > 0;
// const hasSubmissions = submissions.filter(p => p.status === 'Approved').length > 0;

const tabs = [
{ id: 'overview', label: 'Overview' },
Expand Down Expand Up @@ -81,19 +87,37 @@ export default function HackathonPage() {
const [activeTab, setActiveTab] = useState('overview');
const [showRegisterModal, setShowRegisterModal] = useState(false);

// Registration logic
const { isRegistered, hasSubmitted, checkStatus } = useRegisterHackathon({
// Function to refresh all hackathon data
const refreshHackathonData = useCallback(async () => {
if (hackathonId && refreshCurrentHackathon) {
await refreshCurrentHackathon();
}
}, [hackathonId, refreshCurrentHackathon]);

// Registration logic - use the updated hook with setters
const {
isRegistered,
hasSubmitted,
checkStatus,
// isChecking,
setIsRegistered,
setParticipant,
} = useRegisterHackathon({
hackathonSlugOrId: hackathonId,
organizationId: undefined, // organizationId not available in currentHackathon type
organizationId: undefined,
autoCheck: !!hackathonId,
});

// Leave hackathon logic
const { isLeaving, leave: leaveHackathon } = useLeaveHackathon({
hackathonSlugOrId: hackathonId,
organizationId: undefined,
});

const isEnded = useMemo(() => {
if (!currentHackathon?.deadline) return false;

const deadline = new Date(currentHackathon.deadline);
const now = new Date();

return now > deadline;
}, [currentHackathon?.deadline]);

Expand All @@ -111,8 +135,33 @@ export default function HackathonPage() {
setShowRegisterModal(true);
};

const handleRegisterSuccess = () => {
checkStatus();
const handleLeaveClick = async () => {
try {
setIsRegistered(false);
setParticipant(null);

await leaveHackathon();

refreshHackathonData();

router.push('?tab=overview');
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : 'Failed to leave hackathon';
toast.error(errorMessage);
setIsRegistered(true);
checkStatus();
}
};

const handleRegisterSuccess = async (participantData: Participant) => {
// IMMEDIATELY update state with the returned participant data
setIsRegistered(true);
setParticipant(participantData);

// Refresh hackathon data in background (participants count)
await refreshHackathonData();

router.push('?tab=submission');
};

Expand Down Expand Up @@ -151,6 +200,7 @@ export default function HackathonPage() {
if (loading) {
return <LoadingScreen />;
}

if (!currentHackathon) {
return (
<div className='flex min-h-screen items-center justify-center'>
Expand Down Expand Up @@ -187,6 +237,8 @@ export default function HackathonPage() {
registrationDeadline={currentHackathon.registrationDeadline}
isTeamFormationEnabled={isTeamFormationEnabled}
onJoinClick={handleJoinClick}
onLeaveClick={handleLeaveClick}
isLeaving={isLeaving}
onSubmitClick={handleSubmitClick}
onViewSubmissionClick={handleViewSubmissionClick}
onFindTeamClick={handleFindTeamClick}
Expand All @@ -199,7 +251,7 @@ export default function HackathonPage() {
onOpenChange={setShowRegisterModal}
hackathonSlugOrId={hackathonId}
organizationId={undefined}
onSuccess={handleRegisterSuccess}
onSuccess={handleRegisterSuccess} // Now passes participant data
participantType={
(currentHackathon?.participantType as
| 'team'
Expand Down Expand Up @@ -232,9 +284,6 @@ export default function HackathonPage() {
{activeTab === 'participants' && participants.length > 0 && (
<HackathonParticipants />
)}
{/* {activeTab === 'resources' && (
<HackathonResources hackathonSlugOrId={hackathonId} />
)} */}

{activeTab === 'submission' && (
<SubmissionTab
Expand Down
15 changes: 11 additions & 4 deletions components/hackathons/hackathonBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ interface HackathonBannerProps {
onSubmitClick?: () => void;
onViewSubmissionClick?: () => void;
onFindTeamClick?: () => void;
onLeaveClick?: () => void;
isLeaving?: boolean;
}

interface TimeRemaining {
Expand Down Expand Up @@ -125,10 +127,12 @@ export function HackathonBanner({
isTeamFormationEnabled = false,
registrationDeadlinePolicy,
registrationDeadline,
isLeaving,
onJoinClick,
onSubmitClick,
onViewSubmissionClick,
onFindTeamClick,
onLeaveClick,
}: HackathonBannerProps) {
const [timeRemaining, setTimeRemaining] = useState<TimeRemaining>({
days: 0,
Expand Down Expand Up @@ -381,11 +385,14 @@ export function HackathonBanner({
if (isRegistered) {
return (
<Button
onClick={onJoinClick}
variant='outline'
className='border-red-500/50 text-red-400 hover:bg-red-500/20'
onClick={onLeaveClick}
disabled={isLeaving}
className='border border-red-500/40 bg-red-500 font-semibold text-white hover:bg-red-500/50 hover:text-white'
variant='ghost'
>
Leave Hackathon
<Calendar className='mr-2 h-4 w-4 text-white' />
{isLeaving ? 'Leaving...' : 'Leave Hackathon'}
<ArrowRight className='ml-2 h-4 w-4 text-red-400' />
</Button>
);
}
Expand Down
8 changes: 5 additions & 3 deletions components/hackathons/overview/RegisterHackathonModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
hackathonSlugOrId: string;
organizationId?: string;
participantType: 'individual' | 'team' | 'team_or_individual';
onSuccess?: () => void;
onSuccess?: (participantData?: any) => void;

Check warning on line 58 in components/hackathons/overview/RegisterHackathonModal.tsx

View workflow job for this annotation

GitHub Actions / Code Quality & Linting

Unexpected any. Specify a different type
}

export function RegisterHackathonModal({
Expand Down Expand Up @@ -107,7 +107,7 @@

const onSubmit = async (data: RegisterFormData) => {
try {
await registerForHackathon({
const participantData = await registerForHackathon({
participationType: data.participationType,
teamName: data.participationType === 'team' ? data.teamName : undefined,
teamMembers:
Expand All @@ -119,7 +119,9 @@
form.reset();
setTeamMembers([]);
setTeamMemberEmail('');
onSuccess?.();

// Pass the participant data to onSuccess
onSuccess?.(participantData);
} catch {
// Error handled in hook
}
Expand Down
2 changes: 1 addition & 1 deletion components/organization/OrganizationContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export default function OrganizationContent() {
</>
) : (
<div className='flex min-h-[60vh] items-center justify-center'>
<div className='w-full max-w-2xl text-center'>
<div className='mt-10 w-full max-w-2xl text-center'>
{/* Decorative background */}
<div className='relative mx-auto mb-8 h-48 w-48'>
<div className='from-primary/20 absolute inset-0 animate-pulse rounded-full bg-gradient-to-br to-purple-500/20 blur-3xl'></div>
Expand Down
60 changes: 60 additions & 0 deletions hooks/hackathon/use-leave-hackathon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use client';

import { useState, useCallback } from 'react';
import { leaveHackathon } from '@/lib/api/hackathons';
import { useAuthStatus } from '@/hooks/use-auth';
import { toast } from 'sonner';

interface UseLeaveHackathonOptions {
hackathonSlugOrId: string;
organizationId?: string;
}

export function useLeaveHackathon({
hackathonSlugOrId,
organizationId,
}: UseLeaveHackathonOptions) {
const { isAuthenticated } = useAuthStatus();
const [isLeaving, setIsLeaving] = useState(false);
const [error, setError] = useState<string | null>(null);

const leave = useCallback(async () => {
if (!isAuthenticated) {
toast.error('Please sign in to leave hackathons');
throw new Error('Authentication required');
}

if (!hackathonSlugOrId) {
toast.error('Hackathon ID is required');
throw new Error('Hackathon ID is required');
}

setIsLeaving(true);
setError(null);

try {
const response = await leaveHackathon(hackathonSlugOrId, organizationId);

if (response.success) {
toast.success('Successfully left the hackathon');
return response.data;
} else {
throw new Error(response.message || 'Failed to leave hackathon');
}
} catch (err) {
const errorMessage =
err instanceof Error ? err.message : 'Failed to leave hackathon';
setError(errorMessage);
toast.error(errorMessage);
throw err;
} finally {
setIsLeaving(false);
}
}, [hackathonSlugOrId, organizationId, isAuthenticated]);

return {
isLeaving,
error,
leave,
};
}
10 changes: 10 additions & 0 deletions hooks/hackathon/use-register-hackathon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export function useRegisterHackathon({
const [isRegistering, setIsRegistering] = useState(false);
const [isChecking, setIsChecking] = useState(false);
const [error, setError] = useState<string | null>(null);
const [hasCheckedInitially, setHasCheckedInitially] = useState(false);

const checkStatus = useCallback(async () => {
if (!isAuthenticated || !hackathonSlugOrId) {
setIsRegistered(false);
setParticipant(null);
setHasCheckedInitially(true);
return;
}

Expand All @@ -51,6 +53,7 @@ export function useRegisterHackathon({
setIsRegistered(false);
setParticipant(null);
}
setHasCheckedInitially(true);
} catch (err) {
const errorMessage =
err instanceof Error
Expand All @@ -59,6 +62,7 @@ export function useRegisterHackathon({
setError(errorMessage);
setIsRegistered(false);
setParticipant(null);
setHasCheckedInitially(true);
} finally {
setIsChecking(false);
}
Expand Down Expand Up @@ -87,6 +91,7 @@ export function useRegisterHackathon({
);

if (response.success && response.data) {
// IMMEDIATELY update state - don't wait for checkStatus
setIsRegistered(true);
setParticipant(response.data);
toast.success('Successfully registered for hackathon!');
Expand Down Expand Up @@ -116,6 +121,7 @@ export function useRegisterHackathon({
} else if (!isAuthenticated) {
setIsRegistered(false);
setParticipant(null);
setHasCheckedInitially(true);
}
}, [autoCheck, isAuthenticated, hackathonSlugOrId, checkStatus]);

Expand All @@ -127,6 +133,10 @@ export function useRegisterHackathon({
error,
register,
checkStatus,
hasCheckedInitially,
// Expose setters for immediate updates
setIsRegistered,
setParticipant,
hasSubmitted: participant?.submission?.status === 'submitted',
};
}
Loading
Loading