"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { Location } from "@prisma/client"; export default function AdminDashboard() { const [locations, setLocations] = useState([]); const [loading, setLoading] = useState(true); const fetchLocations = async () => { try { const res = await fetch("/api/admin/locations"); if (res.ok) { const data = await res.json(); setLocations(data); } } catch (error) { console.error("Failed to fetch locations", error); } finally { setLoading(false); } }; useEffect(() => { fetchLocations(); }, []); const handleDelete = async (id: string) => { if (!confirm("Are you sure you want to delete this location?")) return; try { const res = await fetch(`/api/admin/locations/${id}`, { method: "DELETE", }); if (res.ok) { fetchLocations(); } else { alert("Failed to delete"); } } catch (error) { console.error(error); } }; if (loading) return
Loading...
; return ( <>
Manage Locations (Projects)
+ Add New Project
{locations.map((loc) => ( ))} {locations.length === 0 && ( )}
Title City GPX Route Visibility Actions
{loc.title} {loc.city} {loc.gpxData ? ( Has Route ) : ( No Route )} {loc.visibility} Edit
No locations found. Start by adding one.
); }