"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; interface PlaceRow { id: string; name: string; description: string | null; type: string | null; city: string | null; province: string | null; country: string | null; status: string | null; image1: string | null; contact: string | null; address: string | null; } function getToken() { if (typeof window === "undefined") return ""; return sessionStorage.getItem("token") || localStorage.getItem("token") || ""; } function statusBadge(status: string | null) { switch (status) { case "APPROVED": return "bg-tertiary-fixed text-on-tertiary-fixed-variant"; case "PENDING": return "bg-primary-fixed text-on-primary-fixed-variant"; case "REJECTED": return "bg-error-container text-on-error-container"; default: return "bg-slate-200 text-slate-600"; } } export default function AdminPlacesPage() { const [rows, setRows] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const [page, setPage] = useState(0); const [totalItem, setTotalItem] = useState(0); const [totalPage, setTotalPage] = useState(1); const pageSize = 20; useEffect(() => { async function load() { setLoading(true); setError(""); try { const token = getToken(); const res = await fetch(`/api/admin/places?page=${page}&size=${pageSize}`, { headers: { "x-auth-token": token }, }); const data = await res.json(); setRows(Array.isArray(data?.rows) ? data.rows : []); setTotalItem(data?.totalItem ?? 0); setTotalPage(data?.totalPage ?? 1); } catch { setError("Gagal memuat data lokasi"); } finally { setLoading(false); } } load(); }, [page]); const startEntry = page * pageSize + 1; const endEntry = Math.min((page + 1) * pageSize, totalItem); return ( <> {/* Header */}

Places Intelligence

Manage locations, tourist destinations, and business spots across Ina Trading's global network.

add Add Place
{/* Stats */}
Total Locations
{totalItem.toLocaleString()} Entries
Approved
{rows.filter((r) => r.status === "APPROVED").length} Active
Showing Page
{page + 1} / {totalPage}
{/* Table */}

Location Registry

{loading ? (
progress_activity

Memuat data...

) : error ? (
error

{error}

) : rows.length === 0 ? (
map

Belum ada lokasi

) : ( {["Place", "Type", "Location", "Status", "Actions"].map((h) => ( ))} {rows.map((item) => ( {/* Place */} {/* Type */} {/* Location */} {/* Status */} {/* Actions */} ))}
{h}
{item.image1 ? ( /* eslint-disable-next-line @next/next/no-img-element */ {item.name} ) : (
place
)}

{item.name}

{item.description && (

{item.description}

)}
{item.type ? ( {item.type} ) : ( )}
{[item.city, item.province].filter(Boolean).join(", ") || "—"} {item.country && ( {item.country} )}
{item.status || "—"} sessionStorage.setItem("editPlaceCache", JSON.stringify(item))} className="inline-flex items-center gap-1.5 bg-surface-container px-4 py-2 rounded-lg text-[10px] font-black uppercase tracking-widest text-on-surface hover:bg-primary hover:text-white transition-all" > edit Edit
)} {/* Pagination */} {!loading && rows.length > 0 && (
Showing{" "} {startEntry}–{endEntry}{" "} of{" "} {totalItem.toLocaleString()} entries
{Array.from({ length: Math.min(totalPage, 5) }, (_, i) => i).map((i) => ( ))}
)}
); }