|
1 | | -import { useState } from "react"; |
| 1 | +import React, { useEffect, useState } from "react"; |
2 | 2 |
|
3 | | -import { usePings } from "@/hooks/pings"; |
| 3 | +import { GuestSection, SponsorSection } from "@/components/SponsorsGuests"; |
4 | 4 |
|
5 | | -import { Button } from "../components/ui/button"; |
| 5 | +type Partner = { |
| 6 | + name: string; |
| 7 | + logo: string; |
| 8 | + link: string; |
| 9 | +}; |
6 | 10 |
|
7 | | -export default function Home() { |
8 | | - const [clicked, setClicked] = useState(false); |
9 | | - const { data, isLoading } = usePings({ |
10 | | - enabled: clicked, |
11 | | - }); |
| 11 | +// Type definition for guest data |
| 12 | +type Guest = { |
| 13 | + name: string; |
| 14 | + description: string; |
| 15 | + link: string; |
| 16 | + photo?: string; |
| 17 | +}; |
| 18 | + |
| 19 | +const SponsorsAndGuest = () => { |
| 20 | + const [partners, setPartners] = useState<Partner[]>([]); // Holds sponsor data |
| 21 | + const [guests, setGuests] = useState<Guest[]>([]); // Holds guest data |
| 22 | + const [loading, setLoading] = useState(true); // Controls loading state |
| 23 | + |
| 24 | + useEffect(() => { |
| 25 | + // Define an async function to fetch data |
| 26 | + const fetchData = async () => { |
| 27 | + try { |
| 28 | + const [partnerRes, guestRes] = await Promise.all([ |
| 29 | + fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/sponsor/`), |
| 30 | + fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/sponsor/guests/`), |
| 31 | + ]); |
| 32 | + const partnerData = await partnerRes.json(); |
| 33 | + const guestData = await guestRes.json(); |
| 34 | + |
| 35 | + setPartners(partnerData); |
| 36 | + setGuests(guestData); |
| 37 | + } catch (error) { |
| 38 | + console.error("Error fetching data:", error); |
| 39 | + } finally { |
| 40 | + setLoading(false); |
| 41 | + } |
| 42 | + }; |
| 43 | + |
| 44 | + fetchData(); |
| 45 | + }, []); |
12 | 46 |
|
13 | 47 | return ( |
14 | | - <> |
15 | | - <h1 className="title-large text-dark">Title Test</h1> |
16 | | - <Button onClick={() => setClicked(true)}> |
17 | | - {isLoading ? "Loading" : "Ping"} |
18 | | - </Button> |
19 | | - <p> |
20 | | - Response from server: <span>{data as string}</span> |
21 | | - </p> |
22 | | - </> |
| 48 | + <div className="min-h-screen bg-background"> |
| 49 | + {/* Page title */} |
| 50 | + <div className="pt-20 text-center"> |
| 51 | + <h1 className={`font-montserrat text-6xl font-semibold leading-none`}> |
| 52 | + Guests & Sponsors |
| 53 | + </h1> |
| 54 | + </div> |
| 55 | + {/* Special Guests & Sponsors Section */} |
| 56 | + {loading ? ( |
| 57 | + <p className="text-center text-gray-500">Loading...</p> |
| 58 | + ) : ( |
| 59 | + <> |
| 60 | + <GuestSection |
| 61 | + guests={guests.map((guest) => ({ |
| 62 | + name: guest.name, |
| 63 | + description: guest.description, |
| 64 | + link: guest.link, |
| 65 | + image: guest.photo, // mapped to 'image' for component |
| 66 | + }))} |
| 67 | + /> |
| 68 | + <div className="mt-16"> |
| 69 | + <SponsorSection partners={partners} /> |
| 70 | + </div> |
| 71 | + </> |
| 72 | + )} |
| 73 | + </div> |
23 | 74 | ); |
24 | | -} |
| 75 | +}; |
| 76 | + |
| 77 | +export default SponsorsAndGuest; |
0 commit comments