"use client"; import { useEffect, useState } from "react"; import { useSession, signOut } from "next-auth/react"; import { useRouter } from "next/navigation"; interface ServerSetting { _id: string; guildId: string; guildName: string; guildIcon: string | null; } export default function AdminPage() { const { data: session } = useSession(); const [serverSettings, setServerSettings] = useState([]); const [loading, setLoading] = useState(true); const router = useRouter(); useEffect(() => { if (!session) return; const fetchServerSettings = async () => { try { const response = await fetch("/api/discord/guilds"); if (!response.ok) { throw new Error("Failed to fetch server settings"); } const data = await response.json(); console.log("Fetched Server Settings:", data); setServerSettings(data); } catch (error) { console.error("Error fetching server settings:", error); } finally { setLoading(false); } }; fetchServerSettings(); }, [session]); if (!session) { return (

Access Denied

Please sign in to access this page.

); } const handleServerClick = (guildId: string) => { router.push(`/admin/manage/${guildId}`); }; return (

Welcome to the Admin Page!

You are signed in as: {session.user?.name}

{loading ? (

Loading server settings...

) : (
{serverSettings.map((setting) => (
handleServerClick(setting.guildId)} className="bg-gray-800 p-4 rounded shadow-md cursor-pointer hover:bg-gray-700 transition duration-200 flex flex-col items-center" > {setting.guildIcon && ( {`${setting.guildName} )}

{setting.guildName}

))}
)}
); }