'use client'; import { buttonVariants } from '@components'; import { cn } from '@utils'; import { useEffect, useState } from 'react'; import { HiOutlineCode, HiOutlineTrophy } from 'react-icons/hi'; import { motion } from 'framer-motion'; interface TeamItem { id: string; name: string; description: string; city: string; logo: string | null; banner: string | null; } interface WinnerItem { id: string; team_id: string; team_name: string; rank: number; prize: string | null; } export default function HackathonsPage() { const [teams, setTeams] = useState([]); const [winners, setWinners] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { Promise.all([ fetch('https://api.imphnen.dev/v1/hackathon/teams/browse?per_page=20') .then((r) => r.json()) .then((j) => j.data?.data || []) .catch(() => []), fetch('https://api.imphnen.dev/v1/hackathon/winners') .then((r) => r.json()) .then((j) => j.data || []) .catch(() => []), ]).then(([t, w]) => { setTeams(t); setWinners(w); setLoading(false); }); }, []); const getWinnerRank = (teamId: string) => { const w = winners.find((x) => x.team_id === teamId); return w ? w.rank : null; }; if (loading) { return (
); } if (teams.length === 0) { return (

No hackathon teams yet.

Join Hackathon
); } return (

IMPHNEN Hackathon

Tim-tim yang berpartisipasi dalam hackathon IMPHNEN

{winners.length > 0 && (

Pemenang

{winners.sort((a, b) => a.rank - b.rank).map((w) => (
{w.rank === 1 ? '🥇' : w.rank === 2 ? '🥈' : '🥉'}

{w.team_name}

Juara {w.rank}

{w.prize &&

{w.prize}

}
))}
)}

Semua Tim

{teams.map((team, idx) => { const rank = getWinnerRank(team.id); return ( {team.banner ? (
{team.name}
) : (
)}

{team.name}

{rank && ( Juara {rank} )}
{team.city && (

{team.city}

)} {team.description && (

{team.description}

)} Lihat Tim
); })}
); }