diff --git a/src/app/api/admin/integrations/route.ts b/src/app/api/admin/integrations/route.ts index 5916a53..4b3df22 100644 --- a/src/app/api/admin/integrations/route.ts +++ b/src/app/api/admin/integrations/route.ts @@ -129,13 +129,24 @@ export async function PATCH(req: NextRequest) { }; if (status) patch.status = status; if (externalAccountId !== undefined) { - patch.external_account_id = externalAccountId || null; + let id = externalAccountId || null; + // Drive: accept full folder URL → store folder id only + if (provider === 'google_drive' && id) { + const m = id.match(/\/folders\/([a-zA-Z0-9_-]+)/); + if (m) id = m[1]; + else if (id.includes('http')) { + const q = id.match(/[?&]id=([a-zA-Z0-9_-]+)/); + if (q) id = q[1]; + } + } + patch.external_account_id = id; } if (label !== undefined) patch.label = label || null; if (errorMessage !== undefined) patch.error_message = errorMessage || null; if (enabled !== undefined) patch.enabled = enabled; + // Manual «Conectar» only marks the reference — do not fake a data sync timestamp. + // Real syncs (Ads discover, Orgánico, Superhuman…) set last_sync_at themselves. if (status === 'connected') { - patch.last_sync_at = new Date().toISOString(); patch.error_message = null; } if (status === 'disconnected') { diff --git a/src/components/ClientIntegrationsPanel.tsx b/src/components/ClientIntegrationsPanel.tsx index 36ac948..c773cf0 100644 --- a/src/components/ClientIntegrationsPanel.tsx +++ b/src/components/ClientIntegrationsPanel.tsx @@ -205,12 +205,16 @@ export default function ClientIntegrationsPanel({ Carpeta: {folderHint}

)} - {row?.last_sync_at && ( + {row?.last_sync_at ? (

- Último sync{' '} + Último sync real{' '} {new Date(row.last_sync_at).toLocaleString('es-ES')}

- )} + ) : status === 'connected' ? ( +

+ Referencia guardada (aún sin sync de datos) +

+ ) : null} {row?.error_message && (

{row.error_message}