Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00b59182ac | ||
|
|
7f56fe06d2 |
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 86 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 146 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
+155
@@ -1,7 +1,16 @@
|
|||||||
import type {
|
import type {
|
||||||
|
AdminPrincipal,
|
||||||
Booking,
|
Booking,
|
||||||
|
BookingCompletePayload,
|
||||||
|
BookingCreatePayload,
|
||||||
|
BookingReschedulePayload,
|
||||||
|
Client,
|
||||||
|
Client360,
|
||||||
|
ClientUpdatePayload,
|
||||||
|
PackageRecord,
|
||||||
PaymentAcknowledgmentPayload,
|
PaymentAcknowledgmentPayload,
|
||||||
PaymentRecord,
|
PaymentRecord,
|
||||||
|
Service,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
const API_BASE_URL =
|
const API_BASE_URL =
|
||||||
@@ -130,3 +139,149 @@ export async function retryCalendarSync(bookingId: string): Promise<Booking> {
|
|||||||
}
|
}
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchCurrentAdmin(): Promise<AdminPrincipal> {
|
||||||
|
const res = await fetch(`${API_BASE_URL}/auth/me`, {
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const errData = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(
|
||||||
|
errData.detail ||
|
||||||
|
`Error al consultar identidad de operador: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchServices(activeOnly = true): Promise<Service[]> {
|
||||||
|
const res = await fetch(
|
||||||
|
`${API_BASE_URL}/services?active_only=${activeOnly ? "true" : "false"}`,
|
||||||
|
{
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`Error al obtener catálogo de servicios: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function searchClients(search?: string): Promise<Client[]> {
|
||||||
|
const query = search ? `?search=${encodeURIComponent(search.trim())}` : "";
|
||||||
|
const res = await fetch(`${API_BASE_URL}/clients${query}`, {
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`Error al buscar clientes: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchClient360(clientId: string): Promise<Client360> {
|
||||||
|
const res = await fetch(`${API_BASE_URL}/clients/${clientId}`, {
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const errData = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(
|
||||||
|
errData.detail ||
|
||||||
|
`Error al obtener perfil de cliente: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateClient(
|
||||||
|
clientId: string,
|
||||||
|
payload: ClientUpdatePayload,
|
||||||
|
): Promise<Client> {
|
||||||
|
const res = await fetch(`${API_BASE_URL}/clients/${clientId}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const errData = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(
|
||||||
|
errData.detail ||
|
||||||
|
`Error al actualizar datos de cliente: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createBooking(
|
||||||
|
payload: BookingCreatePayload,
|
||||||
|
): Promise<Booking> {
|
||||||
|
const res = await fetch(`${API_BASE_URL}/bookings`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const errData = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(
|
||||||
|
errData.detail ||
|
||||||
|
`Error al agendar cita: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function rescheduleBooking(
|
||||||
|
bookingId: string,
|
||||||
|
payload: BookingReschedulePayload,
|
||||||
|
): Promise<Booking> {
|
||||||
|
const res = await fetch(`${API_BASE_URL}/bookings/${bookingId}/reschedule`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const errData = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(
|
||||||
|
errData.detail ||
|
||||||
|
`Error al reagendar cita: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function completeBooking(
|
||||||
|
bookingId: string,
|
||||||
|
payload?: BookingCompletePayload,
|
||||||
|
): Promise<Booking> {
|
||||||
|
const res = await fetch(`${API_BASE_URL}/bookings/${bookingId}/complete`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
body: JSON.stringify(payload || {}),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const errData = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(
|
||||||
|
errData.detail ||
|
||||||
|
`Error al concluir cita: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchPackages(
|
||||||
|
clientId?: string,
|
||||||
|
): Promise<PackageRecord[]> {
|
||||||
|
const query = clientId ? `?client_id=${encodeURIComponent(clientId)}` : "";
|
||||||
|
const res = await fetch(`${API_BASE_URL}/packages${query}`, {
|
||||||
|
headers: getAuthHeaders(),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`Error al obtener paquetes: ${res.status} ${res.statusText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
@@ -0,0 +1,483 @@
|
|||||||
|
import { fetchPackages, searchClients, updateClient } from "../api";
|
||||||
|
import type { Client, PackageRecord } from "../types";
|
||||||
|
import { debounce, formatMexicanPhone, getCleanDigitsPhone } from "../utils";
|
||||||
|
import { showToast } from "./Toast";
|
||||||
|
|
||||||
|
export function renderClientDirectory(
|
||||||
|
container: HTMLElement,
|
||||||
|
onStateChange?: () => void,
|
||||||
|
): void {
|
||||||
|
container.innerHTML = `
|
||||||
|
<div class="view-header">
|
||||||
|
<div>
|
||||||
|
<h2 class="view-title">Directorio de Consultantes</h2>
|
||||||
|
<p class="view-subtitle">Expedientes de contacto, notas clínicas y seguimiento de paquetes activos.</p>
|
||||||
|
</div>
|
||||||
|
<div class="view-actions">
|
||||||
|
<button id="refresh-clients-btn" class="btn btn-secondary btn-sm" title="Refrescar directorio">
|
||||||
|
↻ Actualizar
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Search Bar -->
|
||||||
|
<div class="directory-search-bar">
|
||||||
|
<div class="search-input-group">
|
||||||
|
<span class="search-icon" aria-hidden="true">🔍</span>
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
id="client-directory-search"
|
||||||
|
class="form-input directory-search-input"
|
||||||
|
placeholder="Buscar consultante por nombre o teléfono WhatsApp..."
|
||||||
|
aria-label="Buscar consultante por nombre o teléfono"
|
||||||
|
/>
|
||||||
|
<button type="button" id="clear-search-btn" class="btn-clear-input hidden" title="Limpiar búsqueda">×</button>
|
||||||
|
</div>
|
||||||
|
<div id="clients-counter" class="clients-counter-pill text-xs text-muted"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Main Container (5 States) -->
|
||||||
|
<div id="clients-content" class="clients-list-container">
|
||||||
|
<div class="loading-state">
|
||||||
|
<div class="skeleton-card"></div>
|
||||||
|
<div class="skeleton-card"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const contentDiv =
|
||||||
|
container.querySelector<HTMLDivElement>("#clients-content");
|
||||||
|
const searchInput = container.querySelector<HTMLInputElement>(
|
||||||
|
"#client-directory-search",
|
||||||
|
);
|
||||||
|
const clearSearchBtn =
|
||||||
|
container.querySelector<HTMLButtonElement>("#clear-search-btn");
|
||||||
|
const counterDiv =
|
||||||
|
container.querySelector<HTMLDivElement>("#clients-counter");
|
||||||
|
const refreshBtn = container.querySelector<HTMLButtonElement>(
|
||||||
|
"#refresh-clients-btn",
|
||||||
|
);
|
||||||
|
|
||||||
|
let cachedClients: Client[] = [];
|
||||||
|
let cachedPackages: PackageRecord[] = [];
|
||||||
|
let currentQuery = "";
|
||||||
|
|
||||||
|
const loadData = async (query = "") => {
|
||||||
|
if (!contentDiv) return;
|
||||||
|
currentQuery = query;
|
||||||
|
|
||||||
|
contentDiv.innerHTML = `
|
||||||
|
<div class="loading-state">
|
||||||
|
<div class="skeleton-card"></div>
|
||||||
|
<div class="skeleton-card"></div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Fetch clients and packages concurrently for resilient state
|
||||||
|
const [clientsResult, packagesResult] = await Promise.allSettled([
|
||||||
|
searchClients(query),
|
||||||
|
fetchPackages(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (clientsResult.status === "rejected") {
|
||||||
|
throw new Error(
|
||||||
|
clientsResult.reason instanceof Error
|
||||||
|
? clientsResult.reason.message
|
||||||
|
: "Error al cargar la lista de consultantes.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
cachedClients = clientsResult.value;
|
||||||
|
cachedPackages =
|
||||||
|
packagesResult.status === "fulfilled" ? packagesResult.value : [];
|
||||||
|
|
||||||
|
renderClients(cachedClients, cachedPackages);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
renderError(err instanceof Error ? err.message : "Error desconocido");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderError = (msg: string) => {
|
||||||
|
if (!contentDiv) return;
|
||||||
|
contentDiv.innerHTML = `
|
||||||
|
<div class="card error-state">
|
||||||
|
<div class="error-icon">⚠️</div>
|
||||||
|
<h3 class="error-title">No se pudo cargar el directorio</h3>
|
||||||
|
<p class="error-desc">${msg}</p>
|
||||||
|
<button id="retry-clients-btn" class="btn btn-primary btn-sm">
|
||||||
|
Intentar de nuevo
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
contentDiv
|
||||||
|
.querySelector("#retry-clients-btn")
|
||||||
|
?.addEventListener("click", () => loadData(currentQuery));
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderClients = (clients: Client[], packages: PackageRecord[]) => {
|
||||||
|
if (!contentDiv) return;
|
||||||
|
|
||||||
|
if (counterDiv) {
|
||||||
|
counterDiv.textContent = `${clients.length} ${clients.length === 1 ? "consultante registrado" : "consultantes registrados"}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clients.length === 0) {
|
||||||
|
contentDiv.innerHTML = `
|
||||||
|
<div class="card empty-state">
|
||||||
|
<div class="empty-icon">👥</div>
|
||||||
|
<h3 class="empty-title">
|
||||||
|
${currentQuery ? "Sin coincidencias" : "Directorio vacío"}
|
||||||
|
</h3>
|
||||||
|
<p class="empty-desc">
|
||||||
|
${
|
||||||
|
currentQuery
|
||||||
|
? `No se encontraron consultantes para "<strong>${escapeHtml(currentQuery)}</strong>". Puedes registrar una nueva cita desde el botón superior.`
|
||||||
|
: "Aún no hay consultantes registrados en el sistema."
|
||||||
|
}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
contentDiv.innerHTML = `
|
||||||
|
<div class="clients-grid">
|
||||||
|
${clients
|
||||||
|
.map((c) => {
|
||||||
|
const clientPackages = packages.filter(
|
||||||
|
(p) =>
|
||||||
|
p.client_id === c.id && p.completed_sessions < p.total_sessions,
|
||||||
|
);
|
||||||
|
|
||||||
|
const cleanDigits = getCleanDigitsPhone(c.phone_whatsapp);
|
||||||
|
const waLink = `https://wa.me/${cleanDigits}?text=${encodeURIComponent(
|
||||||
|
`Hola ${c.full_name}, te saludamos de Armonía del Ser.`,
|
||||||
|
)}`;
|
||||||
|
|
||||||
|
const packagesHtml =
|
||||||
|
clientPackages.length > 0
|
||||||
|
? clientPackages
|
||||||
|
.map(
|
||||||
|
(pkg) => `
|
||||||
|
<span class="package-pill" title="Sesiones completadas del paquete">
|
||||||
|
📦 Paquete: ${pkg.completed_sessions} de ${pkg.total_sessions}
|
||||||
|
${pkg.service_name ? `(${escapeHtml(pkg.service_name)})` : ""}
|
||||||
|
</span>
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.join("")
|
||||||
|
: '<span class="text-xs text-muted">Sin paquetes activos</span>';
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="client-card" id="client-card-${c.id}">
|
||||||
|
<div class="client-card-header">
|
||||||
|
<div>
|
||||||
|
<h3 class="client-card-name">${escapeHtml(c.full_name)}</h3>
|
||||||
|
<span class="client-registered-date text-xs text-muted">
|
||||||
|
Registrado el ${new Date(c.created_at).toLocaleDateString("es-MX", { day: "numeric", month: "short", year: "numeric" })}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-secondary btn-sm btn-edit-client"
|
||||||
|
data-client-id="${c.id}"
|
||||||
|
title="Editar datos de contacto o notas clínicas"
|
||||||
|
>
|
||||||
|
✏️ Editar
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="client-card-body">
|
||||||
|
<div class="client-contact-row">
|
||||||
|
<a
|
||||||
|
href="${waLink}"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="btn btn-whatsapp btn-xs"
|
||||||
|
title="Abrir WhatsApp para mensaje directo"
|
||||||
|
>
|
||||||
|
<span>💬 ${escapeHtml(c.phone_whatsapp)}</span>
|
||||||
|
</a>
|
||||||
|
${
|
||||||
|
c.email
|
||||||
|
? `<span class="client-email-badge text-xs">✉️ ${escapeHtml(c.email)}</span>`
|
||||||
|
: '<span class="text-xs text-muted">Sin correo</span>'
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="client-packages-row mt-2">
|
||||||
|
<span class="detail-label text-xs font-semibold">Estado de Paquetes:</span>
|
||||||
|
<div class="packages-tags-container mt-1">
|
||||||
|
${packagesHtml}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
c.notes
|
||||||
|
? `
|
||||||
|
<div class="client-notes-box mt-3">
|
||||||
|
<span class="notes-kicker text-xs font-semibold">Notas Clínicas / Operativas:</span>
|
||||||
|
<p class="notes-content text-sm mt-1">${escapeHtml(c.notes)}</p>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: `
|
||||||
|
<div class="client-notes-empty mt-2 text-xs text-muted">
|
||||||
|
Sin notas adicionales registradas.
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
})
|
||||||
|
.join("")}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Attach Edit Handlers
|
||||||
|
contentDiv.querySelectorAll(".btn-edit-client").forEach((btn) => {
|
||||||
|
btn.addEventListener("click", () => {
|
||||||
|
const id = btn.getAttribute("data-client-id");
|
||||||
|
const client = clients.find((c) => c.id === id);
|
||||||
|
if (!client) return;
|
||||||
|
|
||||||
|
openEditClientModal({
|
||||||
|
client,
|
||||||
|
onSuccess: (updated) => {
|
||||||
|
showToast(
|
||||||
|
`Datos actualizados para ${updated.full_name}`,
|
||||||
|
"success",
|
||||||
|
4500,
|
||||||
|
);
|
||||||
|
loadData(currentQuery);
|
||||||
|
onStateChange?.();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Debounced Search Handler
|
||||||
|
const onSearchInput = debounce((val: string) => {
|
||||||
|
if (clearSearchBtn) {
|
||||||
|
clearSearchBtn.classList.toggle("hidden", val.length === 0);
|
||||||
|
}
|
||||||
|
loadData(val);
|
||||||
|
}, 250);
|
||||||
|
|
||||||
|
searchInput?.addEventListener("input", () => {
|
||||||
|
onSearchInput(searchInput.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
clearSearchBtn?.addEventListener("click", () => {
|
||||||
|
if (searchInput) {
|
||||||
|
searchInput.value = "";
|
||||||
|
clearSearchBtn.classList.add("hidden");
|
||||||
|
loadData("");
|
||||||
|
searchInput.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
refreshBtn?.addEventListener("click", () => loadData(currentQuery));
|
||||||
|
|
||||||
|
// Initial load
|
||||||
|
loadData("");
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EditClientModalOptions {
|
||||||
|
client: Client;
|
||||||
|
onSuccess: (updated: Client) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openEditClientModal(options: EditClientModalOptions): void {
|
||||||
|
const { client, onSuccess } = options;
|
||||||
|
|
||||||
|
const existingBackdrop = document.getElementById(
|
||||||
|
"edit-client-modal-backdrop",
|
||||||
|
);
|
||||||
|
if (existingBackdrop) existingBackdrop.remove();
|
||||||
|
|
||||||
|
const backdrop = document.createElement("div");
|
||||||
|
backdrop.id = "edit-client-modal-backdrop";
|
||||||
|
backdrop.className = "modal-backdrop";
|
||||||
|
|
||||||
|
backdrop.innerHTML = `
|
||||||
|
<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="edit-client-title">
|
||||||
|
<div class="modal-header">
|
||||||
|
<div>
|
||||||
|
<span class="modal-kicker">Expediente de Consultante</span>
|
||||||
|
<h3 id="edit-client-title" class="modal-title">Editar Consultante</h3>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="modal-close-btn" id="edit-modal-close" aria-label="Cerrar modal">×</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="edit-client-form" class="modal-form-content">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-client-name" class="form-label font-semibold">
|
||||||
|
Nombre Completo <span class="text-danger">*</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="edit-client-name"
|
||||||
|
name="full_name"
|
||||||
|
class="form-input"
|
||||||
|
value="${escapeHtml(client.full_name)}"
|
||||||
|
required
|
||||||
|
minlength="2"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-client-phone" class="form-label font-semibold">
|
||||||
|
Teléfono WhatsApp (+52) <span class="text-danger">*</span>
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="tel"
|
||||||
|
id="edit-client-phone"
|
||||||
|
name="phone_whatsapp"
|
||||||
|
class="form-input"
|
||||||
|
value="${escapeHtml(formatMexicanPhone(client.phone_whatsapp))}"
|
||||||
|
required
|
||||||
|
minlength="10"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-client-email" class="form-label font-semibold">
|
||||||
|
Correo Electrónico (opcional)
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
id="edit-client-email"
|
||||||
|
name="email"
|
||||||
|
class="form-input"
|
||||||
|
value="${escapeHtml(client.email || "")}"
|
||||||
|
placeholder="correo@ejemplo.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="edit-client-notes" class="form-label font-semibold">
|
||||||
|
Notas Clínicas u Operativas
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
id="edit-client-notes"
|
||||||
|
name="notes"
|
||||||
|
class="form-textarea"
|
||||||
|
rows="3"
|
||||||
|
placeholder="Observaciones de salud, antecedentes, preferencias de horario..."
|
||||||
|
>${escapeHtml(client.notes || "")}</textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="edit-client-error" class="modal-error-box hidden" role="alert"></div>
|
||||||
|
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button type="button" id="edit-modal-cancel" class="btn btn-secondary">
|
||||||
|
Cancelar
|
||||||
|
</button>
|
||||||
|
<button type="submit" id="edit-modal-submit" class="btn btn-primary">
|
||||||
|
Guardar Cambios
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.body.appendChild(backdrop);
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
backdrop.remove();
|
||||||
|
document.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Escape") close();
|
||||||
|
};
|
||||||
|
document.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
backdrop
|
||||||
|
.querySelector("#edit-modal-close")
|
||||||
|
?.addEventListener("click", () => close());
|
||||||
|
backdrop
|
||||||
|
.querySelector("#edit-modal-cancel")
|
||||||
|
?.addEventListener("click", () => close());
|
||||||
|
backdrop.addEventListener("click", (e) => {
|
||||||
|
if (e.target === backdrop) close();
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = backdrop.querySelector<HTMLFormElement>("#edit-client-form");
|
||||||
|
const nameInput =
|
||||||
|
backdrop.querySelector<HTMLInputElement>("#edit-client-name");
|
||||||
|
const phoneInput =
|
||||||
|
backdrop.querySelector<HTMLInputElement>("#edit-client-phone");
|
||||||
|
const emailInput =
|
||||||
|
backdrop.querySelector<HTMLInputElement>("#edit-client-email");
|
||||||
|
const notesInput =
|
||||||
|
backdrop.querySelector<HTMLTextAreaElement>("#edit-client-notes");
|
||||||
|
const submitBtn =
|
||||||
|
backdrop.querySelector<HTMLButtonElement>("#edit-modal-submit");
|
||||||
|
const errorBox = backdrop.querySelector<HTMLDivElement>("#edit-client-error");
|
||||||
|
|
||||||
|
phoneInput?.addEventListener("blur", () => {
|
||||||
|
if (phoneInput.value) {
|
||||||
|
phoneInput.value = formatMexicanPhone(phoneInput.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
form?.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!submitBtn || !errorBox) return;
|
||||||
|
|
||||||
|
const full_name = nameInput?.value.trim();
|
||||||
|
const raw_phone = phoneInput?.value.trim() || "";
|
||||||
|
const phone_whatsapp = formatMexicanPhone(raw_phone);
|
||||||
|
const raw_email = emailInput?.value.trim();
|
||||||
|
const email = raw_email || null;
|
||||||
|
const raw_notes = notesInput?.value.trim();
|
||||||
|
const notes = raw_notes || null;
|
||||||
|
|
||||||
|
if (!full_name || !phone_whatsapp) {
|
||||||
|
errorBox.textContent = "El nombre y teléfono son obligatorios.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
submitBtn.disabled = true;
|
||||||
|
submitBtn.textContent = "Guardando...";
|
||||||
|
errorBox.classList.add("hidden");
|
||||||
|
errorBox.textContent = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updated = await updateClient(client.id, {
|
||||||
|
full_name,
|
||||||
|
phone_whatsapp,
|
||||||
|
email,
|
||||||
|
notes,
|
||||||
|
});
|
||||||
|
close();
|
||||||
|
onSuccess(updated);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
submitBtn.textContent = "Guardar Cambios";
|
||||||
|
errorBox.textContent =
|
||||||
|
err instanceof Error
|
||||||
|
? err.message
|
||||||
|
: "Error al actualizar datos del cliente.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
nameInput?.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(str: string): string {
|
||||||
|
return str
|
||||||
|
.replace(/&/g, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """)
|
||||||
|
.replace(/'/g, "'");
|
||||||
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
import { fetchAllBookings, retryCalendarSync } from "../api";
|
import {
|
||||||
|
completeBooking,
|
||||||
|
fetchAllBookings,
|
||||||
|
rescheduleBooking,
|
||||||
|
retryCalendarSync,
|
||||||
|
} from "../api";
|
||||||
import type { Booking } from "../types";
|
import type { Booking } from "../types";
|
||||||
import {
|
import {
|
||||||
calculateInterval,
|
calculateInterval,
|
||||||
checkBufferCollision,
|
checkBufferCollision,
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
|
formatDateInput,
|
||||||
formatDateTime,
|
formatDateTime,
|
||||||
formatTimeOnly,
|
formatTimeOnly,
|
||||||
isSameDay,
|
isSameDay,
|
||||||
@@ -11,6 +17,7 @@ import {
|
|||||||
isToday,
|
isToday,
|
||||||
isTomorrow,
|
isTomorrow,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
|
import { showConfirmModal } from "./MicroModal";
|
||||||
import {
|
import {
|
||||||
renderBookingStatusBadge,
|
renderBookingStatusBadge,
|
||||||
renderCalendarSyncBadge,
|
renderCalendarSyncBadge,
|
||||||
@@ -345,6 +352,31 @@ export function renderDailyAgenda(
|
|||||||
<span class="buffer-hint">Tiempo no agendable protegido por el backend.</span>
|
<span class="buffer-hint">Tiempo no agendable protegido por el backend.</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
${
|
||||||
|
b.booking_status === "RESERVED"
|
||||||
|
? `
|
||||||
|
<div class="agenda-card-actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-secondary btn-sm btn-reschedule-booking"
|
||||||
|
data-booking-id="${b.id}"
|
||||||
|
title="Mover cita a otro horario o día"
|
||||||
|
>
|
||||||
|
<span>🗓️ Mover Cita</span>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-outline-success btn-sm btn-complete-booking"
|
||||||
|
data-booking-id="${b.id}"
|
||||||
|
title="Marcar consulta como concluida"
|
||||||
|
>
|
||||||
|
<span>✓ Concluir Cita</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
|
||||||
${collisionNotice}
|
${collisionNotice}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -354,6 +386,72 @@ export function renderDailyAgenda(
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// Attach 'Mover Cita' handlers
|
||||||
|
contentDiv.querySelectorAll(".btn-reschedule-booking").forEach((btn) => {
|
||||||
|
btn.addEventListener("click", () => {
|
||||||
|
const id = btn.getAttribute("data-booking-id");
|
||||||
|
const booking = bookings.find((b) => b.id === id);
|
||||||
|
if (!booking) return;
|
||||||
|
|
||||||
|
openRescheduleModal({
|
||||||
|
booking,
|
||||||
|
onSuccess: (updated) => {
|
||||||
|
showToast(
|
||||||
|
`Cita reagendada para ${formatDateTime(updated.scheduled_at)}`,
|
||||||
|
"success",
|
||||||
|
5000,
|
||||||
|
{ folio: updated.booking_code },
|
||||||
|
);
|
||||||
|
loadData();
|
||||||
|
onStateChange();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Attach 'Concluir Cita' handlers
|
||||||
|
contentDiv.querySelectorAll(".btn-complete-booking").forEach((btn) => {
|
||||||
|
btn.addEventListener("click", () => {
|
||||||
|
const id = btn.getAttribute("data-booking-id");
|
||||||
|
const booking = bookings.find((b) => b.id === id);
|
||||||
|
if (!booking) return;
|
||||||
|
|
||||||
|
showConfirmModal({
|
||||||
|
title: "¿Concluir consulta?",
|
||||||
|
kicker: "Finalización de Sesión",
|
||||||
|
message: `¿Deseas marcar la consulta de <strong>${booking.client_name || "Cliente"}</strong> (${booking.booking_code}) como concluida? Se registrará la asistencia y el estado cambiará a CONCLUIDA.`,
|
||||||
|
bookingContext: {
|
||||||
|
bookingCode: booking.booking_code,
|
||||||
|
clientName: booking.client_name,
|
||||||
|
serviceName: booking.service_name,
|
||||||
|
scheduledAtFormatted: formatDateTime(booking.scheduled_at),
|
||||||
|
},
|
||||||
|
withReasonInput: true,
|
||||||
|
reasonLabel:
|
||||||
|
"Notas clínicas u observaciones de la sesión (opcional):",
|
||||||
|
defaultReason: "",
|
||||||
|
reasonPlaceholder:
|
||||||
|
"Ej. Se completó terapia de sonido; paciente reporta relajación profunda.",
|
||||||
|
confirmText: "✓ Sí, Concluir Cita",
|
||||||
|
cancelText: "Volver",
|
||||||
|
isDanger: false,
|
||||||
|
onConfirm: async (notes) => {
|
||||||
|
await completeBooking(booking.id, {
|
||||||
|
notes: notes || undefined,
|
||||||
|
});
|
||||||
|
showToast(
|
||||||
|
`Cita ${booking.booking_code} marcada como Concluida`,
|
||||||
|
"success",
|
||||||
|
5000,
|
||||||
|
{ folio: booking.booking_code },
|
||||||
|
);
|
||||||
|
loadData();
|
||||||
|
onStateChange();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Attach retry calendar sync buttons
|
// Attach retry calendar sync buttons
|
||||||
contentDiv.querySelectorAll(".btn-retry-gcal").forEach((btn) => {
|
contentDiv.querySelectorAll(".btn-retry-gcal").forEach((btn) => {
|
||||||
btn.addEventListener("click", async () => {
|
btn.addEventListener("click", async () => {
|
||||||
@@ -422,3 +520,184 @@ export function renderDailyAgenda(
|
|||||||
refreshBtn?.addEventListener("click", () => loadData());
|
refreshBtn?.addEventListener("click", () => loadData());
|
||||||
loadData();
|
loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface RescheduleModalOptions {
|
||||||
|
booking: Booking;
|
||||||
|
onSuccess: (updated: Booking) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function openRescheduleModal(options: RescheduleModalOptions): void {
|
||||||
|
const { booking, onSuccess } = options;
|
||||||
|
const existing = document.getElementById("reschedule-modal-backdrop");
|
||||||
|
if (existing) existing.remove();
|
||||||
|
|
||||||
|
const backdrop = document.createElement("div");
|
||||||
|
backdrop.id = "reschedule-modal-backdrop";
|
||||||
|
backdrop.className = "modal-backdrop";
|
||||||
|
|
||||||
|
const currentDt = new Date(booking.scheduled_at);
|
||||||
|
const defaultDate = formatDateInput(currentDt);
|
||||||
|
const hours = String(currentDt.getHours()).padStart(2, "0");
|
||||||
|
const mins = String(currentDt.getMinutes()).padStart(2, "0");
|
||||||
|
const defaultTime = `${hours}:${mins}`;
|
||||||
|
|
||||||
|
backdrop.innerHTML = `
|
||||||
|
<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="reschedule-modal-title">
|
||||||
|
<div class="modal-header">
|
||||||
|
<div>
|
||||||
|
<span class="modal-kicker">Reagendación de Consulta</span>
|
||||||
|
<h3 id="reschedule-modal-title" class="modal-title">Mover Cita</h3>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="modal-close-btn" id="reschedule-modal-close" aria-label="Cerrar modal">×</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="summary-box">
|
||||||
|
<div class="summary-row">
|
||||||
|
<span class="summary-label">Folio:</span>
|
||||||
|
<span class="summary-value font-mono font-bold">${booking.booking_code}</span>
|
||||||
|
</div>
|
||||||
|
<div class="summary-row">
|
||||||
|
<span class="summary-label">Paciente:</span>
|
||||||
|
<span class="summary-value font-semibold">${booking.client_name || "Cliente"}</span>
|
||||||
|
</div>
|
||||||
|
<div class="summary-row">
|
||||||
|
<span class="summary-label">Servicio:</span>
|
||||||
|
<span class="summary-value">${booking.service_name || "Consulta"}</span>
|
||||||
|
</div>
|
||||||
|
<div class="summary-row">
|
||||||
|
<span class="summary-label">Horario actual:</span>
|
||||||
|
<span class="summary-value font-medium">${formatDateTime(booking.scheduled_at)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="reschedule-form" class="modal-form-content mt-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label font-semibold">Nuevo Horario Propuesto:</label>
|
||||||
|
<div class="datetime-grid">
|
||||||
|
<div class="form-subgroup">
|
||||||
|
<label for="reschedule-date" class="form-sublabel">Nueva Fecha:</label>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
id="reschedule-date"
|
||||||
|
class="form-input"
|
||||||
|
value="${defaultDate}"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="form-subgroup">
|
||||||
|
<label for="reschedule-time" class="form-sublabel">Nueva Hora:</label>
|
||||||
|
<input
|
||||||
|
type="time"
|
||||||
|
id="reschedule-time"
|
||||||
|
class="form-input"
|
||||||
|
value="${defaultTime}"
|
||||||
|
step="900"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="reschedule-notes" class="form-label font-semibold">
|
||||||
|
Motivo de Reagendación (opcional):
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
id="reschedule-notes"
|
||||||
|
class="form-textarea"
|
||||||
|
rows="2"
|
||||||
|
placeholder="Ej. Solicitado por el consultante..."
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="reschedule-error" class="modal-error-box hidden" role="alert"></div>
|
||||||
|
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button type="button" id="reschedule-cancel-btn" class="btn btn-secondary">
|
||||||
|
Cancelar
|
||||||
|
</button>
|
||||||
|
<button type="submit" id="reschedule-submit-btn" class="btn btn-primary">
|
||||||
|
Confirmar Nuevo Horario
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.body.appendChild(backdrop);
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
backdrop.remove();
|
||||||
|
document.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Escape") close();
|
||||||
|
};
|
||||||
|
document.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
backdrop
|
||||||
|
.querySelector("#reschedule-modal-close")
|
||||||
|
?.addEventListener("click", () => close());
|
||||||
|
backdrop
|
||||||
|
.querySelector("#reschedule-cancel-btn")
|
||||||
|
?.addEventListener("click", () => close());
|
||||||
|
backdrop.addEventListener("click", (e) => {
|
||||||
|
if (e.target === backdrop) close();
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = backdrop.querySelector<HTMLFormElement>("#reschedule-form");
|
||||||
|
const dateInput =
|
||||||
|
backdrop.querySelector<HTMLInputElement>("#reschedule-date");
|
||||||
|
const timeInput =
|
||||||
|
backdrop.querySelector<HTMLInputElement>("#reschedule-time");
|
||||||
|
const notesInput =
|
||||||
|
backdrop.querySelector<HTMLTextAreaElement>("#reschedule-notes");
|
||||||
|
const submitBtn = backdrop.querySelector<HTMLButtonElement>(
|
||||||
|
"#reschedule-submit-btn",
|
||||||
|
);
|
||||||
|
const errorBox = backdrop.querySelector<HTMLDivElement>("#reschedule-error");
|
||||||
|
|
||||||
|
form?.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!submitBtn || !errorBox) return;
|
||||||
|
|
||||||
|
const dVal = dateInput?.value;
|
||||||
|
const tVal = timeInput?.value;
|
||||||
|
const notes = notesInput?.value.trim() || undefined;
|
||||||
|
|
||||||
|
if (!dVal || !tVal) {
|
||||||
|
errorBox.textContent = "Por favor selecciona la nueva fecha y hora.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newDt = new Date(`${dVal}T${tVal}:00`);
|
||||||
|
if (Number.isNaN(newDt.getTime())) {
|
||||||
|
errorBox.textContent = "Fecha u hora inválida.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
submitBtn.disabled = true;
|
||||||
|
submitBtn.textContent = "Reagendando...";
|
||||||
|
errorBox.classList.add("hidden");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updated = await rescheduleBooking(booking.id, {
|
||||||
|
new_scheduled_at: newDt.toISOString(),
|
||||||
|
notes,
|
||||||
|
});
|
||||||
|
close();
|
||||||
|
onSuccess(updated);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
submitBtn.textContent = "Confirmar Nuevo Horario";
|
||||||
|
errorBox.textContent =
|
||||||
|
err instanceof Error ? err.message : "Error al reagendar la consulta.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,569 @@
|
|||||||
|
import { createBooking, fetchServices, searchClients } from "../api";
|
||||||
|
import type { Booking, Client, Service } from "../types";
|
||||||
|
import {
|
||||||
|
debounce,
|
||||||
|
formatCurrency,
|
||||||
|
formatDateInput,
|
||||||
|
formatMexicanPhone,
|
||||||
|
} from "../utils";
|
||||||
|
import { showToast } from "./Toast";
|
||||||
|
|
||||||
|
export interface IntakeModalOptions {
|
||||||
|
onSuccess: (booking: Booking) => void;
|
||||||
|
defaultDate?: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function openBookingIntakeModal(options: IntakeModalOptions): void {
|
||||||
|
const { onSuccess, defaultDate = new Date() } = options;
|
||||||
|
|
||||||
|
const existingBackdrop = document.getElementById("intake-modal-backdrop");
|
||||||
|
if (existingBackdrop) existingBackdrop.remove();
|
||||||
|
|
||||||
|
const backdrop = document.createElement("div");
|
||||||
|
backdrop.id = "intake-modal-backdrop";
|
||||||
|
backdrop.className = "modal-backdrop intake-modal-backdrop";
|
||||||
|
|
||||||
|
const defaultDateStr = formatDateInput(defaultDate);
|
||||||
|
// Default time: next hour or 10:00
|
||||||
|
const currentHour = new Date().getHours();
|
||||||
|
const nextHour = Math.min(20, Math.max(9, currentHour + 1));
|
||||||
|
const defaultTimeStr = `${String(nextHour).padStart(2, "0")}:00`;
|
||||||
|
|
||||||
|
backdrop.innerHTML = `
|
||||||
|
<div class="modal-card modal-card-lg" role="dialog" aria-modal="true" aria-labelledby="intake-modal-title">
|
||||||
|
<div class="modal-header">
|
||||||
|
<div>
|
||||||
|
<span class="modal-kicker">Recepción Operativa</span>
|
||||||
|
<h3 id="intake-modal-title" class="modal-title">+ Nueva Cita</h3>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="modal-close-btn" id="intake-modal-close" aria-label="Cerrar ventana">×</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<p class="modal-subtitle-text">
|
||||||
|
Registra una cita directa. Se aplicará la validación de colisiones y buffer de 15 minutos obligatorio.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form id="intake-form" class="modal-form-content">
|
||||||
|
<!-- 1. Servicio -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="intake-service" class="form-label font-semibold">
|
||||||
|
1. Servicio <span class="text-danger">*</span>
|
||||||
|
</label>
|
||||||
|
<select id="intake-service" name="service_id" class="form-select" required>
|
||||||
|
<option value="">Cargando servicios...</option>
|
||||||
|
</select>
|
||||||
|
<div id="service-preview-hint" class="service-preview-hint text-xs text-muted mt-1"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 2. Cliente Search Combobox -->
|
||||||
|
<div class="form-group client-combobox-group">
|
||||||
|
<div class="combobox-label-row">
|
||||||
|
<label for="client-search-input" class="form-label font-semibold">
|
||||||
|
2. Paciente / Consultante <span class="text-danger">*</span>
|
||||||
|
</label>
|
||||||
|
<span id="client-type-badge" class="client-type-badge badge-new">✦ Nuevo Consultante</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="combobox-wrapper">
|
||||||
|
<div class="combobox-input-container">
|
||||||
|
<span class="combobox-icon" aria-hidden="true">🔍</span>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="client-search-input"
|
||||||
|
class="form-input combobox-input"
|
||||||
|
placeholder="Buscar por nombre o teléfono, o escribir uno nuevo..."
|
||||||
|
autocomplete="off"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<button type="button" id="clear-client-btn" class="btn-clear-input hidden" title="Limpiar selección">×</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Autocomplete dropdown list -->
|
||||||
|
<div id="combobox-dropdown" class="combobox-dropdown hidden" role="listbox"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="client-fields-grid mt-2">
|
||||||
|
<div class="form-subgroup">
|
||||||
|
<label for="client-phone-input" class="form-sublabel">Teléfono WhatsApp (+52) <span class="text-danger">*</span></label>
|
||||||
|
<input
|
||||||
|
type="tel"
|
||||||
|
id="client-phone-input"
|
||||||
|
name="client_phone"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="+52 55 1234 5678"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="form-subgroup">
|
||||||
|
<label for="client-email-input" class="form-sublabel">Correo Electrónico (opcional)</label>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
id="client-email-input"
|
||||||
|
name="client_email"
|
||||||
|
class="form-input"
|
||||||
|
placeholder="correo@ejemplo.com"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 3. Fecha y Hora -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="form-label font-semibold">
|
||||||
|
3. Fecha y Horario <span class="text-danger">*</span>
|
||||||
|
</label>
|
||||||
|
<div class="datetime-grid">
|
||||||
|
<div class="form-subgroup">
|
||||||
|
<label for="intake-date" class="form-sublabel">Día de la cita:</label>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
id="intake-date"
|
||||||
|
class="form-input"
|
||||||
|
value="${defaultDateStr}"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="form-subgroup">
|
||||||
|
<label for="intake-time" class="form-sublabel">Hora de inicio:</label>
|
||||||
|
<input
|
||||||
|
type="time"
|
||||||
|
id="intake-time"
|
||||||
|
class="form-input"
|
||||||
|
value="${defaultTimeStr}"
|
||||||
|
step="900"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 4. Notas u Observaciones -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="intake-notes" class="form-label font-semibold">
|
||||||
|
4. Motivo de Consulta u Observaciones (opcional)
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
id="intake-notes"
|
||||||
|
name="notes"
|
||||||
|
class="form-textarea"
|
||||||
|
rows="2"
|
||||||
|
placeholder="Ej. Primera vez con dolor lumbar; recomendada por María."
|
||||||
|
></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Error container -->
|
||||||
|
<div id="intake-error" class="modal-error-box hidden" role="alert"></div>
|
||||||
|
|
||||||
|
<!-- Modal actions -->
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button type="button" id="intake-cancel-btn" class="btn btn-secondary">
|
||||||
|
Cancelar
|
||||||
|
</button>
|
||||||
|
<button type="submit" id="intake-submit-btn" class="btn btn-primary btn-submit-intake">
|
||||||
|
<span>✓ Agendar Cita</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.body.appendChild(backdrop);
|
||||||
|
|
||||||
|
const close = () => {
|
||||||
|
backdrop.remove();
|
||||||
|
document.removeEventListener("keydown", handleKeyDown);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Escape") close();
|
||||||
|
};
|
||||||
|
document.addEventListener("keydown", handleKeyDown);
|
||||||
|
|
||||||
|
backdrop
|
||||||
|
.querySelector("#intake-modal-close")
|
||||||
|
?.addEventListener("click", () => close());
|
||||||
|
backdrop
|
||||||
|
.querySelector("#intake-cancel-btn")
|
||||||
|
?.addEventListener("click", () => close());
|
||||||
|
backdrop.addEventListener("click", (e) => {
|
||||||
|
if (e.target === backdrop) close();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Elements
|
||||||
|
const form = backdrop.querySelector<HTMLFormElement>("#intake-form");
|
||||||
|
const serviceSelect =
|
||||||
|
backdrop.querySelector<HTMLSelectElement>("#intake-service");
|
||||||
|
const serviceHint = backdrop.querySelector<HTMLDivElement>(
|
||||||
|
"#service-preview-hint",
|
||||||
|
);
|
||||||
|
const searchInput = backdrop.querySelector<HTMLInputElement>(
|
||||||
|
"#client-search-input",
|
||||||
|
);
|
||||||
|
const phoneInput = backdrop.querySelector<HTMLInputElement>(
|
||||||
|
"#client-phone-input",
|
||||||
|
);
|
||||||
|
const emailInput = backdrop.querySelector<HTMLInputElement>(
|
||||||
|
"#client-email-input",
|
||||||
|
);
|
||||||
|
const clientBadge =
|
||||||
|
backdrop.querySelector<HTMLSpanElement>("#client-type-badge");
|
||||||
|
const clearClientBtn =
|
||||||
|
backdrop.querySelector<HTMLButtonElement>("#clear-client-btn");
|
||||||
|
const dropdown = backdrop.querySelector<HTMLDivElement>("#combobox-dropdown");
|
||||||
|
const dateInput = backdrop.querySelector<HTMLInputElement>("#intake-date");
|
||||||
|
const timeInput = backdrop.querySelector<HTMLInputElement>("#intake-time");
|
||||||
|
const notesInput =
|
||||||
|
backdrop.querySelector<HTMLTextAreaElement>("#intake-notes");
|
||||||
|
const errorBox = backdrop.querySelector<HTMLDivElement>("#intake-error");
|
||||||
|
const submitBtn =
|
||||||
|
backdrop.querySelector<HTMLButtonElement>("#intake-submit-btn");
|
||||||
|
|
||||||
|
let availableServices: Service[] = [];
|
||||||
|
let selectedClient: Client | null = null;
|
||||||
|
|
||||||
|
// 1. Load Services
|
||||||
|
fetchServices(true)
|
||||||
|
.then((services) => {
|
||||||
|
availableServices = services;
|
||||||
|
if (!serviceSelect) return;
|
||||||
|
if (services.length === 0) {
|
||||||
|
serviceSelect.innerHTML =
|
||||||
|
'<option value="">No hay servicios activos</option>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceSelect.innerHTML = `
|
||||||
|
<option value="">-- Selecciona un servicio --</option>
|
||||||
|
${services
|
||||||
|
.map(
|
||||||
|
(s) => `
|
||||||
|
<option value="${s.id}" data-duration="${s.duration_minutes}" data-buffer="${s.buffer_minutes}" data-price="${s.price_mxn}">
|
||||||
|
${s.name} (${s.modality === "PRESENCIAL" ? "Presencial" : "En Línea"}) — ${s.duration_minutes} min — ${formatCurrency(s.price_mxn)}
|
||||||
|
</option>
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.join("")}
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Auto-select first service if available
|
||||||
|
if (services.length > 0) {
|
||||||
|
serviceSelect.value = services[0].id;
|
||||||
|
updateServiceHint(services[0]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (serviceSelect) {
|
||||||
|
serviceSelect.innerHTML =
|
||||||
|
'<option value="">Error al cargar catálogo</option>';
|
||||||
|
}
|
||||||
|
if (errorBox) {
|
||||||
|
errorBox.textContent = `Error al cargar servicios: ${err instanceof Error ? err.message : "Desconocido"}`;
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateServiceHint = (svc?: Service) => {
|
||||||
|
if (!serviceHint) return;
|
||||||
|
if (!svc) {
|
||||||
|
serviceHint.innerHTML = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
serviceHint.innerHTML = `
|
||||||
|
⏱️ Duración: <strong>${svc.duration_minutes} min</strong> + <strong>${svc.buffer_minutes || 15} min</strong> de colchón obligatorio protegido.
|
||||||
|
${svc.price_mxn ? `• Tarifa: <strong>${formatCurrency(svc.price_mxn)}</strong>` : ""}
|
||||||
|
`;
|
||||||
|
};
|
||||||
|
|
||||||
|
serviceSelect?.addEventListener("change", () => {
|
||||||
|
const sId = serviceSelect.value;
|
||||||
|
const svc = availableServices.find((s) => s.id === sId);
|
||||||
|
updateServiceHint(svc);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Client Combobox & Autocomplete
|
||||||
|
const selectExistingClient = (c: Client) => {
|
||||||
|
selectedClient = c;
|
||||||
|
if (searchInput) searchInput.value = c.full_name;
|
||||||
|
if (phoneInput) phoneInput.value = formatMexicanPhone(c.phone_whatsapp);
|
||||||
|
if (emailInput) emailInput.value = c.email || "";
|
||||||
|
if (clientBadge) {
|
||||||
|
clientBadge.textContent = "✓ Cliente Registrado";
|
||||||
|
clientBadge.className = "client-type-badge badge-existing";
|
||||||
|
}
|
||||||
|
clearClientBtn?.classList.remove("hidden");
|
||||||
|
hideDropdown();
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearSelectedClient = () => {
|
||||||
|
selectedClient = null;
|
||||||
|
if (searchInput) searchInput.value = "";
|
||||||
|
if (phoneInput) phoneInput.value = "";
|
||||||
|
if (emailInput) emailInput.value = "";
|
||||||
|
if (clientBadge) {
|
||||||
|
clientBadge.textContent = "✦ Nuevo Consultante";
|
||||||
|
clientBadge.className = "client-type-badge badge-new";
|
||||||
|
}
|
||||||
|
clearClientBtn?.classList.add("hidden");
|
||||||
|
hideDropdown();
|
||||||
|
searchInput?.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
clearClientBtn?.addEventListener("click", clearSelectedClient);
|
||||||
|
|
||||||
|
const hideDropdown = () => {
|
||||||
|
if (dropdown) dropdown.classList.add("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
const showDropdown = () => {
|
||||||
|
if (dropdown) dropdown.classList.remove("hidden");
|
||||||
|
};
|
||||||
|
|
||||||
|
const doSearch = debounce(async (query: string) => {
|
||||||
|
const q = query.trim();
|
||||||
|
if (!q || !dropdown) {
|
||||||
|
hideDropdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const results = await searchClients(q);
|
||||||
|
if (results.length === 0) {
|
||||||
|
dropdown.innerHTML = `
|
||||||
|
<div class="combobox-empty">
|
||||||
|
No se encontraron pacientes para "<strong>${escapeHtml(q)}</strong>".
|
||||||
|
<span class="text-xs text-muted block mt-1">Se registrará como nuevo paciente con los datos ingresados.</span>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
showDropdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dropdown.innerHTML = results
|
||||||
|
.map(
|
||||||
|
(c) => `
|
||||||
|
<div class="combobox-item" role="option" data-id="${c.id}">
|
||||||
|
<div class="font-medium">${escapeHtml(c.full_name)}</div>
|
||||||
|
<div class="combobox-meta text-xs text-muted">
|
||||||
|
<span>📱 ${escapeHtml(c.phone_whatsapp)}</span>
|
||||||
|
${c.email ? `<span>✉️ ${escapeHtml(c.email)}</span>` : ""}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
)
|
||||||
|
.join("");
|
||||||
|
|
||||||
|
dropdown.querySelectorAll(".combobox-item").forEach((item) => {
|
||||||
|
item.addEventListener("click", () => {
|
||||||
|
const id = item.getAttribute("data-id");
|
||||||
|
const found = results.find((r) => r.id === id);
|
||||||
|
if (found) {
|
||||||
|
selectExistingClient(found);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
showDropdown();
|
||||||
|
} catch {
|
||||||
|
// Ignore autocomplete failure
|
||||||
|
}
|
||||||
|
}, 250);
|
||||||
|
|
||||||
|
searchInput?.addEventListener("input", () => {
|
||||||
|
const val = searchInput.value;
|
||||||
|
if (selectedClient && val !== selectedClient.full_name) {
|
||||||
|
selectedClient = null;
|
||||||
|
if (clientBadge) {
|
||||||
|
clientBadge.textContent = "✦ Nuevo Consultante";
|
||||||
|
clientBadge.className = "client-type-badge badge-new";
|
||||||
|
}
|
||||||
|
clearClientBtn?.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
doSearch(val);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Auto format Mexican phone on blur
|
||||||
|
phoneInput?.addEventListener("blur", () => {
|
||||||
|
if (phoneInput.value) {
|
||||||
|
phoneInput.value = formatMexicanPhone(phoneInput.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Close dropdown when clicking outside
|
||||||
|
document.addEventListener("click", (e) => {
|
||||||
|
if (
|
||||||
|
dropdown &&
|
||||||
|
!dropdown.contains(e.target as Node) &&
|
||||||
|
e.target !== searchInput
|
||||||
|
) {
|
||||||
|
hideDropdown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. Form Submit
|
||||||
|
form?.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!submitBtn || !errorBox) return;
|
||||||
|
|
||||||
|
errorBox.classList.add("hidden");
|
||||||
|
errorBox.textContent = "";
|
||||||
|
|
||||||
|
const serviceId = serviceSelect?.value;
|
||||||
|
const clientName = searchInput?.value.trim();
|
||||||
|
let clientPhone = phoneInput?.value.trim();
|
||||||
|
const clientEmail = emailInput?.value.trim() || undefined;
|
||||||
|
const dateVal = dateInput?.value;
|
||||||
|
const timeVal = timeInput?.value;
|
||||||
|
const notesVal = notesInput?.value.trim() || undefined;
|
||||||
|
|
||||||
|
if (!serviceId) {
|
||||||
|
errorBox.textContent = "Por favor selecciona un servicio.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!clientName || !clientPhone) {
|
||||||
|
errorBox.textContent =
|
||||||
|
"El nombre y teléfono de WhatsApp del consultante son obligatorios.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure formatted phone
|
||||||
|
clientPhone = formatMexicanPhone(clientPhone);
|
||||||
|
|
||||||
|
if (!dateVal || !timeVal) {
|
||||||
|
errorBox.textContent = "Por favor define la fecha y hora de la cita.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build scheduled_at in ISO format
|
||||||
|
const localDateTimeString = `${dateVal}T${timeVal}:00`;
|
||||||
|
const scheduledDate = new Date(localDateTimeString);
|
||||||
|
if (Number.isNaN(scheduledDate.getTime())) {
|
||||||
|
errorBox.textContent = "La fecha u hora seleccionada no es válida.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
submitBtn.disabled = true;
|
||||||
|
submitBtn.textContent = "Agendando sesión...";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const booking = await createBooking({
|
||||||
|
service_id: serviceId,
|
||||||
|
client_name: clientName,
|
||||||
|
client_phone: clientPhone,
|
||||||
|
client_email: clientEmail,
|
||||||
|
scheduled_at: scheduledDate.toISOString(),
|
||||||
|
notes: notesVal,
|
||||||
|
});
|
||||||
|
|
||||||
|
close();
|
||||||
|
onSuccess(booking);
|
||||||
|
|
||||||
|
// Toast with Folio
|
||||||
|
showToast(
|
||||||
|
`Cita agendada para ${booking.client_name || clientName}`,
|
||||||
|
"success",
|
||||||
|
6000,
|
||||||
|
{ folio: booking.booking_code },
|
||||||
|
);
|
||||||
|
|
||||||
|
// 1-Tap WhatsApp confirmation dialog
|
||||||
|
showBookingCreatedSuccessModal(booking);
|
||||||
|
} catch (err: unknown) {
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
submitBtn.textContent = "✓ Agendar Cita";
|
||||||
|
errorBox.textContent =
|
||||||
|
err instanceof Error
|
||||||
|
? err.message
|
||||||
|
: "Error inesperado al registrar la cita.";
|
||||||
|
errorBox.classList.remove("hidden");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Focus first input
|
||||||
|
searchInput?.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function showBookingCreatedSuccessModal(booking: Booking): void {
|
||||||
|
const waUrl =
|
||||||
|
booking.whatsapp_redirect_url ||
|
||||||
|
`https://wa.me/${(booking.client_phone || "").replace(/\D/g, "")}?text=${encodeURIComponent(
|
||||||
|
`Hola ${booking.client_name || ""}, te confirmamos tu cita en Armonía del Ser con folio ${booking.booking_code}. ¡Te esperamos!`,
|
||||||
|
)}`;
|
||||||
|
|
||||||
|
const modal = document.createElement("div");
|
||||||
|
modal.className = "modal-backdrop";
|
||||||
|
modal.innerHTML = `
|
||||||
|
<div class="modal-card" role="dialog" aria-modal="true">
|
||||||
|
<div class="modal-header">
|
||||||
|
<div>
|
||||||
|
<span class="modal-kicker text-success">✓ Cita Confirmada</span>
|
||||||
|
<h3 class="modal-title">Folio ${booking.booking_code}</h3>
|
||||||
|
</div>
|
||||||
|
<button type="button" class="modal-close-btn" id="success-modal-close">×</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="summary-box">
|
||||||
|
<div class="summary-row">
|
||||||
|
<span class="summary-label">Paciente:</span>
|
||||||
|
<span class="summary-value font-semibold">${booking.client_name}</span>
|
||||||
|
</div>
|
||||||
|
<div class="summary-row">
|
||||||
|
<span class="summary-label">Servicio:</span>
|
||||||
|
<span class="summary-value">${booking.service_name || "Consulta"}</span>
|
||||||
|
</div>
|
||||||
|
<div class="summary-row">
|
||||||
|
<span class="summary-label">Fecha y Hora:</span>
|
||||||
|
<span class="summary-value font-medium">${new Date(booking.scheduled_at).toLocaleString("es-MX", { dateStyle: "long", timeStyle: "short" })}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="modal-subtitle-text mt-3">
|
||||||
|
La cita ha sido reservada y el buffer protector ha sido bloqueado en el sistema.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="modal-actions mt-4">
|
||||||
|
<a
|
||||||
|
href="${waUrl}"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
id="btn-send-wa-confirm"
|
||||||
|
class="btn btn-whatsapp"
|
||||||
|
>
|
||||||
|
<span>💬 Enviar Confirmación por WhatsApp</span>
|
||||||
|
</a>
|
||||||
|
<button type="button" id="success-modal-dismiss" class="btn btn-secondary">
|
||||||
|
Listo
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
document.body.appendChild(modal);
|
||||||
|
|
||||||
|
const closeSuccess = () => modal.remove();
|
||||||
|
modal
|
||||||
|
.querySelector("#success-modal-close")
|
||||||
|
?.addEventListener("click", closeSuccess);
|
||||||
|
modal
|
||||||
|
.querySelector("#success-modal-dismiss")
|
||||||
|
?.addEventListener("click", closeSuccess);
|
||||||
|
modal.querySelector("#btn-send-wa-confirm")?.addEventListener("click", () => {
|
||||||
|
setTimeout(closeSuccess, 500);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHtml(str: string): string {
|
||||||
|
return str
|
||||||
|
.replace(/&/g, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """)
|
||||||
|
.replace(/'/g, "'");
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { acknowledgePayment } from "../api";
|
||||||
import type { Booking } from "../types";
|
import type { Booking } from "../types";
|
||||||
import { formatCurrency } from "../utils";
|
import { formatCurrency } from "../utils";
|
||||||
|
|
||||||
@@ -161,7 +162,6 @@ export function openPaymentModal(options: {
|
|||||||
const notes = notesInput?.value.trim() || undefined;
|
const notes = notesInput?.value.trim() || undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { acknowledgePayment } = await import("../api");
|
|
||||||
await acknowledgePayment({
|
await acknowledgePayment({
|
||||||
booking_id: booking.id,
|
booking_id: booking.id,
|
||||||
amount_mxn: amount,
|
amount_mxn: amount,
|
||||||
|
|||||||
+100
-9
@@ -1,10 +1,13 @@
|
|||||||
import "./style.css";
|
import "./style.css";
|
||||||
import { fetchFollowUpQueue } from "./api";
|
import { fetchCurrentAdmin, fetchFollowUpQueue } from "./api";
|
||||||
import { renderAllBookings } from "./components/AllBookings";
|
import { renderAllBookings } from "./components/AllBookings";
|
||||||
|
import { renderClientDirectory } from "./components/ClientDirectory";
|
||||||
import { renderDailyAgenda } from "./components/DailyAgenda";
|
import { renderDailyAgenda } from "./components/DailyAgenda";
|
||||||
import { renderFollowUpQueue } from "./components/FollowUpQueue";
|
import { renderFollowUpQueue } from "./components/FollowUpQueue";
|
||||||
|
import { openBookingIntakeModal } from "./components/IntakeModal";
|
||||||
|
import { getRoleBadge } from "./utils";
|
||||||
|
|
||||||
type TabId = "queue" | "agenda" | "all";
|
type TabId = "queue" | "agenda" | "clients" | "all";
|
||||||
|
|
||||||
class OperatorDashboardApp {
|
class OperatorDashboardApp {
|
||||||
private activeTab: TabId = "queue";
|
private activeTab: TabId = "queue";
|
||||||
@@ -22,11 +25,27 @@ class OperatorDashboardApp {
|
|||||||
private async init(): Promise<void> {
|
private async init(): Promise<void> {
|
||||||
this.renderShell();
|
this.renderShell();
|
||||||
this.bindEvents();
|
this.bindEvents();
|
||||||
|
await Promise.allSettled([
|
||||||
|
this.loadOperatorIdentity(),
|
||||||
|
this.refreshTabBadge(),
|
||||||
|
]);
|
||||||
|
const hash = window.location.hash.replace("#", "") as TabId | "nueva-cita";
|
||||||
|
if (hash === "nueva-cita") {
|
||||||
|
this.switchTab("agenda");
|
||||||
|
openBookingIntakeModal({
|
||||||
|
onSuccess: async () => {
|
||||||
await this.refreshTabBadge();
|
await this.refreshTabBadge();
|
||||||
const hash = window.location.hash.replace("#", "") as TabId;
|
this.switchTab(this.activeTab);
|
||||||
const initialTab = hash === "agenda" || hash === "all" ? hash : "queue";
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const initialTab =
|
||||||
|
hash === "agenda" || hash === "clients" || hash === "all"
|
||||||
|
? hash
|
||||||
|
: "queue";
|
||||||
this.switchTab(initialTab);
|
this.switchTab(initialTab);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private renderShell(): void {
|
private renderShell(): void {
|
||||||
this.container.innerHTML = `
|
this.container.innerHTML = `
|
||||||
@@ -39,10 +58,22 @@ class OperatorDashboardApp {
|
|||||||
</div>
|
</div>
|
||||||
<span class="brand-badge">Operador</span>
|
<span class="brand-badge">Operador</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="operator-profile">
|
|
||||||
<div class="operator-badge">
|
<div class="header-actions">
|
||||||
<span class="status-dot"></span>
|
<button
|
||||||
<span>Jasmin & Asistente</span>
|
id="global-new-booking-btn"
|
||||||
|
class="btn btn-primary btn-new-booking"
|
||||||
|
type="button"
|
||||||
|
title="Registrar una nueva reservación de consulta"
|
||||||
|
>
|
||||||
|
<span>+ Nueva Cita</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div id="operator-profile" class="operator-profile" aria-live="polite">
|
||||||
|
<div class="operator-badge operator-badge-loading">
|
||||||
|
<span class="status-dot status-dot-pulse"></span>
|
||||||
|
<span class="operator-name-text">Cargando operador...</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
@@ -56,6 +87,9 @@ class OperatorDashboardApp {
|
|||||||
<button class="nav-tab" data-tab="agenda" role="tab" aria-selected="false">
|
<button class="nav-tab" data-tab="agenda" role="tab" aria-selected="false">
|
||||||
<span>Agenda del Día (Buffers)</span>
|
<span>Agenda del Día (Buffers)</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button class="nav-tab" data-tab="clients" role="tab" aria-selected="false">
|
||||||
|
<span>Clientes</span>
|
||||||
|
</button>
|
||||||
<button class="nav-tab" data-tab="all" role="tab" aria-selected="false">
|
<button class="nav-tab" data-tab="all" role="tab" aria-selected="false">
|
||||||
<span>Todas las Citas</span>
|
<span>Todas las Citas</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -75,6 +109,10 @@ class OperatorDashboardApp {
|
|||||||
<span class="mobile-nav-icon" aria-hidden="true">📅</span>
|
<span class="mobile-nav-icon" aria-hidden="true">📅</span>
|
||||||
<span class="mobile-nav-label">Agenda</span>
|
<span class="mobile-nav-label">Agenda</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button class="mobile-nav-item" data-tab="clients" role="tab" aria-selected="false">
|
||||||
|
<span class="mobile-nav-icon" aria-hidden="true">👥</span>
|
||||||
|
<span class="mobile-nav-label">Clientes</span>
|
||||||
|
</button>
|
||||||
<button class="mobile-nav-item" data-tab="all" role="tab" aria-selected="false">
|
<button class="mobile-nav-item" data-tab="all" role="tab" aria-selected="false">
|
||||||
<span class="mobile-nav-icon" aria-hidden="true">📋</span>
|
<span class="mobile-nav-icon" aria-hidden="true">📋</span>
|
||||||
<span class="mobile-nav-label">Historial</span>
|
<span class="mobile-nav-label">Historial</span>
|
||||||
@@ -83,7 +121,52 @@ class OperatorDashboardApp {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async loadOperatorIdentity(): Promise<void> {
|
||||||
|
const profileEl =
|
||||||
|
this.container.querySelector<HTMLElement>("#operator-profile");
|
||||||
|
if (!profileEl) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const admin = await fetchCurrentAdmin();
|
||||||
|
const roleInfo = getRoleBadge(admin.role);
|
||||||
|
|
||||||
|
profileEl.innerHTML = `
|
||||||
|
<div class="operator-badge operator-badge-authenticated" title="Sesión activa: ${admin.email}">
|
||||||
|
<span class="status-dot status-dot-online"></span>
|
||||||
|
<span class="operator-name font-medium">${admin.full_name}</span>
|
||||||
|
<span class="operator-role-pill ${roleInfo.roleClass}">
|
||||||
|
${roleInfo.label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} catch {
|
||||||
|
// Graceful fallback if unauthorized or loading error
|
||||||
|
profileEl.innerHTML = `
|
||||||
|
<div class="operator-badge operator-badge-fallback" title="Sesión local o sin conexión">
|
||||||
|
<span class="status-dot status-dot-offline"></span>
|
||||||
|
<span class="operator-name">Jasmin & Asistente</span>
|
||||||
|
<span class="operator-role-pill role-fallback">Local</span>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bindEvents(): void {
|
private bindEvents(): void {
|
||||||
|
// New Booking Button
|
||||||
|
const newBookingBtn = this.container.querySelector<HTMLButtonElement>(
|
||||||
|
"#global-new-booking-btn",
|
||||||
|
);
|
||||||
|
newBookingBtn?.addEventListener("click", () => {
|
||||||
|
openBookingIntakeModal({
|
||||||
|
onSuccess: async () => {
|
||||||
|
await this.refreshTabBadge();
|
||||||
|
// Refresh current view
|
||||||
|
this.switchTab(this.activeTab);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tab Switching Buttons
|
||||||
const allTabButtons =
|
const allTabButtons =
|
||||||
this.container.querySelectorAll<HTMLButtonElement>("[data-tab]");
|
this.container.querySelectorAll<HTMLButtonElement>("[data-tab]");
|
||||||
allTabButtons.forEach((btn) => {
|
allTabButtons.forEach((btn) => {
|
||||||
@@ -95,9 +178,15 @@ class OperatorDashboardApp {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Hash routing
|
||||||
window.addEventListener("hashchange", () => {
|
window.addEventListener("hashchange", () => {
|
||||||
const hash = window.location.hash.replace("#", "") as TabId;
|
const hash = window.location.hash.replace("#", "") as TabId;
|
||||||
if (hash === "queue" || hash === "agenda" || hash === "all") {
|
if (
|
||||||
|
hash === "queue" ||
|
||||||
|
hash === "agenda" ||
|
||||||
|
hash === "clients" ||
|
||||||
|
hash === "all"
|
||||||
|
) {
|
||||||
if (this.activeTab !== hash) {
|
if (this.activeTab !== hash) {
|
||||||
this.switchTab(hash);
|
this.switchTab(hash);
|
||||||
}
|
}
|
||||||
@@ -130,6 +219,8 @@ class OperatorDashboardApp {
|
|||||||
renderFollowUpQueue(contentEl, onStateChange);
|
renderFollowUpQueue(contentEl, onStateChange);
|
||||||
} else if (tab === "agenda") {
|
} else if (tab === "agenda") {
|
||||||
renderDailyAgenda(contentEl, onStateChange);
|
renderDailyAgenda(contentEl, onStateChange);
|
||||||
|
} else if (tab === "clients") {
|
||||||
|
renderClientDirectory(contentEl, onStateChange);
|
||||||
} else if (tab === "all") {
|
} else if (tab === "all") {
|
||||||
renderAllBookings(contentEl);
|
renderAllBookings(contentEl);
|
||||||
}
|
}
|
||||||
|
|||||||
+415
-2
@@ -109,16 +109,96 @@ body {
|
|||||||
margin-left: 8px;
|
margin-left: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.operator-badge {
|
.header-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-new-booking {
|
||||||
|
min-height: 44px;
|
||||||
|
padding: 8px 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
|
box-shadow: var(--shadow-sm);
|
||||||
|
transition: all 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-new-booking:hover {
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: var(--shadow-md);
|
||||||
|
}
|
||||||
|
|
||||||
|
.operator-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: var(--color-text-muted);
|
color: var(--color-text-main);
|
||||||
background: var(--color-surface);
|
background: var(--color-surface);
|
||||||
padding: 6px 12px;
|
padding: 6px 12px;
|
||||||
border-radius: var(--radius-md);
|
border-radius: var(--radius-md);
|
||||||
border: 1px solid var(--color-border);
|
border: 1px solid var(--color-border);
|
||||||
|
min-height: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.operator-badge-loading {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot-pulse {
|
||||||
|
animation: pulse-dot 1.5s infinite ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse-dot {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
opacity: 0.4;
|
||||||
|
transform: scale(0.9);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot-online {
|
||||||
|
background-color: var(--color-success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot-offline {
|
||||||
|
background-color: var(--color-warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
.operator-role-pill {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 700;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-owner {
|
||||||
|
background: var(--color-gold-light);
|
||||||
|
color: var(--color-gold);
|
||||||
|
border: 1px solid rgba(184, 134, 11, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-assistant {
|
||||||
|
background: var(--color-sage-light);
|
||||||
|
color: var(--color-sage);
|
||||||
|
border: 1px solid rgba(45, 90, 70, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-fallback {
|
||||||
|
background: var(--color-surface-soft);
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-dot {
|
.status-dot {
|
||||||
@@ -1376,6 +1456,339 @@ body {
|
|||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Intake Modal & Autocomplete Combobox
|
||||||
|
========================================================================== */
|
||||||
|
.modal-card-lg {
|
||||||
|
max-width: 620px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-combobox-group {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-label-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-type-badge {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 700;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 999px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-new {
|
||||||
|
background: var(--color-gold-light);
|
||||||
|
color: var(--color-gold);
|
||||||
|
border: 1px solid rgba(184, 134, 11, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-existing {
|
||||||
|
background: var(--color-success-light);
|
||||||
|
color: var(--color-success);
|
||||||
|
border: 1px solid rgba(30, 126, 78, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-wrapper {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-input-container {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-icon {
|
||||||
|
position: absolute;
|
||||||
|
left: 12px;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
pointer-events: none;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-input {
|
||||||
|
padding-left: 36px;
|
||||||
|
padding-right: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-clear-input {
|
||||||
|
position: absolute;
|
||||||
|
right: 8px;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
font-size: 18px;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 4px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-width: 36px;
|
||||||
|
min-height: 36px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-clear-input:hover {
|
||||||
|
color: var(--color-text-main);
|
||||||
|
background: var(--color-surface-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-dropdown {
|
||||||
|
position: absolute;
|
||||||
|
top: 100%;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
margin-top: 4px;
|
||||||
|
background: var(--color-surface);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
box-shadow: var(--shadow-lg);
|
||||||
|
max-height: 220px;
|
||||||
|
overflow-y: auto;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-item {
|
||||||
|
padding: 10px 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-bottom: 1px solid var(--color-border);
|
||||||
|
transition: background 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-item:hover,
|
||||||
|
.combobox-item:focus {
|
||||||
|
background: var(--color-sage-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-meta {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.combobox-empty {
|
||||||
|
padding: 12px 14px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-fields-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 580px) {
|
||||||
|
.client-fields-grid {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.datetime-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 580px) {
|
||||||
|
.datetime-grid {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-subgroup {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-sublabel {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.service-preview-hint {
|
||||||
|
background: var(--color-sage-light);
|
||||||
|
color: var(--color-sage-dark);
|
||||||
|
padding: 6px 10px;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
margin-top: 6px;
|
||||||
|
border: 1px solid rgba(45, 90, 70, 0.15);
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Agenda Card Lifecycle Actions (Mover & Concluir)
|
||||||
|
========================================================================== */
|
||||||
|
.agenda-card-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin-top: 12px;
|
||||||
|
padding-top: 10px;
|
||||||
|
border-top: 1px dashed var(--color-border);
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-outline-success {
|
||||||
|
background: transparent;
|
||||||
|
color: var(--color-success);
|
||||||
|
border: 1px solid var(--color-success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-outline-success:hover {
|
||||||
|
background: var(--color-success-light);
|
||||||
|
border-color: var(--color-success);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================
|
||||||
|
Client Directory View
|
||||||
|
========================================================================== */
|
||||||
|
.directory-search-bar {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-input-group {
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 260px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.directory-search-input {
|
||||||
|
padding-left: 36px;
|
||||||
|
padding-right: 36px;
|
||||||
|
min-height: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-icon {
|
||||||
|
position: absolute;
|
||||||
|
left: 12px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clients-counter-pill {
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.clients-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 768px) {
|
||||||
|
.clients-grid {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card {
|
||||||
|
background: var(--color-surface);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
padding: 18px;
|
||||||
|
box-shadow: var(--shadow-sm);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card-name {
|
||||||
|
font-size: 17px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--color-sage-dark);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-registered-date {
|
||||||
|
display: block;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-card-body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-contact-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-email-badge {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.packages-tags-container {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.package-pill {
|
||||||
|
display: inline-block;
|
||||||
|
background: var(--color-gold-light);
|
||||||
|
color: var(--color-gold);
|
||||||
|
border: 1px solid rgba(184, 134, 11, 0.3);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 600;
|
||||||
|
padding: 3px 8px;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-notes-box {
|
||||||
|
background: var(--color-surface-soft);
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
border-left: 3px solid var(--color-sage);
|
||||||
|
}
|
||||||
|
|
||||||
|
.notes-kicker {
|
||||||
|
color: var(--color-sage-dark);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.notes-content {
|
||||||
|
color: var(--color-text-main);
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.client-notes-empty {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
/* ==========================================================================
|
/* ==========================================================================
|
||||||
Sticky Mobile Navigation Bar & Mobile Ergonomics
|
Sticky Mobile Navigation Bar & Mobile Ergonomics
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
|
|||||||
@@ -72,3 +72,90 @@ export interface PaymentRecord {
|
|||||||
notes?: string | null;
|
notes?: string | null;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type AdminRole = "OWNER" | "ASSISTANT";
|
||||||
|
|
||||||
|
export interface AdminPrincipal {
|
||||||
|
email: string;
|
||||||
|
full_name: string;
|
||||||
|
role: AdminRole;
|
||||||
|
is_active: boolean;
|
||||||
|
last_login_at?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ServiceType = "INDIVIDUAL" | "GROUP";
|
||||||
|
export type ServiceModality = "PRESENCIAL" | "ONLINE";
|
||||||
|
|
||||||
|
export interface Service {
|
||||||
|
id: string;
|
||||||
|
slug: string;
|
||||||
|
name: string;
|
||||||
|
description?: string | null;
|
||||||
|
service_type: ServiceType;
|
||||||
|
modality: ServiceModality;
|
||||||
|
default_schedule?: string | null;
|
||||||
|
price_mxn: number;
|
||||||
|
max_capacity: number;
|
||||||
|
duration_minutes: number;
|
||||||
|
buffer_minutes: number;
|
||||||
|
is_active: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Client {
|
||||||
|
id: string;
|
||||||
|
full_name: string;
|
||||||
|
phone_whatsapp: string;
|
||||||
|
email?: string | null;
|
||||||
|
notes?: string | null;
|
||||||
|
created_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ClientUpdatePayload {
|
||||||
|
full_name?: string;
|
||||||
|
phone_whatsapp?: string;
|
||||||
|
email?: string | null;
|
||||||
|
notes?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PackageRecord {
|
||||||
|
id: string;
|
||||||
|
client_id: string;
|
||||||
|
client_name?: string | null;
|
||||||
|
client_phone?: string | null;
|
||||||
|
service_id: string;
|
||||||
|
service_name?: string | null;
|
||||||
|
total_sessions: number;
|
||||||
|
completed_sessions: number;
|
||||||
|
remaining_sessions: number;
|
||||||
|
price_paid_mxn: number;
|
||||||
|
financial_status: "PAID" | "PARTIAL" | "PENDING";
|
||||||
|
notes?: string | null;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Client360 extends Client {
|
||||||
|
active_packages: PackageRecord[];
|
||||||
|
booking_history: Booking[];
|
||||||
|
recent_bookings: Booking[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BookingCreatePayload {
|
||||||
|
service_id: string;
|
||||||
|
client_name: string;
|
||||||
|
client_phone: string;
|
||||||
|
client_email?: string | null;
|
||||||
|
scheduled_at: string;
|
||||||
|
notes?: string | null;
|
||||||
|
package_id?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BookingReschedulePayload {
|
||||||
|
new_scheduled_at: string;
|
||||||
|
notes?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BookingCompletePayload {
|
||||||
|
package_id?: string | null;
|
||||||
|
notes?: string | null;
|
||||||
|
}
|
||||||
@@ -173,3 +173,53 @@ export function checkBufferCollision(
|
|||||||
deficitMinutes,
|
deficitMinutes,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatMexicanPhone(input: string): string {
|
||||||
|
const trimmed = input.trim();
|
||||||
|
if (!trimmed) return "";
|
||||||
|
// Strip all non-digit characters
|
||||||
|
const digits = trimmed.replace(/\D/g, "");
|
||||||
|
// If 10 digits (Mexican national format, e.g. 5512345678)
|
||||||
|
if (digits.length === 10) {
|
||||||
|
return `+52 ${digits.slice(0, 2)} ${digits.slice(2, 6)} ${digits.slice(6)}`;
|
||||||
|
}
|
||||||
|
// If 12 digits starting with 52
|
||||||
|
if (digits.length === 12 && digits.startsWith("52")) {
|
||||||
|
const national = digits.slice(2);
|
||||||
|
return `+52 ${national.slice(0, 2)} ${national.slice(2, 6)} ${national.slice(6)}`;
|
||||||
|
}
|
||||||
|
// Otherwise return input as-is or cleaned
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCleanDigitsPhone(phone: string): string {
|
||||||
|
const digits = phone.replace(/\D/g, "");
|
||||||
|
if (digits.length === 10) return `52${digits}`;
|
||||||
|
return digits;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRoleBadge(role: "OWNER" | "ASSISTANT" | string): {
|
||||||
|
label: string;
|
||||||
|
roleClass: string;
|
||||||
|
} {
|
||||||
|
if (role === "OWNER") {
|
||||||
|
return { label: "Titular", roleClass: "role-owner" };
|
||||||
|
}
|
||||||
|
if (role === "ASSISTANT") {
|
||||||
|
return { label: "Asistente", roleClass: "role-assistant" };
|
||||||
|
}
|
||||||
|
return { label: role || "Operador", roleClass: "role-fallback" };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function debounce<Args extends unknown[]>(
|
||||||
|
fn: (...args: Args) => void,
|
||||||
|
delayMs = 250,
|
||||||
|
): (...args: Args) => void {
|
||||||
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||||
|
return (...args: Args) => {
|
||||||
|
if (timer) clearTimeout(timer);
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
fn(...args);
|
||||||
|
}, delayMs);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -2,9 +2,13 @@ import { describe, expect, it } from "vitest";
|
|||||||
import {
|
import {
|
||||||
calculateInterval,
|
calculateInterval,
|
||||||
checkBufferCollision,
|
checkBufferCollision,
|
||||||
|
debounce,
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
formatDateInput,
|
formatDateInput,
|
||||||
|
formatMexicanPhone,
|
||||||
|
getCleanDigitsPhone,
|
||||||
getHoursRemainingBadge,
|
getHoursRemainingBadge,
|
||||||
|
getRoleBadge,
|
||||||
isSameDay,
|
isSameDay,
|
||||||
isThisWeek,
|
isThisWeek,
|
||||||
isToday,
|
isToday,
|
||||||
@@ -102,4 +106,65 @@ describe("Frontend Utilities", () => {
|
|||||||
expect(result.deficitMinutes).toBe(30); // 15 min session + 15 min buffer
|
expect(result.deficitMinutes).toBe(30); // 15 min session + 15 min buffer
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Phone and WhatsApp Utilities", () => {
|
||||||
|
it("formats 10-digit national number to Mexican international format (+52)", () => {
|
||||||
|
expect(formatMexicanPhone("5512345678")).toBe("+52 55 1234 5678");
|
||||||
|
expect(formatMexicanPhone("55-1234-5678")).toBe("+52 55 1234 5678");
|
||||||
|
expect(formatMexicanPhone("(55) 1234 5678")).toBe("+52 55 1234 5678");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("formats 12-digit number with 52 prefix correctly", () => {
|
||||||
|
expect(formatMexicanPhone("525512345678")).toBe("+52 55 1234 5678");
|
||||||
|
expect(formatMexicanPhone("+525512345678")).toBe("+52 55 1234 5678");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns empty string on empty input", () => {
|
||||||
|
expect(formatMexicanPhone("")).toBe("");
|
||||||
|
expect(formatMexicanPhone(" ")).toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("cleans phone digits for wa.me links", () => {
|
||||||
|
expect(getCleanDigitsPhone("5512345678")).toBe("525512345678");
|
||||||
|
expect(getCleanDigitsPhone("+52 55 1234 5678")).toBe("525512345678");
|
||||||
|
expect(getCleanDigitsPhone("525512345678")).toBe("525512345678");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Operator Role Badges", () => {
|
||||||
|
it("maps OWNER to Titular with role-owner class", () => {
|
||||||
|
const badge = getRoleBadge("OWNER");
|
||||||
|
expect(badge.label).toBe("Titular");
|
||||||
|
expect(badge.roleClass).toBe("role-owner");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("maps ASSISTANT to Asistente with role-assistant class", () => {
|
||||||
|
const badge = getRoleBadge("ASSISTANT");
|
||||||
|
expect(badge.label).toBe("Asistente");
|
||||||
|
expect(badge.roleClass).toBe("role-assistant");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back gracefully for unknown roles", () => {
|
||||||
|
const badge = getRoleBadge("UNKNOWN");
|
||||||
|
expect(badge.label).toBe("UNKNOWN");
|
||||||
|
expect(badge.roleClass).toBe("role-fallback");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Debounce Utility", () => {
|
||||||
|
it("debounces calls within timeout", async () => {
|
||||||
|
let counter = 0;
|
||||||
|
const fn = debounce(() => {
|
||||||
|
counter++;
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
fn();
|
||||||
|
fn();
|
||||||
|
fn();
|
||||||
|
expect(counter).toBe(0);
|
||||||
|
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 80));
|
||||||
|
expect(counter).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user