'use client'; import { useState, useEffect } from 'react'; import DataTable from '@/components/admin/DataTable'; import DetailModal from '@/components/admin/DetailModal'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { ArrowLeft, FolderKanban } from 'lucide-react'; import Link from 'next/link'; export default function ProjectsBrowserPage() { const [projects, setProjects] = useState([]); const [totalCount, setTotalCount] = useState(0); const [page, setPage] = useState(1); const [pageSize] = useState(50); const [isLoading, setIsLoading] = useState(false); const [selectedProject, setSelectedProject] = useState(null); const [modalOpen, setModalOpen] = useState(false); const fetchProjects = async (currentPage: number, search?: string, sortBy?: string, sortOrder?: string) => { setIsLoading(true); try { const params = new URLSearchParams({ limit: pageSize.toString(), offset: ((currentPage - 1) * pageSize).toString(), }); if (search) params.append('search', search); if (sortBy) params.append('sort', sortBy); if (sortOrder) params.append('order', sortOrder); const response = await fetch(`/api/data/projects?${params}`); const result = await response.json(); setProjects(result.projects || []); setTotalCount(result.pagination?.total || 0); } catch (error) { console.error('Failed to fetch projects:', error); } finally { setIsLoading(false); } }; useEffect(() => { fetchProjects(page); }, [page]); const handleRowClick = (project: any) => { setSelectedProject(project); setModalOpen(true); }; const columns = [ { key: 'id', label: 'ID', sortable: true, }, { key: 'project_name', label: 'Project Name', sortable: true, render: (value: string) => (
{value}
), }, { key: 'project_number', label: 'Project #', sortable: true, }, { key: 'company_id', label: 'Company ID', sortable: true, }, { key: 'status', label: 'Status', sortable: true, }, { key: 'start_date_time', label: 'Start Date', sortable: true, render: (value: string) => ( value ? new Date(value).toLocaleDateString() : '-' ), }, { key: 'completed_percentage', label: 'Progress', render: (value: number) => (
{value ? `${value}%` : '-'}
), }, ]; const detailFields = [ { key: 'id', label: 'ID' }, { key: 'company_id', label: 'Company ID' }, { key: 'project_name', label: 'Project Name' }, { key: 'project_number', label: 'Project Number' }, { key: 'description', label: 'Description' }, { key: 'status', label: 'Status' }, { key: 'type', label: 'Type' }, { key: 'start_date_time', label: 'Start Date' }, { key: 'end_date_time', label: 'End Date' }, { key: 'estimated_time', label: 'Estimated Time' }, { key: 'actual_hours', label: 'Actual Hours' }, { key: 'completed_percentage', label: 'Completed %' }, { key: 'project_lead_resource_id', label: 'Project Lead ID' }, { key: 'owner_resource_id', label: 'Owner ID' }, { key: 'synced_at', label: 'Synced At' }, { key: 'is_deleted', label: 'Is Deleted' }, ]; return (
{/* Header */}

Projects

Manage and inspect project data

{totalCount} total records
{/* Data Table Card */}
All Projects View and search through all projects in the system
fetchProjects(page, undefined, column, direction)} onSearch={(query) => fetchProjects(1, query)} onRowClick={handleRowClick} isLoading={isLoading} />
{/* Detail Modal */}
); }