fix(notas): notas persisten entre etapas via clienteClave
- Campo clienteClave en RecordatorioVendedor (hash nombre+telefono) - Al crear nota: se calcula clienteClave del lead/cliente - Al buscar notas: busca por leadId O clienteClave (no por nombre suelto) - Mantiene compatibilidad: notas viejas sin clienteClave siguen por leadId - Migración SQL aplicada
This commit is contained in:
@@ -6,6 +6,13 @@ import { listarRecordatorios, crearRecordatorio, type Recordatorio } from '../se
|
||||
|
||||
type LeadItem = LeadMiDia | OportunidadMiDia | ApartadoMiDia
|
||||
|
||||
/** Calcula una clave estable del cliente: nombre normalizado + últimos 10 dígitos del teléfono */
|
||||
function calcularClienteClave(nombre?: string | null, telefono?: string | null): string {
|
||||
const n = (nombre ?? '').trim().toLowerCase()
|
||||
const t = (telefono ?? '').replace(/\s+/g, '').slice(-10)
|
||||
return `${n}|${t}`
|
||||
}
|
||||
|
||||
function esLead(item: LeadItem): item is LeadMiDia {
|
||||
return 'email' in item && 'origen' in item && !('modeloInteres' in item)
|
||||
}
|
||||
@@ -40,7 +47,8 @@ export default function DetalleLeadModal({ item, onCerrar }: { item: LeadItem; o
|
||||
setCargandoNotas(true)
|
||||
try {
|
||||
const todas = await listarRecordatorios()
|
||||
setNotas(todas.filter((r) => r.leadId === item.id || r.titulo?.toLowerCase().includes(item.nombre.toLowerCase()) || r.descripcion?.toLowerCase().includes(item.nombre.toLowerCase())))
|
||||
const clave = calcularClienteClave(item.nombre, (item as any).telefono)
|
||||
setNotas(todas.filter((r) => r.leadId === item.id || (r.clienteClave && r.clienteClave === clave)))
|
||||
} catch { setNotaError('Error al cargar notas.') }
|
||||
finally { setCargandoNotas(false) }
|
||||
}, [item.id])
|
||||
@@ -52,7 +60,7 @@ export default function DetalleLeadModal({ item, onCerrar }: { item: LeadItem; o
|
||||
if (!nuevaNota.trim()) return
|
||||
setEnviandoNota(true)
|
||||
try {
|
||||
await crearRecordatorio({ titulo: nuevaNota.trim(), leadId: item.id, fechaRecordar: new Date().toISOString() })
|
||||
await crearRecordatorio({ titulo: nuevaNota.trim(), leadId: item.id, clienteClave: calcularClienteClave(item.nombre, (item as any).telefono), fechaRecordar: new Date().toISOString() })
|
||||
setNuevaNota('')
|
||||
await cargarNotas()
|
||||
} catch { setNotaError('No se pudo guardar.') }
|
||||
|
||||
@@ -6,7 +6,8 @@ export interface Recordatorio {
|
||||
id: string
|
||||
titulo: string
|
||||
descripcion: string | null
|
||||
leadId: string | null
|
||||
leadId: string
|
||||
clienteClave: string | null
|
||||
fechaRecordar: string // ISO
|
||||
completado: boolean
|
||||
createdAt: string
|
||||
@@ -28,6 +29,7 @@ export async function crearRecordatorio(data: {
|
||||
titulo: string
|
||||
descripcion?: string
|
||||
leadId: string
|
||||
clienteClave?: string
|
||||
fechaRecordar: string
|
||||
}): Promise<Recordatorio> {
|
||||
const res = await fetch(`${API_URL}/recordatorios`, conAuth({
|
||||
|
||||
Reference in New Issue
Block a user