feat: restaurar todas las secciones en Creatividades Ads con sincronización bidireccional en tiempo real con Zona de Marca

This commit is contained in:
Marcos Fargas
2026-10-14 17:33:29 +02:00
parent 9d7d799ec1
commit 6e8e9ee5c8
5 changed files with 1677 additions and 406 deletions

View File

@@ -97,7 +97,15 @@ function KitThumb({ assetFileId, alt }: { assetFileId: string; alt: string }) {
);
}
export default function BrandZone({ tenantLabel }: { tenantLabel: string }) {
export default function BrandZone({
tenantId,
tenantLabel,
tenantSlug,
}: {
tenantId?: string;
tenantLabel: string;
tenantSlug?: string;
}) {
const [viewMode, setViewMode] = useState<'overview' | 'edit'>('overview');
const [section, setSection] = useState<BrandbookSectionId>('identidad');
const [book, setBook] = useState<Brandbook>(() => emptyBrandbook(tenantLabel));
@@ -120,11 +128,12 @@ export default function BrandZone({ tenantLabel }: { tenantLabel: string }) {
setLoading(true);
setErr(null);
try {
const r = await fetch('/api/brandbook');
const query = tenantId ? `?tenant_id=${encodeURIComponent(tenantId)}` : '';
const r = await fetch(`/api/brandbook${query}`);
const j = await r.json();
if (!r.ok) throw new Error(j.error || 'No se pudo cargar');
setBook(j.brandbook || emptyBrandbook(tenantLabel));
setSlug(j.slug || '');
setSlug(j.slug || tenantSlug || '');
setScore(j.completeness?.score ?? 0);
setMissing(j.completeness?.missing || []);
setExists(!!j.exists);
@@ -133,7 +142,7 @@ export default function BrandZone({ tenantLabel }: { tenantLabel: string }) {
} finally {
setLoading(false);
}
}, [tenantLabel]);
}, [tenantId, tenantLabel, tenantSlug]);
useEffect(() => {
void load();
@@ -149,10 +158,11 @@ export default function BrandZone({ tenantLabel }: { tenantLabel: string }) {
setErr(null);
setOkMsg(null);
try {
const r = await fetch('/api/brandbook', {
const query = tenantId ? `?tenant_id=${encodeURIComponent(tenantId)}` : '';
const r = await fetch(`/api/brandbook${query}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ brandbook: book }),
body: JSON.stringify({ brandbook: book, tenant_id: tenantId }),
});
const j = await r.json();
if (!r.ok) throw new Error(j.error || 'No se pudo guardar');
@@ -160,7 +170,7 @@ export default function BrandZone({ tenantLabel }: { tenantLabel: string }) {
setScore(j.completeness?.score ?? 0);
setMissing(j.completeness?.missing || []);
setExists(true);
setOkMsg('Brand kit guardado');
setOkMsg('Brand kit guardado correctamente y sincronizado');
} catch (e) {
setErr(e instanceof Error ? e.message : 'Error al guardar');
} finally {
@@ -172,10 +182,11 @@ export default function BrandZone({ tenantLabel }: { tenantLabel: string }) {
setSeeding(true);
setErr(null);
try {
const r = await fetch('/api/brandbook', {
const query = tenantId ? `?tenant_id=${encodeURIComponent(tenantId)}` : '';
const r = await fetch(`/api/brandbook${query}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ seed: true }),
body: JSON.stringify({ seed: true, tenant_id: tenantId }),
});
const j = await r.json();
if (!r.ok) throw new Error(j.error || 'No se pudo sembrar');