'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, Users } from 'lucide-react'; import Link from 'next/link'; export default function CompaniesBrowserPage() { const [companies, setCompanies] = useState([]); const [totalCount, setTotalCount] = useState(0); const [page, setPage] = useState(1); const [pageSize] = useState(50); const [isLoading, setIsLoading] = useState(false); const [selectedCompany, setSelectedCompany] = useState(null); const [modalOpen, setModalOpen] = useState(false); const fetchCompanies = async (currentPage: number, search?: string, sortBy?: string, sortOrder?: string) => { setIsLoading(true); try { const params = new URLSearchParams({ page: currentPage.toString(), limit: 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/companies?${params}`); const result = await response.json(); setCompanies(result.data || []); setTotalCount(result.pagination?.total || 0); } catch (error) { console.error('Failed to fetch companies:', error); } finally { setIsLoading(false); } }; useEffect(() => { fetchCompanies(page); }, [page]); const handleRowClick = (company: any) => { setSelectedCompany(company); setModalOpen(true); }; const columns = [ { key: 'id', label: 'ID', sortable: true, }, { key: 'company_name', label: 'Company Name', sortable: true, render: (value: string) => (
{value}
), }, { key: 'company_number', label: 'Company #', sortable: true, }, { key: 'phone', label: 'Phone', }, { key: 'city', label: 'City', sortable: true, }, { key: 'state', label: 'State', }, { key: 'is_active', label: 'Active', render: (value: boolean) => ( {value ? 'Active' : 'Inactive'} ), }, { key: 'is_deleted', label: 'Deleted', render: (value: boolean) => ( {value ? 'Yes' : 'No'} ), }, ]; const detailFields = [ { key: 'id', label: 'ID' }, { key: 'company_name', label: 'Company Name' }, { key: 'company_number', label: 'Company Number' }, { key: 'is_active', label: 'Active' }, { key: 'phone', label: 'Phone' }, { key: 'alternate_phone1', label: 'Alternate Phone 1' }, { key: 'alternate_phone2', label: 'Alternate Phone 2' }, { key: 'fax', label: 'Fax' }, { key: 'web_site_url', label: 'Website' }, { key: 'address1', label: 'Address 1' }, { key: 'address2', label: 'Address 2' }, { key: 'city', label: 'City' }, { key: 'state', label: 'State' }, { key: 'postal_code', label: 'Postal Code' }, { key: 'country', label: 'Country' }, { key: 'company_type', label: 'Company Type' }, { key: 'synced_at', label: 'Synced At' }, { key: 'is_deleted', label: 'Is Deleted' }, ]; return (

Companies Browser

Browse and inspect company data

Companies {totalCount} total companies in database fetchCompanies(page, undefined, column, direction)} onSearch={(query) => fetchCompanies(1, query)} onRowClick={handleRowClick} isLoading={isLoading} />
); }