feat: upload any validated file to the asset library
Activos now supports multi-file/folder upload to private Storage (PDF, Excel, CSV, images, ZIP, etc.) with per-tenant folders. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import React from 'react';
|
||||
import { FileText, CheckCircle2 } from 'lucide-react';
|
||||
import { CheckCircle2 } from 'lucide-react';
|
||||
import { createClient } from '@/lib/supabase/server';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { resolveActiveTenant, restGet } from '@/lib/tenant-context';
|
||||
import { isAgencyRole, userRole } from '@/lib/agency';
|
||||
import AssetsLibrary from '@/components/AssetsLibrary';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
@@ -28,15 +29,13 @@ export default async function ActivosPage() {
|
||||
const agency = isAgencyRole(userRole(user));
|
||||
let documents: Doc[] = [];
|
||||
|
||||
if (ctx.portfolioWide) {
|
||||
documents = [];
|
||||
} else if (agency && ctx.viaView && ctx.tenantId) {
|
||||
if (!ctx.portfolioWide && agency && ctx.viaView && ctx.tenantId) {
|
||||
const tid = encodeURIComponent(ctx.tenantId);
|
||||
const r = await restGet<Doc[]>(
|
||||
`/rest/v1/documents?tenant_id=eq.${tid}&status=eq.approved&select=id,type,title,content,version,created_at,status&order=created_at.desc`
|
||||
);
|
||||
documents = r.data || [];
|
||||
} else {
|
||||
} else if (!ctx.portfolioWide) {
|
||||
const { data, error } = await supabase
|
||||
.from('documents')
|
||||
.select('id,type,title,content,version,created_at,status')
|
||||
@@ -46,70 +45,59 @@ export default async function ActivosPage() {
|
||||
else documents = data ?? [];
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight text-white">
|
||||
Biblioteca de activos
|
||||
</h2>
|
||||
<p className="text-sm text-gray-400 mt-1 max-w-2xl">
|
||||
Entregables aprobados del cliente ({ctx.label}): briefs, audits,
|
||||
copys, calendarios exportados. Fuente:{' '}
|
||||
<code>documents</code> con <code>status=approved</code> (agentes →
|
||||
Slack → OK). Distinto del pipeline de creatividades ads.
|
||||
if (ctx.portfolioWide) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h2 className="text-2xl font-bold tracking-tight text-white">
|
||||
Biblioteca de activos
|
||||
</h2>
|
||||
<p className="text-sm text-gray-400 mt-1">
|
||||
Selecciona un cliente en Contexto para subir o consultar archivos
|
||||
validados.
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-sm text-gray-500 border border-gray-800 rounded-xl p-6 bg-[#111827]">
|
||||
Vista global: elige el tenant arriba y vuelve aquí.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
{ctx.portfolioWide ? (
|
||||
<p className="text-sm text-gray-500 border border-gray-800 rounded-xl p-6 bg-[#111827]">
|
||||
Selecciona un cliente en Contexto para ver su biblioteca.
|
||||
</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
{documents.length === 0 ? (
|
||||
<div className="col-span-3 bg-[#111827] border border-gray-800 rounded-xl p-12 text-center text-gray-400">
|
||||
<FileText className="w-10 h-10 text-gray-600 mx-auto mb-3" />
|
||||
<p className="text-base font-medium text-gray-300">
|
||||
No hay activos aprobados todavía.
|
||||
</p>
|
||||
<p className="text-xs text-gray-400 mt-1">
|
||||
Aparecerán aquí tras validación en Slack / ops.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
documents.map((doc) => (
|
||||
return (
|
||||
<div className="space-y-10">
|
||||
<AssetsLibrary tenantLabel={ctx.label} />
|
||||
|
||||
{documents.length > 0 && (
|
||||
<section className="space-y-4">
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-white">
|
||||
Entregables de agentes
|
||||
</h3>
|
||||
<p className="text-xs text-gray-500 mt-1">
|
||||
Textos/briefs aprobados en <code>documents</code> (Slack / ops).
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
{documents.map((doc) => (
|
||||
<div
|
||||
key={doc.id}
|
||||
className="bg-[#111827] border border-gray-800 rounded-xl p-5 flex flex-col justify-between"
|
||||
className="bg-[#111827] border border-gray-800 rounded-xl p-5"
|
||||
>
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<span className="uppercase text-[10px] font-bold px-2 py-0.5 rounded bg-gray-800 text-gray-300">
|
||||
{doc.type}
|
||||
</span>
|
||||
<span className="flex items-center gap-1 text-[11px] text-emerald-400">
|
||||
<CheckCircle2 className="w-3 h-3" /> Aprobado
|
||||
</span>
|
||||
</div>
|
||||
<h4 className="font-bold text-white text-base mb-2">
|
||||
{doc.title}
|
||||
</h4>
|
||||
<p className="text-xs text-gray-400 line-clamp-4">
|
||||
{doc.content}
|
||||
</p>
|
||||
</div>
|
||||
<div className="pt-4 border-t border-gray-800/80 mt-4 text-[11px] text-gray-400 flex justify-between">
|
||||
<span>Versión v{doc.version}</span>
|
||||
<span>
|
||||
{doc.created_at
|
||||
? new Date(doc.created_at).toLocaleDateString('es-ES')
|
||||
: '—'}
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<span className="uppercase text-[10px] font-bold px-2 py-0.5 rounded bg-gray-800 text-gray-300">
|
||||
{doc.type}
|
||||
</span>
|
||||
<span className="flex items-center gap-1 text-[11px] text-emerald-400">
|
||||
<CheckCircle2 className="w-3 h-3" /> Aprobado
|
||||
</span>
|
||||
</div>
|
||||
<h4 className="font-bold text-white text-sm mb-2">{doc.title}</h4>
|
||||
<p className="text-xs text-gray-400 line-clamp-3">{doc.content}</p>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user