feat: agency portfolio with per-client integrations hub

Admin home lists tenants, alerts, and connection health; header
selector enables superadmin context; Meta/GA4/GSC/GTM/CRM/email
slots live per tenant (manual status until OAuth).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-09-22 01:31:47 +02:00
parent 9d1609c88b
commit 791976a3d8
19 changed files with 1503 additions and 20 deletions

View File

@@ -0,0 +1,41 @@
import React from 'react';
import ClientIntegrationsPanel from '@/components/ClientIntegrationsPanel';
import { createClient } from '@/lib/supabase/server';
import { redirect } from 'next/navigation';
import {
isAgencyRole,
serviceHeaders,
supabaseUrl,
userRole,
} from '@/lib/agency';
export const dynamic = 'force-dynamic';
export default async function ClienteIntegrationsPage({
params,
}: {
params: Promise<{ id: string }>;
}) {
const { id } = await params;
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) redirect('/login');
if (!isAgencyRole(userRole(user))) redirect('/dashboard/kpis');
const headers = serviceHeaders();
let name = 'Cliente';
if (headers) {
const r = await fetch(
`${supabaseUrl()}/rest/v1/tenants?id=eq.${encodeURIComponent(id)}&select=name`,
{ headers, cache: 'no-store' }
);
if (r.ok) {
const rows = await r.json();
if (rows[0]?.name) name = rows[0].name;
}
}
return <ClientIntegrationsPanel tenantId={id} tenantName={name} />;
}

View File

@@ -1,6 +1,7 @@
import React from 'react';
import { Building2, DollarSign, Users, TrendingUp, Layers } from 'lucide-react';
import ClientManagement from '@/components/ClientManagement';
import AgencyPortfolioBoard from '@/components/AgencyPortfolioBoard';
import { createClient } from '@/lib/supabase/server';
import { redirect } from 'next/navigation';
@@ -76,10 +77,12 @@ export default async function AgencyPage() {
</div>
<h2 className="text-2xl font-bold tracking-tight text-white">Centro de Mando 4Ventures</h2>
<p className="text-sm text-gray-400 mt-1">
Métricas consolidadas de infraestructura, inversión publicitaria y cartera de clientes.
Portafolio multi-cliente · integraciones (Meta, MCC, GA4, GSC, GTM, CRM, email) · alertas · modo superadmin.
</p>
</div>
<AgencyPortfolioBoard />
{/* Global Agency KPI Cards */}
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<div className="bg-[#111827] border border-gray-800 rounded-xl p-5">

View File

@@ -57,7 +57,8 @@ export default function CreativesPage() {
Creatividades
</h2>
<p className="text-sm text-gray-400 mt-1">
Borradores por tenant con RLS · visibles solo para tu <code>tenant_id</code>.
Borradores del cliente en contexto (selector arriba). Con superadmin
activo, ves/creas en ese tenant.
</p>
</div>

View File

@@ -13,6 +13,9 @@ import {
} from 'lucide-react';
import { createClient } from '@/lib/supabase/server';
import { logoutAction } from '@/app/auth/actions';
import TenantSwitcher from '@/components/TenantSwitcher';
import { cookies } from 'next/headers';
import { VIEW_TENANT_NAME_COOKIE } from '@/lib/agency';
export default async function DashboardLayout({
children,
@@ -26,6 +29,8 @@ export default async function DashboardLayout({
const company = user?.user_metadata?.company || '4Ventures Central';
const email = user?.email || 'usuario@4ventures.es';
const isAgency = role === 'admin' || role === 'team';
const cookieStore = await cookies();
const viewName = cookieStore.get(VIEW_TENANT_NAME_COOKIE)?.value;
return (
<div className="flex min-h-screen bg-[#0B0F19]">
@@ -94,7 +99,7 @@ export default async function DashboardLayout({
className="flex items-center gap-3 px-3 py-2.5 mt-1 rounded-lg text-sm font-medium text-gray-300 hover:text-white hover:bg-gray-800/60 transition-all"
>
<Layers className="w-4 h-4 text-amber-400" />
Cartera Cross-Tenant
Portafolio Agencia
</Link>
</div>
)}
@@ -139,10 +144,11 @@ export default async function DashboardLayout({
<div className="flex-1 flex flex-col min-w-0">
<header className="h-16 border-b border-gray-800 bg-[#0D121F]/50 backdrop-blur px-8 flex items-center justify-between">
<div className="flex items-center gap-2 text-sm text-gray-400">
<span>Cliente / Portal:</span>
<span className="bg-brand-500/10 text-brand-400 font-semibold px-2.5 py-1 rounded-md border border-brand-500/20">
{company}
</span>
<span>{isAgency ? 'Contexto:' : 'Cliente / Portal:'}</span>
<TenantSwitcher
isAgency={isAgency}
initialName={viewName || company}
/>
</div>
<div className="flex items-center gap-4">
<div className="flex items-center gap-2 text-xs bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 px-2.5 py-1 rounded-full">

View File

@@ -1,5 +1,14 @@
import { redirect } from 'next/navigation';
import { createClient } from '@/lib/supabase/server';
import { isAgencyRole, userRole } from '@/lib/agency';
export default function DashboardIndex() {
export default async function DashboardIndex() {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (user && isAgencyRole(userRole(user))) {
redirect('/dashboard/agencia');
}
redirect('/dashboard/kpis');
}