-
-
Portal del Cliente
-
Próximamente
+
+
+
+
+
+
+
+
+
Portal del Cliente
+
Personaliza la web que ven tus clientes al recibir el WhatsApp.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Formatos: PNG, JPG (Máx. 1MB). Recomendado: Cuadrado o Apaisado.
+
+
+
+
+
+
+
+
Horario de Citas (Rutas)
+
El portal calculará los huecos cada 30 min dentro de estas franjas.
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
@@ -478,6 +559,7 @@
if(tabId === 'others') { loadCompanies(); loadStatusesConfig(); }
if(tabId === 'whatsapp') { checkWhatsappStatus(); }
+ if(tabId === 'portal') { loadPortalConfig(); } // CARGAR DATOS DEL PORTAL
if(tabId === 'providers') {
loadProviderCredentials();
loadIaRules();
@@ -718,6 +800,88 @@
} catch(e) { showToast("Error de conexión", true); }
}
+ // --- LÓGICA PORTAL DEL CLIENTE ---
+ async function loadPortalConfig() {
+ try {
+ const res = await fetch(`${API_URL}/config/company`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } });
+ const data = await res.json();
+ if (data.ok && data.config) {
+ document.getElementById('confCompanyName').value = data.config.full_name || "";
+
+ if (data.config.company_logo) {
+ document.getElementById('confLogoBase64').value = data.config.company_logo;
+ document.getElementById('logoPreview').innerHTML = `

`;
+ }
+
+ if (data.config.portal_settings) {
+ const s = data.config.portal_settings;
+ if(s.m_start) document.getElementById('mStart').value = s.m_start;
+ if(s.m_end) document.getElementById('mEnd').value = s.m_end;
+ if(s.a_start) document.getElementById('aStart').value = s.a_start;
+ if(s.a_end) document.getElementById('aEnd').value = s.a_end;
+ }
+ }
+ } catch (e) { console.error("Error cargando config", e); }
+ }
+
+ function encodeLogo(input) {
+ const file = input.files[0];
+ if (!file) return;
+
+ if (file.size > 1024 * 1024) {
+ alert("La imagen es demasiado grande. Máximo 1MB.");
+ return;
+ }
+
+ const reader = new FileReader();
+ reader.onload = function(e) {
+ const base64 = e.target.result;
+ document.getElementById('confLogoBase64').value = base64;
+ document.getElementById('logoPreview').innerHTML = `

`;
+ };
+ reader.readAsDataURL(file);
+ }
+
+ async function savePortalConfig() {
+ const btn = document.getElementById('btnSavePortal');
+ const originalText = btn.innerHTML;
+ btn.innerHTML = '
Guardando...';
+ lucide.createIcons();
+
+ const payload = {
+ company_name: document.getElementById('confCompanyName').value,
+ company_logo: document.getElementById('confLogoBase64').value,
+ portal_settings: {
+ m_start: document.getElementById('mStart').value,
+ m_end: document.getElementById('mEnd').value,
+ a_start: document.getElementById('aStart').value,
+ a_end: document.getElementById('aEnd').value
+ }
+ };
+
+ try {
+ const res = await fetch(`${API_URL}/config/company`, {
+ method: 'POST',
+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` },
+ body: JSON.stringify(payload)
+ });
+ const data = await res.json();
+
+ if (data.ok) {
+ showToast("Configuración del Portal guardada");
+ const nameEl = document.getElementById("headerUserName");
+ if (nameEl && payload.company_name) nameEl.innerText = payload.company_name;
+ } else {
+ showToast("Error: " + data.error, true);
+ }
+ } catch (e) {
+ showToast("Error de conexión", true);
+ } finally {
+ btn.innerHTML = originalText;
+ lucide.createIcons();
+ }
+ }
+
function showToast(msg, isError = false) {
const t = document.getElementById('toast'), m = document.getElementById('toastMsg');
t.className = `fixed bottom-5 right-5 px-6 py-3 rounded-lg shadow-xl transition-all duration-300 z-50 flex items-center gap-3 ${isError ? 'bg-red-600' : 'bg-slate-800'} text-white font-medium`;