import { APPWRITE_ALMEIRA_CONFIG } from '@/lib/appwrite'; import { createSessionClient } from '@/lib/appwrite.server'; import { getEntity, updateEntity } from '@/app/actions/entity'; import { revalidatePath } from 'next/cache'; import { Settings as SettingsIcon, Save, Clock, Menu, Building, Image as ImageIcon, Link as LinkIcon, Share2 } from 'lucide-react'; import { Settings as SettingsInterface } from '@/types/settings'; export default async function SettingsPage() { let settings: SettingsInterface = { ticker_count: 10, rotation_seconds: 5 }; let docId = ''; let entity: any = null; try { const sessionClient = await createSessionClient(); if (sessionClient) { const response = await sessionClient.databases.listDocuments( APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', [] ); if (response.documents.length > 0) { settings = response.documents[0] as unknown as SettingsInterface; docId = response.documents[0].$id; } } entity = await getEntity(); } catch (e) { console.error("No se pudo cargar config:", e); } async function saveSettingsServer(formData: FormData) { 'use server'; const sessionClient = await createSessionClient(); if (!sessionClient) throw new Error("Acceso denegado"); const updateData = { ticker_count: parseInt(formData.get('ticker_count') as string), feed_news_count: parseInt(formData.get('feed_news_count') as string), rotation_seconds: parseInt(formData.get('rotation_seconds') as string), show_news_date: formData.get('show_news_date') === 'true' }; if (formData.get('docId')) { await sessionClient.databases.updateDocument( APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', formData.get('docId') as string, updateData ); } else { await sessionClient.databases.createDocument( APPWRITE_ALMEIRA_CONFIG.databaseId, 'settings', 'unique()', updateData ); } revalidatePath('/dashboard/settings'); revalidatePath('/'); // Revalidate frontpage } async function updateEntityClient(formData: FormData) { 'use server'; await updateEntity(formData); } return (
Panel de Ajustes Maestros del Ecosistema Web y Entidad Corporativa