"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import { useAuth } from "@/context/AuthContext"; import { Terminal } from "lucide-react"; export default function LogsPage() { const { user } = useAuth(); const router = useRouter(); const [applications, setApplications] = useState([]); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(""); useEffect(() => { fetchApplications(); }, []); async function fetchApplications() { setIsLoading(true); try { const response = await fetch( "http://localhost:8080/twirp/applications.ApplicationsService/ListApplications", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ token: localStorage.getItem("token"), }), }, ); const data = await response.json(); if (data.applications) { setApplications(data.applications); } } catch (error) { console.error("Error fetching applications:", error); setError("Failed to load applications"); } finally { setIsLoading(false); } } const handleApplicationClick = (appId) => { router.push(`/dashboard/logs/${appId}`); }; return (

Logs

{error && (
{error}
)} {isLoading ? (

Loading applications...

) : applications.length === 0 ? (

No applications found.

) : (
{applications.map((app) => (
handleApplicationClick(app.id)} className="rounded-lg border border-gray-200 bg-white p-6 shadow-sm transition-shadow hover:shadow-md cursor-pointer" >
{app.name}
Description: {app.description}
Created: {new Date(app.created_at).toLocaleString()}
))}
)}
); }