Files
TenerifeProp/public/js/admin/modals/LeadModal.js
APAW Agent Sync 8c1b897b9d feat(admin): replace prompt() with Bootstrap modals for CRUD operations
Replace browser prompt()-based editing with proper Bootstrap 5 modal
dialogs for testimonials, services, FAQs, and leads. This provides
better UX with form validation, structured input fields, and i18n
support (ES/RU) instead of raw prompt dialogs.

- Add testimonialModal, serviceModal, faqModal, leadModal to admin.html
- Add show*/save* methods in admin.js for each entity type
- Wire leads.html 'Add lead' button to leadModal
- Add modal JS modules (FAQModal, LeadModal, ServiceModal)
- Add unit and e2e tests for modals and API client
2026-05-16 00:43:04 +01:00

57 lines
1.9 KiB
JavaScript

import { BaseModal } from '../core/BaseModal.js';
import { API } from '../../api.js';
export class LeadModal extends BaseModal {
constructor() {
super({
id: 'leadModal',
title: 'Lead',
icon: 'bi-person-plus',
fields: [
{ name: 'name', label: 'Nombre', type: 'text', required: true },
{ name: 'email', label: 'Email', type: 'email' },
{ name: 'phone', label: 'Teléfono', type: 'text' },
{ name: 'message', label: 'Mensaje', type: 'textarea', rows: 3 },
{ name: 'property_id', label: 'ID propiedad', type: 'text', placeholder: 'ID propiedad opcional' },
{
name: 'status',
label: 'Estado',
type: 'select',
defaultValue: 'new',
options: [
{ value: 'new', label: 'Nuevo' },
{ value: 'contacted', label: 'Contactado' },
{ value: 'qualified', label: 'Cualificado' },
{ value: 'negotiating', label: 'Negociando' },
{ value: 'closed', label: 'Cerrado' }
]
},
{
name: 'source',
label: 'Fuente',
type: 'select',
defaultValue: 'manual',
options: [
{ value: 'webform', label: 'Formulario web' },
{ value: 'whatsapp', label: 'WhatsApp' },
{ value: 'email', label: 'Email' },
{ value: 'phone', label: 'Teléfono' },
{ value: 'manual', label: 'Manual' }
]
}
],
onSave: async (data, editId) => {
// For leads, we always use the admin API endpoints
const res = editId
? await API.updateLead(editId, data)
: await API.createLead(data);
if (res.success) {
window.app.showNotification(editId ? 'Lead actualizado' : 'Lead creado', 'success');
window.app.refreshSection('leads');
} else {
throw new Error(res.error || 'Error al guardar lead');
}
}
});
}
}