'use client'; import { useState, useEffect } from 'react'; import { Plus, FileText, Calendar, Settings, Trash2, Edit } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { format } from 'date-fns'; import { getImports, deleteImport } from '@/app/actions/imports'; import { CreateImportDialog } from '@/app/components/imports/CreateImportDialog'; import { EditImportDialog } from '@/app/components/imports/EditImportDialog'; import { ImportDetailDialog } from '@/app/components/imports/ImportDetailDialog'; import { useToast } from '@/hooks/use-toast'; interface Import { id: number; name: string; importDate: string; layoutId: number; layout: { id: number; name: string; }; } export default function ImportsPage() { const [imports, setImports] = useState([]); const [loading, setLoading] = useState(true); const [createDialogOpen, setCreateDialogOpen] = useState(false); const [editDialogOpen, setEditDialogOpen] = useState(false); const [detailDialogOpen, setDetailDialogOpen] = useState(false); const [selectedImport, setSelectedImport] = useState(null); const { toast } = useToast(); useEffect(() => { loadImports(); }, []); async function loadImports() { try { const result = await getImports(); if (result.success) { setImports(result.data); } else { toast({ title: 'Error', description: 'Failed to load imports', variant: 'destructive', }); } } catch (error) { toast({ title: 'Error', description: 'Failed to load imports', variant: 'destructive', }); } finally { setLoading(false); } } async function handleDeleteImport(id: number) { if (!confirm('Are you sure you want to delete this import?')) return; try { const result = await deleteImport(id); if (result.success) { toast({ title: 'Success', description: 'Import deleted successfully', }); loadImports(); } else { toast({ title: 'Error', description: result.error || 'Failed to delete import', variant: 'destructive', }); } } catch (error) { toast({ title: 'Error', description: 'Failed to delete import', variant: 'destructive', }); } } function handleEditImport(importRecord: Import) { setSelectedImport(importRecord); setEditDialogOpen(true); } function handleViewImport(importRecord: Import) { setSelectedImport(importRecord); setDetailDialogOpen(true); } if (loading) { return (
); } return (

Import Management

Manage your data imports and configurations

{imports.length === 0 ? (

No imports yet

Get started by creating your first import

) : (
{imports.map((importRecord) => (
{importRecord.name} Layout: {importRecord.layout.name}
{format(new Date(importRecord.importDate), 'MMM d, yyyy')}
))}
)}
); }