'use client'; import { useState } from 'react'; import { Plus, Search, Filter, MoreHorizontal, Edit, Trash2, Eye } from 'lucide-react'; import { Button } from '@/components/ui/button'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; interface ContentType { id: string; name: string; apiIdentifier: string; description?: string | null; fields: Field[]; entries: ContentEntry[]; } interface Field { id: string; label: string; apiIdentifier: string; type: string; isRequired: boolean; } interface ContentEntry { id: string; data: any; status: string; createdAt: string; updatedAt: string; } interface ContentEntriesPageProps { contentType: ContentType; } export function ContentEntriesPage({ contentType }: ContentEntriesPageProps) { const [searchTerm, setSearchTerm] = useState(''); const [statusFilter, setStatusFilter] = useState('all'); const router = useRouter(); const filteredEntries = contentType.entries.filter(entry => { const matchesSearch = searchTerm === '' || Object.values(entry.data).some(value => String(value).toLowerCase().includes(searchTerm.toLowerCase()) ); const matchesStatus = statusFilter === 'all' || entry.status === statusFilter; return matchesSearch && matchesStatus; }); const getDisplayValue = (entry: ContentEntry, field: Field) => { const value = entry.data[field.apiIdentifier]; if (!value) return '-'; if (field.type === 'RICH_TEXT') { // Extraer texto plano del HTML const div = document.createElement('div'); div.innerHTML = value; return div.textContent?.slice(0, 100) + '...' || '-'; } if (field.type === 'MEDIA') { return value.url ? '📷 Imagen' : '-'; } if (field.type === 'BOOLEAN') { return value ? '✅' : '❌'; } if (field.type === 'DATE') { return new Date(value).toLocaleDateString(); } return String(value).slice(0, 50) + (String(value).length > 50 ? '...' : ''); }; const handleDelete = async (entryId: string) => { if (!confirm('¿Estás seguro de que quieres eliminar esta entrada?')) return; try { const response = await fetch(`/api/content-types/${contentType.apiIdentifier}/entries/${entryId}`, { method: 'DELETE' }); if (response.ok) { router.refresh(); } } catch (error) { console.error('Error deleting entry:', error); } }; return (
{contentType.description || `Gestiona las entradas de ${contentType.name}`}
Comienza creando tu primera entrada de {contentType.name}
| {field.label} | ))}Estado | Actualizado | Acciones |
|---|---|---|---|
| {getDisplayValue(entry, field)} | ))}{entry.status === 'published' ? 'Publicada' : entry.status === 'draft' ? 'Borrador' : 'Archivada'} | {new Date(entry.updatedAt).toLocaleDateString()} |
|