|
190 | 190 | return null; |
191 | 191 | } |
192 | 192 |
|
| 193 | + const KIND_LABEL = { deal: 'Deal', person: 'Persona', organization: 'Organización', leads: 'Lead' }; |
| 194 | + const KIND_ICON = { deal: '💼', person: '👤', organization: '🏢', leads: '🎯' }; |
| 195 | + |
| 196 | + // Pinta (o esconde) el chip que indica si la nota automática va a ir a |
| 197 | + // Pipedrive al enviar. Se lee en vivo cada vez, no cacheamos. |
| 198 | + async function renderEntityChip(modal) { |
| 199 | + const chip = modal.querySelector('#whatpipe-entity-chip'); |
| 200 | + if (!chip) return; |
| 201 | + |
| 202 | + const { logSentAsNote = true, pipedriveApiToken } = await new Promise((res) => |
| 203 | + chrome.storage.local.get(['logSentAsNote', 'pipedriveApiToken'], res) |
| 204 | + ); |
| 205 | + |
| 206 | + if (!pipedriveApiToken) { |
| 207 | + chip.style.cssText = 'display:flex;align-items:center;gap:8px;padding:8px 10px;margin-bottom:12px;border-radius:8px;font-size:12.5px;background:#f1f5f9;color:#64748b;border:1px solid #e2e8f0;'; |
| 208 | + chip.textContent = 'ℹ️ Sin token de Pipedrive — no se registrará nota al enviar.'; |
| 209 | + return; |
| 210 | + } |
| 211 | + if (logSentAsNote === false) { |
| 212 | + chip.style.cssText = 'display:flex;align-items:center;gap:8px;padding:8px 10px;margin-bottom:12px;border-radius:8px;font-size:12.5px;background:#f1f5f9;color:#64748b;border:1px solid #e2e8f0;'; |
| 213 | + chip.textContent = 'ℹ️ Registro de nota desactivado en Opciones.'; |
| 214 | + return; |
| 215 | + } |
| 216 | + |
| 217 | + const entity = detectCurrentEntity(); |
| 218 | + if (entity) { |
| 219 | + const label = KIND_LABEL[entity.kind] || entity.kind; |
| 220 | + const icon = KIND_ICON[entity.kind] || '📌'; |
| 221 | + const idShort = String(entity.id).length > 10 ? String(entity.id).slice(0, 8) + '…' : entity.id; |
| 222 | + chip.style.cssText = 'display:flex;align-items:center;gap:8px;padding:8px 10px;margin-bottom:12px;border-radius:8px;font-size:12.5px;background:#dcfce7;color:#166534;border:1px solid #86efac;font-weight:600;'; |
| 223 | + chip.textContent = `${icon} ${label} #${idShort} detectado — se creará nota en Pipedrive al enviar`; |
| 224 | + } else { |
| 225 | + chip.style.cssText = 'display:flex;align-items:center;gap:8px;padding:8px 10px;margin-bottom:12px;border-radius:8px;font-size:12.5px;background:#fef3c7;color:#92400e;border:1px solid #fde68a;'; |
| 226 | + chip.textContent = '⚠️ No pude detectar la entidad de Pipedrive — no se creará nota. Abrí un deal/lead/persona (o su preview) para que lo registre.'; |
| 227 | + } |
| 228 | + } |
| 229 | + |
193 | 230 | // Observer global: cada vez que aparece un drawer/modal con un link a una |
194 | 231 | // entity, cacheamos esa entity. Sirve de fallback cuando, en el momento del |
195 | 232 | // envío, el DOM del drawer cambió y ya no tiene el link a la vista. |
|
600 | 637 | </div> |
601 | 638 |
|
602 | 639 | <div class="whatpipe-modal-body"> |
| 640 | + <div id="whatpipe-entity-chip" class="whatpipe-entity-chip" style="display:none;"></div> |
| 641 | +
|
603 | 642 | <div class="whatpipe-form-group"> |
604 | 643 | <label>Número de teléfono (WhatsApp)</label> |
605 | 644 | <div class="whatpipe-number-row"> |
|
705 | 744 | // Enrich from Pipedrive API if configured — overrides DOM guesses. |
706 | 745 | enrichFromPipedriveAPI(modal); |
707 | 746 |
|
| 747 | + // Entity chip: mostrar si detectamos deal/lead/persona/org para la nota. |
| 748 | + renderEntityChip(modal); |
| 749 | + // Refrescar periódicamente mientras el modal está abierto — la preview |
| 750 | + // puede abrirse o cambiar después de abrir el modal. |
| 751 | + const entityChipInterval = setInterval(() => { |
| 752 | + if (!document.body.contains(modal)) { |
| 753 | + clearInterval(entityChipInterval); |
| 754 | + return; |
| 755 | + } |
| 756 | + renderEntityChip(modal); |
| 757 | + }, 1500); |
| 758 | + |
708 | 759 | // Save-as-template button |
709 | 760 | modal.querySelector('#whatpipe-save-tpl').addEventListener('click', () => saveCurrentAsTemplate(modal)); |
710 | 761 | } |
|
0 commit comments