From a99355f76ea131094c1480e30f439172a1d80017 Mon Sep 17 00:00:00 2001 From: "Carlos (Almeira)" Date: Sun, 29 Mar 2026 01:41:29 -0500 Subject: [PATCH] feat(entity): habilitar MediaGridSelector para elegir y subir logotipo corporativo --- src/app/dashboard/entity/page.tsx | 16 +------- src/components/dashboard/EntityLogoField.tsx | 41 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 src/components/dashboard/EntityLogoField.tsx diff --git a/src/app/dashboard/entity/page.tsx b/src/app/dashboard/entity/page.tsx index 3f95670..91e8526 100644 --- a/src/app/dashboard/entity/page.tsx +++ b/src/app/dashboard/entity/page.tsx @@ -2,6 +2,7 @@ import { getEntity, updateEntity } from '@/app/actions/entity'; import { Building, Image as ImageIcon, Link as LinkIcon, Share2, Tv, RadioTower, Facebook, Instagram, Twitter, Youtube, Send, Mail, Globe, MapPin, Phone, MessageSquare } from 'lucide-react'; import { createSessionClient } from '@/lib/appwrite.server'; import { APPWRITE_ALMEIRA_CONFIG } from '@/lib/appwrite'; +import EntityLogoField from '@/components/dashboard/EntityLogoField'; export default async function EntityPage() { let entity: any = null; @@ -59,20 +60,7 @@ export default async function EntityPage() { /> -
- - {entity?.logotipo && ( -
- Logo actual -
- )} - -
+
diff --git a/src/components/dashboard/EntityLogoField.tsx b/src/components/dashboard/EntityLogoField.tsx new file mode 100644 index 0000000..a52d335 --- /dev/null +++ b/src/components/dashboard/EntityLogoField.tsx @@ -0,0 +1,41 @@ +'use client'; + +import { useState } from 'react'; +import { MediaGridSelector } from './MediaGridSelector'; + +export default function EntityLogoField({ + initialUrl = '', + initialId = '' +}: { + initialUrl?: string, + initialId?: string +}) { + // Si la entidad viene con url vieja, guardamos la url final. Si se escoge nueva, guardamos la url o el id según convenga. + // MediaGridSelector espera el ID del documento para hacer el preview. + const [mediaId, setMediaId] = useState(initialId); + const [finalUrl, setFinalUrl] = useState(initialUrl); + + return ( +
+ { + setMediaId(id); + setFinalUrl(url || ''); + }} + label="Logotipo Corporativo" + /> + {/* Si no hay mediaId activo pero sí URL antigua (legacy), la mostramos */} + {!mediaId && finalUrl && ( +
+

Logo Heredado

+ Logo actual +
+ )} + + {/* Enviamos el string del ID o de la URL para que entity.ts la guarde. + Adaptaremos entity.ts para que si 'logotipo' es texto puro, lo guarde tal cual. */} + +
+ ); +}