independencia del provider

This commit is contained in:
2026-07-09 16:55:39 +02:00
parent 61a43ef481
commit 6400485b6d
5 changed files with 164 additions and 17 deletions
+15 -5
View File
@@ -211,9 +211,16 @@
}
// === EasyAppointments config ===
// IMPORTANTE: Después de configurar EasyAppointments, ve al admin (http://localhost:8888)
// y crea al menos un Provider. Anota su ID y ponlo aquí.
const PROVIDER_ID = 5;
// El id del provider lo resuelve el servidor (/api/config): autodescubierto
// en EasyAppointments o fijado con EA_PROVIDER_ID en .env. Aquí nunca va
// hardcodeado, así el mismo HTML sirve en desarrollo y en producción.
let PROVIDER_ID = null;
async function loadConfig() {
const res = await fetch('/api/config');
if (!res.ok) throw new Error('HTTP ' + res.status);
PROVIDER_ID = (await res.json()).providerId;
}
// ---- Horario desde EasyAppointments (Settings → Business, company_working_plan) ----
// Si la petición falla se mantiene el horario estático del HTML.
@@ -655,7 +662,6 @@
email: email,
telefono: form.telefono.value.trim(),
mensaje: form.mensaje.value.trim(),
providerId: PROVIDER_ID,
serviceIds: selectedServices.map(s => s.id).filter(Boolean),
date: selectedDate,
time: selectedHora
@@ -696,7 +702,11 @@
document.addEventListener('DOMContentLoaded', function() {
loadSchedule();
loadServices();
// loadServices filtra por provider y las availabilities usan su id:
// primero la config. Si falla, los servicios se cargan igual (sin filtro).
loadConfig().catch(function(e) {
console.error('Error cargando config:', e);
}).finally(loadServices);
initCalendar();
initBookingForm();
});