Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fe2b6c9e6 | ||
|
|
6cbc8b53c1 |
No files matched your search
+212
-15
@@ -1,16 +1,33 @@
|
||||
import { fetchAllBookings, retryCalendarSync } from "../api";
|
||||
import type { Booking } from "../types";
|
||||
import { calculateInterval, formatCurrency, formatDateTime } from "../utils";
|
||||
import {
|
||||
calculateInterval,
|
||||
checkBufferCollision,
|
||||
formatCurrency,
|
||||
formatDateTime,
|
||||
formatTimeOnly,
|
||||
isSameDay,
|
||||
isThisWeek,
|
||||
isToday,
|
||||
isTomorrow,
|
||||
} from "../utils";
|
||||
import {
|
||||
renderBookingStatusBadge,
|
||||
renderCalendarSyncBadge,
|
||||
renderPaymentStatusBadge,
|
||||
} from "./StatusBadge";
|
||||
import { showToast } from "./Toast";
|
||||
|
||||
type AgendaDateFilter = "TODAY" | "TOMORROW" | "THIS_WEEK" | "ALL" | "CUSTOM";
|
||||
|
||||
export function renderDailyAgenda(
|
||||
container: HTMLElement,
|
||||
onStateChange: () => void,
|
||||
): void {
|
||||
let activeFilter: AgendaDateFilter = "TODAY";
|
||||
let customDateStr: string = "";
|
||||
let cachedBookings: Booking[] = [];
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="view-header">
|
||||
<div>
|
||||
@@ -24,6 +41,37 @@ export function renderDailyAgenda(
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Date Navigation & Filter Bar -->
|
||||
<div class="agenda-nav-bar">
|
||||
<div class="date-filter-group" role="tablist" aria-label="Filtro de fecha para la agenda">
|
||||
<button type="button" class="btn btn-filter-pill active" data-filter="TODAY" role="tab" aria-selected="true">
|
||||
Hoy
|
||||
</button>
|
||||
<button type="button" class="btn btn-filter-pill" data-filter="TOMORROW" role="tab" aria-selected="false">
|
||||
Mañana
|
||||
</button>
|
||||
<button type="button" class="btn btn-filter-pill" data-filter="THIS_WEEK" role="tab" aria-selected="false">
|
||||
Esta Semana
|
||||
</button>
|
||||
<button type="button" class="btn btn-filter-pill" data-filter="ALL" role="tab" aria-selected="false">
|
||||
Todas
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="custom-date-container">
|
||||
<label for="agenda-custom-date" class="date-picker-label">Día específico:</label>
|
||||
<input
|
||||
type="date"
|
||||
id="agenda-custom-date"
|
||||
class="form-input-date"
|
||||
title="Elegir una fecha específica"
|
||||
aria-label="Seleccionar fecha específica en calendario"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="agenda-filter-indicator" class="filter-indicator-banner"></div>
|
||||
|
||||
<div id="agenda-stats" class="stats-row"></div>
|
||||
|
||||
<div id="agenda-content" class="agenda-timeline">
|
||||
@@ -36,9 +84,17 @@ export function renderDailyAgenda(
|
||||
|
||||
const contentDiv = container.querySelector<HTMLDivElement>("#agenda-content");
|
||||
const statsDiv = container.querySelector<HTMLDivElement>("#agenda-stats");
|
||||
const indicatorDiv = container.querySelector<HTMLDivElement>(
|
||||
"#agenda-filter-indicator",
|
||||
);
|
||||
const refreshBtn = container.querySelector<HTMLButtonElement>(
|
||||
"#refresh-agenda-btn",
|
||||
);
|
||||
const customDateInput = container.querySelector<HTMLInputElement>(
|
||||
"#agenda-custom-date",
|
||||
);
|
||||
const filterButtons =
|
||||
container.querySelectorAll<HTMLButtonElement>(".btn-filter-pill");
|
||||
|
||||
const loadData = async () => {
|
||||
if (!contentDiv) return;
|
||||
@@ -50,8 +106,7 @@ export function renderDailyAgenda(
|
||||
|
||||
try {
|
||||
const bookings = await fetchAllBookings();
|
||||
// Filter active bookings and sort chronologically
|
||||
const activeBookings = bookings
|
||||
cachedBookings = bookings
|
||||
.filter(
|
||||
(b) =>
|
||||
b.booking_status !== "CANCELLED" && b.booking_status !== "RELEASED",
|
||||
@@ -62,8 +117,7 @@ export function renderDailyAgenda(
|
||||
new Date(b.scheduled_at).getTime(),
|
||||
);
|
||||
|
||||
renderStats(activeBookings);
|
||||
renderTimeline(activeBookings);
|
||||
applyFilter();
|
||||
} catch (err: unknown) {
|
||||
if (contentDiv) {
|
||||
contentDiv.innerHTML = `
|
||||
@@ -71,12 +125,76 @@ export function renderDailyAgenda(
|
||||
<div class="error-icon">⚠️</div>
|
||||
<h3 class="error-title">Error al cargar la agenda</h3>
|
||||
<p class="error-desc">${err instanceof Error ? err.message : "Error desconocido"}</p>
|
||||
<button id="retry-agenda-load" class="btn btn-primary btn-sm">Reintentar</button>
|
||||
</div>
|
||||
`;
|
||||
contentDiv
|
||||
.querySelector("#retry-agenda-load")
|
||||
?.addEventListener("click", () => loadData());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const filterBookings = (): Booking[] => {
|
||||
const now = new Date();
|
||||
|
||||
if (activeFilter === "TODAY") {
|
||||
return cachedBookings.filter((b) =>
|
||||
isToday(new Date(b.scheduled_at), now),
|
||||
);
|
||||
}
|
||||
if (activeFilter === "TOMORROW") {
|
||||
return cachedBookings.filter((b) =>
|
||||
isTomorrow(new Date(b.scheduled_at), now),
|
||||
);
|
||||
}
|
||||
if (activeFilter === "THIS_WEEK") {
|
||||
return cachedBookings.filter((b) =>
|
||||
isThisWeek(new Date(b.scheduled_at), now),
|
||||
);
|
||||
}
|
||||
if (activeFilter === "CUSTOM" && customDateStr) {
|
||||
const [year, month, day] = customDateStr.split("-").map(Number);
|
||||
const targetDate = new Date(year, month - 1, day);
|
||||
return cachedBookings.filter((b) =>
|
||||
isSameDay(new Date(b.scheduled_at), targetDate),
|
||||
);
|
||||
}
|
||||
return cachedBookings;
|
||||
};
|
||||
|
||||
const updateIndicator = (filteredCount: number) => {
|
||||
if (!indicatorDiv) return;
|
||||
let label = "";
|
||||
if (activeFilter === "TODAY") {
|
||||
label = `📅 Mostrando citas para: <strong>Hoy</strong> (${new Intl.DateTimeFormat("es-MX", { dateStyle: "long" }).format(new Date())})`;
|
||||
} else if (activeFilter === "TOMORROW") {
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
label = `📅 Mostrando citas para: <strong>Mañana</strong> (${new Intl.DateTimeFormat("es-MX", { dateStyle: "long" }).format(tomorrow)})`;
|
||||
} else if (activeFilter === "THIS_WEEK") {
|
||||
label = `📅 Mostrando citas para: <strong>Esta Semana</strong>`;
|
||||
} else if (activeFilter === "CUSTOM" && customDateStr) {
|
||||
const [year, month, day] = customDateStr.split("-").map(Number);
|
||||
const targetDate = new Date(year, month - 1, day);
|
||||
label = `📅 Mostrando citas para el día: <strong>${new Intl.DateTimeFormat("es-MX", { dateStyle: "long" }).format(targetDate)}</strong>`;
|
||||
} else {
|
||||
label = "📅 Mostrando: <strong>Todas las citas programadas</strong>";
|
||||
}
|
||||
|
||||
indicatorDiv.innerHTML = `
|
||||
<span>${label}</span>
|
||||
<span class="indicator-count">${filteredCount} ${filteredCount === 1 ? "cita activa" : "citas activas"}</span>
|
||||
`;
|
||||
};
|
||||
|
||||
const applyFilter = () => {
|
||||
const filtered = filterBookings();
|
||||
updateIndicator(filtered.length);
|
||||
renderStats(filtered);
|
||||
renderTimeline(filtered);
|
||||
};
|
||||
|
||||
const renderStats = (bookings: Booking[]) => {
|
||||
if (!statsDiv) return;
|
||||
const total = bookings.length;
|
||||
@@ -94,7 +212,7 @@ export function renderDailyAgenda(
|
||||
|
||||
statsDiv.innerHTML = `
|
||||
<div class="stat-card">
|
||||
<span class="stat-label">Citas Programadas</span>
|
||||
<span class="stat-label">Citas en Periodo</span>
|
||||
<span class="stat-number">${total}</span>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
@@ -119,8 +237,8 @@ export function renderDailyAgenda(
|
||||
contentDiv.innerHTML = `
|
||||
<div class="card empty-state">
|
||||
<div class="empty-icon">📅</div>
|
||||
<h3 class="empty-title">Agenda libre</h3>
|
||||
<p class="empty-desc">No hay citas activas programadas en este momento.</p>
|
||||
<h3 class="empty-title">Agenda libre en este periodo</h3>
|
||||
<p class="empty-desc">No hay citas activas programadas para el filtro seleccionado. Puedes cambiar de fecha o ver "Todas las Citas".</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
@@ -140,11 +258,45 @@ export function renderDailyAgenda(
|
||||
let collisionNotice = "";
|
||||
if (idx < bookings.length - 1) {
|
||||
const nextBooking = bookings[idx + 1];
|
||||
const nextStart = new Date(nextBooking.scheduled_at);
|
||||
if (nextStart < interval.bufferEnd) {
|
||||
const collision = checkBufferCollision(
|
||||
b.scheduled_at,
|
||||
b.duration_minutes || 60,
|
||||
b.buffer_minutes || 15,
|
||||
nextBooking.scheduled_at,
|
||||
);
|
||||
|
||||
if (collision.hasCollision) {
|
||||
const nextStartStr = formatTimeOnly(nextBooking.scheduled_at);
|
||||
collisionNotice = `
|
||||
<div class="collision-alert">
|
||||
⚠️ ADVERTENCIA: La siguiente cita (${nextBooking.booking_code}) inicia a las ${interval.endStr}, invadiendo el buffer de preparación.
|
||||
<div class="collision-alert ${collision.isDirectCollision ? "collision-critical" : "collision-warning"}" role="alert">
|
||||
<div class="collision-header">
|
||||
<span class="collision-icon">${collision.isDirectCollision ? "🛑" : "⚠️"}</span>
|
||||
<span class="collision-title font-bold">
|
||||
${collision.isDirectCollision ? "Colisión Directa entre Sesiones" : "Conflicto de Buffer Protegido"}
|
||||
</span>
|
||||
<span class="collision-deficit-pill">-${collision.deficitMinutes} min de holgura</span>
|
||||
</div>
|
||||
<div class="collision-markers">
|
||||
<div class="marker-chip">
|
||||
<span class="marker-chip-label">Término cita actual:</span>
|
||||
<span class="marker-chip-time font-mono">${interval.endStr}</span>
|
||||
</div>
|
||||
<div class="marker-chip marker-buffer">
|
||||
<span class="marker-chip-label">Buffer requerido hasta:</span>
|
||||
<span class="marker-chip-time font-mono">${interval.bufferEndStr}</span>
|
||||
</div>
|
||||
<div class="marker-chip marker-conflict">
|
||||
<span class="marker-chip-label">Inicio siguiente (${nextBooking.booking_code}):</span>
|
||||
<span class="marker-chip-time font-mono font-bold">${nextStartStr}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="collision-explainer">
|
||||
${
|
||||
collision.isDirectCollision
|
||||
? `La cita <strong>${nextBooking.booking_code}</strong> inicia antes del término de la sesión actual.`
|
||||
: `La cita <strong>${nextBooking.booking_code}</strong> invade el buffer de 15 minutos de descanso y preparación.`
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
@@ -207,21 +359,66 @@ export function renderDailyAgenda(
|
||||
btn.addEventListener("click", async () => {
|
||||
const id = btn.getAttribute("data-booking-id");
|
||||
if (!id) return;
|
||||
const origText = btn.textContent;
|
||||
btn.textContent = "⏳...";
|
||||
try {
|
||||
await retryCalendarSync(id);
|
||||
showToast(
|
||||
"✓ Sincronización exitosa con Google Calendar",
|
||||
"success",
|
||||
4000,
|
||||
);
|
||||
loadData();
|
||||
onStateChange();
|
||||
} catch (err: unknown) {
|
||||
alert(
|
||||
err instanceof Error ? err.message : "Error al reintentar sync",
|
||||
showToast(
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Error al reintentar sincronización",
|
||||
"error",
|
||||
5000,
|
||||
);
|
||||
btn.textContent = "↻";
|
||||
btn.textContent = origText;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Event Handlers for Filter Buttons
|
||||
filterButtons.forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
const filter = btn.getAttribute("data-filter") as AgendaDateFilter;
|
||||
if (!filter) return;
|
||||
|
||||
activeFilter = filter;
|
||||
if (customDateInput) customDateInput.value = "";
|
||||
customDateStr = "";
|
||||
|
||||
filterButtons.forEach((b) => {
|
||||
const isCurrent = b === btn;
|
||||
b.classList.toggle("active", isCurrent);
|
||||
b.setAttribute("aria-selected", isCurrent ? "true" : "false");
|
||||
});
|
||||
|
||||
applyFilter();
|
||||
});
|
||||
});
|
||||
|
||||
// Event Handler for Custom Date Input
|
||||
customDateInput?.addEventListener("change", () => {
|
||||
if (customDateInput.value) {
|
||||
activeFilter = "CUSTOM";
|
||||
customDateStr = customDateInput.value;
|
||||
|
||||
filterButtons.forEach((b) => {
|
||||
b.classList.remove("active");
|
||||
b.setAttribute("aria-selected", "false");
|
||||
});
|
||||
|
||||
applyFilter();
|
||||
}
|
||||
});
|
||||
|
||||
refreshBtn?.addEventListener("click", () => loadData());
|
||||
loadData();
|
||||
}
|
||||
@@ -9,12 +9,14 @@ import {
|
||||
formatDateTime,
|
||||
getHoursRemainingBadge,
|
||||
} from "../utils";
|
||||
import { showConfirmModal, showPromptModal } from "./MicroModal";
|
||||
import { openPaymentModal } from "./PaymentModal";
|
||||
import {
|
||||
renderBookingStatusBadge,
|
||||
renderCalendarSyncBadge,
|
||||
renderPaymentStatusBadge,
|
||||
} from "./StatusBadge";
|
||||
import { showToast } from "./Toast";
|
||||
|
||||
export function renderFollowUpQueue(
|
||||
container: HTMLElement,
|
||||
@@ -176,20 +178,19 @@ export function renderFollowUpQueue(
|
||||
<div class="secondary-actions">
|
||||
<button
|
||||
type="button"
|
||||
class="btn-text btn-authorize-delay"
|
||||
class="btn btn-action-delay btn-authorize-delay"
|
||||
data-booking-id="${b.id}"
|
||||
title="Permitir que el paciente pague al llegar"
|
||||
>
|
||||
Autorizar prórroga
|
||||
<span>⏳ Prórroga</span>
|
||||
</button>
|
||||
<span class="divider">·</span>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-text text-danger btn-release-slot"
|
||||
class="btn btn-action-release btn-release-slot"
|
||||
data-booking-id="${b.id}"
|
||||
title="Liberar el espacio si no hubo respuesta"
|
||||
>
|
||||
Liberar lugar
|
||||
<span>✕ Liberar</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -209,7 +210,13 @@ export function renderFollowUpQueue(
|
||||
|
||||
openPaymentModal({
|
||||
booking,
|
||||
onSuccess: () => {
|
||||
onSuccess: (amount: number) => {
|
||||
showToast(
|
||||
`Pago acreditado exitosamente (${formatCurrency(amount)})`,
|
||||
"success",
|
||||
4500,
|
||||
{ folio: booking.booking_code },
|
||||
);
|
||||
loadData();
|
||||
onStateChange();
|
||||
},
|
||||
@@ -219,47 +226,82 @@ export function renderFollowUpQueue(
|
||||
|
||||
// Authorize delayed payment
|
||||
contentDiv.querySelectorAll(".btn-authorize-delay").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
btn.addEventListener("click", () => {
|
||||
const id = btn.getAttribute("data-booking-id");
|
||||
if (!id) return;
|
||||
const notes = window.prompt(
|
||||
"Motivo o acuerdo de la prórroga de pago:",
|
||||
"Acordado con el paciente para pago en efectivo antes de la sesión",
|
||||
);
|
||||
if (notes === null) return;
|
||||
const booking = bookings.find((b) => b.id === id);
|
||||
if (!id || !booking) return;
|
||||
|
||||
try {
|
||||
await authorizeDelayedPayment(id, notes);
|
||||
loadData();
|
||||
onStateChange();
|
||||
} catch (err: unknown) {
|
||||
alert(
|
||||
err instanceof Error ? err.message : "Error al autorizar prórroga",
|
||||
);
|
||||
}
|
||||
showPromptModal({
|
||||
title: "Autorizar Prórroga de Pago",
|
||||
kicker: "Excepción Operativa",
|
||||
subtitle:
|
||||
"Permite al consultante conservar su lugar y liquidar en efectivo o SPEI antes de iniciar su sesión.",
|
||||
bookingContext: {
|
||||
bookingCode: booking.booking_code,
|
||||
clientName: booking.client_name,
|
||||
serviceName: booking.service_name,
|
||||
scheduledAtFormatted: formatDateTime(booking.scheduled_at),
|
||||
},
|
||||
label: "Motivo o acuerdo de la prórroga:",
|
||||
defaultValue:
|
||||
"Acordado con el paciente para pago en efectivo antes de la sesión",
|
||||
placeholder:
|
||||
"Ej. Confirmado por Jasmin para pago presencial el día de la cita",
|
||||
confirmText: "Autorizar Prórroga",
|
||||
cancelText: "Cancelar",
|
||||
onConfirm: async (notes: string) => {
|
||||
await authorizeDelayedPayment(id, notes);
|
||||
showToast(
|
||||
"Prórroga autorizada. Estado actualizado a Prórroga Autorizada.",
|
||||
"warning",
|
||||
4500,
|
||||
{ folio: booking.booking_code },
|
||||
);
|
||||
loadData();
|
||||
onStateChange();
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Release booking
|
||||
contentDiv.querySelectorAll(".btn-release-slot").forEach((btn) => {
|
||||
btn.addEventListener("click", async () => {
|
||||
btn.addEventListener("click", () => {
|
||||
const id = btn.getAttribute("data-booking-id");
|
||||
if (!id) return;
|
||||
const reason = window.prompt(
|
||||
"¿Deseas liberar este horario para otros clientes? Motivo:",
|
||||
"Sin respuesta a recordatorios de pago dentro de las 48h",
|
||||
);
|
||||
if (reason === null) return;
|
||||
const booking = bookings.find((b) => b.id === id);
|
||||
if (!id || !booking) return;
|
||||
|
||||
try {
|
||||
await releaseBooking(id, reason);
|
||||
loadData();
|
||||
onStateChange();
|
||||
} catch (err: unknown) {
|
||||
alert(
|
||||
err instanceof Error ? err.message : "Error al liberar espacio",
|
||||
);
|
||||
}
|
||||
showConfirmModal({
|
||||
title: "¿Liberar este horario?",
|
||||
kicker: "Liberación de Espacio",
|
||||
message: `¿Deseas liberar este horario para otros clientes? Se cancelará la reservación activa y el horario volverá a estar disponible en el calendario público.`,
|
||||
bookingContext: {
|
||||
bookingCode: booking.booking_code,
|
||||
clientName: booking.client_name,
|
||||
serviceName: booking.service_name,
|
||||
scheduledAtFormatted: formatDateTime(booking.scheduled_at),
|
||||
},
|
||||
withReasonInput: true,
|
||||
reasonLabel: "Motivo de la liberación:",
|
||||
defaultReason:
|
||||
"Sin respuesta a recordatorios de pago dentro de las 48h",
|
||||
reasonPlaceholder:
|
||||
"Describe brevemente por qué se libera el horario...",
|
||||
confirmText: "Sí, liberar espacio",
|
||||
cancelText: "Conservar reservación",
|
||||
isDanger: true,
|
||||
onConfirm: async (reason: string) => {
|
||||
await releaseBooking(id, reason);
|
||||
showToast(
|
||||
"Espacio liberado con éxito. Horario nuevamente disponible.",
|
||||
"info",
|
||||
4500,
|
||||
{ folio: booking.booking_code },
|
||||
);
|
||||
loadData();
|
||||
onStateChange();
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,362 @@
|
||||
export interface BookingSummaryContext {
|
||||
bookingCode: string;
|
||||
clientName?: string | null;
|
||||
serviceName?: string | null;
|
||||
scheduledAtFormatted?: string | null;
|
||||
}
|
||||
|
||||
export interface PromptModalOptions {
|
||||
title: string;
|
||||
kicker?: string;
|
||||
subtitle?: string;
|
||||
bookingContext?: BookingSummaryContext;
|
||||
label: string;
|
||||
defaultValue?: string;
|
||||
placeholder?: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
onConfirm: (value: string) => Promise<void> | void;
|
||||
onCancel?: () => void;
|
||||
}
|
||||
|
||||
export interface ConfirmModalOptions {
|
||||
title: string;
|
||||
kicker?: string;
|
||||
message: string;
|
||||
bookingContext?: BookingSummaryContext;
|
||||
withReasonInput?: boolean;
|
||||
reasonLabel?: string;
|
||||
defaultReason?: string;
|
||||
reasonPlaceholder?: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
isDanger?: boolean;
|
||||
onConfirm: (reason: string) => Promise<void> | void;
|
||||
onCancel?: () => void;
|
||||
}
|
||||
|
||||
export function showPromptModal(options: PromptModalOptions): void {
|
||||
const {
|
||||
title,
|
||||
kicker = "Acción Requerida",
|
||||
subtitle,
|
||||
bookingContext,
|
||||
label,
|
||||
defaultValue = "",
|
||||
placeholder = "",
|
||||
confirmText = "Confirmar",
|
||||
cancelText = "Cancelar",
|
||||
onConfirm,
|
||||
onCancel,
|
||||
} = options;
|
||||
|
||||
const existingBackdrop = document.getElementById("micro-modal-backdrop");
|
||||
if (existingBackdrop) existingBackdrop.remove();
|
||||
|
||||
const backdrop = document.createElement("div");
|
||||
backdrop.id = "micro-modal-backdrop";
|
||||
backdrop.className = "modal-backdrop";
|
||||
|
||||
const summaryHtml = bookingContext
|
||||
? `
|
||||
<div class="summary-box">
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">Folio:</span>
|
||||
<span class="summary-value font-mono font-bold">${bookingContext.bookingCode}</span>
|
||||
</div>
|
||||
${
|
||||
bookingContext.clientName
|
||||
? `
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">Paciente:</span>
|
||||
<span class="summary-value">${bookingContext.clientName}</span>
|
||||
</div>`
|
||||
: ""
|
||||
}
|
||||
${
|
||||
bookingContext.serviceName
|
||||
? `
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">Servicio:</span>
|
||||
<span class="summary-value">${bookingContext.serviceName}</span>
|
||||
</div>`
|
||||
: ""
|
||||
}
|
||||
${
|
||||
bookingContext.scheduledAtFormatted
|
||||
? `
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">Horario:</span>
|
||||
<span class="summary-value font-medium">${bookingContext.scheduledAtFormatted}</span>
|
||||
</div>`
|
||||
: ""
|
||||
}
|
||||
</div>
|
||||
`
|
||||
: "";
|
||||
|
||||
backdrop.innerHTML = `
|
||||
<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="micro-modal-title">
|
||||
<div class="modal-header">
|
||||
<div>
|
||||
<span class="modal-kicker">${kicker}</span>
|
||||
<h3 id="micro-modal-title" class="modal-title">${title}</h3>
|
||||
</div>
|
||||
<button type="button" class="modal-close-btn" id="micro-modal-close" aria-label="Cerrar modal">×</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
${subtitle ? `<p class="modal-subtitle-text">${subtitle}</p>` : ""}
|
||||
${summaryHtml}
|
||||
|
||||
<form id="micro-modal-form" class="modal-form-content">
|
||||
<div class="form-group">
|
||||
<label for="prompt-input" class="form-label">${label}</label>
|
||||
<textarea
|
||||
id="prompt-input"
|
||||
name="prompt_value"
|
||||
class="form-textarea"
|
||||
rows="3"
|
||||
placeholder="${placeholder}"
|
||||
required
|
||||
>${defaultValue}</textarea>
|
||||
</div>
|
||||
|
||||
<div id="micro-modal-error" class="modal-error-box hidden"></div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button type="button" id="micro-modal-cancel" class="btn btn-secondary">
|
||||
${cancelText}
|
||||
</button>
|
||||
<button type="submit" id="micro-modal-submit" class="btn btn-primary">
|
||||
${confirmText}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.body.appendChild(backdrop);
|
||||
|
||||
const close = () => {
|
||||
backdrop.remove();
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
onCancel?.();
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") close();
|
||||
};
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
backdrop
|
||||
.querySelector("#micro-modal-close")
|
||||
?.addEventListener("click", () => close());
|
||||
backdrop
|
||||
.querySelector("#micro-modal-cancel")
|
||||
?.addEventListener("click", () => close());
|
||||
backdrop.addEventListener("click", (e) => {
|
||||
if (e.target === backdrop) close();
|
||||
});
|
||||
|
||||
const form = backdrop.querySelector<HTMLFormElement>("#micro-modal-form");
|
||||
const textarea = backdrop.querySelector<HTMLTextAreaElement>("#prompt-input");
|
||||
const submitBtn = backdrop.querySelector<HTMLButtonElement>(
|
||||
"#micro-modal-submit",
|
||||
);
|
||||
const errorBox = backdrop.querySelector<HTMLDivElement>("#micro-modal-error");
|
||||
|
||||
textarea?.focus();
|
||||
|
||||
form?.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
const val = textarea?.value.trim() ?? "";
|
||||
if (!submitBtn || !errorBox) return;
|
||||
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = "Procesando...";
|
||||
errorBox.classList.add("hidden");
|
||||
errorBox.textContent = "";
|
||||
|
||||
try {
|
||||
await onConfirm(val);
|
||||
backdrop.remove();
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
} catch (err: unknown) {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = confirmText;
|
||||
errorBox.textContent =
|
||||
err instanceof Error ? err.message : "Error al procesar la acción";
|
||||
errorBox.classList.remove("hidden");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function showConfirmModal(options: ConfirmModalOptions): void {
|
||||
const {
|
||||
title,
|
||||
kicker = "Confirmación Requerida",
|
||||
message,
|
||||
bookingContext,
|
||||
withReasonInput = false,
|
||||
reasonLabel = "Motivo de la acción:",
|
||||
defaultReason = "",
|
||||
reasonPlaceholder = "Describe el motivo...",
|
||||
confirmText = "Confirmar",
|
||||
cancelText = "Cancelar",
|
||||
isDanger = false,
|
||||
onConfirm,
|
||||
onCancel,
|
||||
} = options;
|
||||
|
||||
const existingBackdrop = document.getElementById("micro-modal-backdrop");
|
||||
if (existingBackdrop) existingBackdrop.remove();
|
||||
|
||||
const backdrop = document.createElement("div");
|
||||
backdrop.id = "micro-modal-backdrop";
|
||||
backdrop.className = "modal-backdrop";
|
||||
|
||||
const summaryHtml = bookingContext
|
||||
? `
|
||||
<div class="summary-box">
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">Folio:</span>
|
||||
<span class="summary-value font-mono font-bold">${bookingContext.bookingCode}</span>
|
||||
</div>
|
||||
${
|
||||
bookingContext.clientName
|
||||
? `
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">Paciente:</span>
|
||||
<span class="summary-value">${bookingContext.clientName}</span>
|
||||
</div>`
|
||||
: ""
|
||||
}
|
||||
${
|
||||
bookingContext.serviceName
|
||||
? `
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">Servicio:</span>
|
||||
<span class="summary-value">${bookingContext.serviceName}</span>
|
||||
</div>`
|
||||
: ""
|
||||
}
|
||||
${
|
||||
bookingContext.scheduledAtFormatted
|
||||
? `
|
||||
<div class="summary-row">
|
||||
<span class="summary-label">Horario:</span>
|
||||
<span class="summary-value font-medium">${bookingContext.scheduledAtFormatted}</span>
|
||||
</div>`
|
||||
: ""
|
||||
}
|
||||
</div>
|
||||
`
|
||||
: "";
|
||||
|
||||
const reasonSectionHtml = withReasonInput
|
||||
? `
|
||||
<div class="form-group" style="margin-top: 12px;">
|
||||
<label for="confirm-reason-input" class="form-label">${reasonLabel}</label>
|
||||
<textarea
|
||||
id="confirm-reason-input"
|
||||
name="reason"
|
||||
class="form-textarea"
|
||||
rows="2"
|
||||
placeholder="${reasonPlaceholder}"
|
||||
required
|
||||
>${defaultReason}</textarea>
|
||||
</div>
|
||||
`
|
||||
: "";
|
||||
|
||||
backdrop.innerHTML = `
|
||||
<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="confirm-modal-title">
|
||||
<div class="modal-header">
|
||||
<div>
|
||||
<span class="modal-kicker ${isDanger ? "text-danger" : ""}">${kicker}</span>
|
||||
<h3 id="confirm-modal-title" class="modal-title">${title}</h3>
|
||||
</div>
|
||||
<button type="button" class="modal-close-btn" id="confirm-modal-close" aria-label="Cerrar modal">×</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="${isDanger ? "reassuring-warning-box" : "modal-message-box"}">
|
||||
${message}
|
||||
</div>
|
||||
|
||||
${summaryHtml}
|
||||
${reasonSectionHtml}
|
||||
|
||||
<div id="confirm-modal-error" class="modal-error-box hidden"></div>
|
||||
|
||||
<div class="modal-actions">
|
||||
<button type="button" id="confirm-modal-cancel" class="btn btn-secondary">
|
||||
${cancelText}
|
||||
</button>
|
||||
<button type="button" id="confirm-modal-submit" class="btn ${isDanger ? "btn-danger" : "btn-primary"}">
|
||||
${confirmText}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
document.body.appendChild(backdrop);
|
||||
|
||||
const close = () => {
|
||||
backdrop.remove();
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
onCancel?.();
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") close();
|
||||
};
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
backdrop
|
||||
.querySelector("#confirm-modal-close")
|
||||
?.addEventListener("click", () => close());
|
||||
backdrop
|
||||
.querySelector("#confirm-modal-cancel")
|
||||
?.addEventListener("click", () => close());
|
||||
backdrop.addEventListener("click", (e) => {
|
||||
if (e.target === backdrop) close();
|
||||
});
|
||||
|
||||
const submitBtn = backdrop.querySelector<HTMLButtonElement>(
|
||||
"#confirm-modal-submit",
|
||||
);
|
||||
const errorBox = backdrop.querySelector<HTMLDivElement>(
|
||||
"#confirm-modal-error",
|
||||
);
|
||||
const reasonInput = backdrop.querySelector<HTMLTextAreaElement>(
|
||||
"#confirm-reason-input",
|
||||
);
|
||||
|
||||
submitBtn?.focus();
|
||||
|
||||
submitBtn?.addEventListener("click", async () => {
|
||||
if (!submitBtn || !errorBox) return;
|
||||
const reasonVal = reasonInput ? reasonInput.value.trim() : "";
|
||||
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = "Procesando...";
|
||||
errorBox.classList.add("hidden");
|
||||
errorBox.textContent = "";
|
||||
|
||||
try {
|
||||
await onConfirm(reasonVal);
|
||||
backdrop.remove();
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
} catch (err: unknown) {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = confirmText;
|
||||
errorBox.textContent =
|
||||
err instanceof Error ? err.message : "Error al procesar la acción";
|
||||
errorBox.classList.remove("hidden");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -14,7 +14,7 @@ export interface PaymentModalOptions {
|
||||
|
||||
export function openPaymentModal(options: {
|
||||
booking: Booking;
|
||||
onSuccess: () => void;
|
||||
onSuccess: (amount: number) => void;
|
||||
}): void {
|
||||
const { booking, onSuccess } = options;
|
||||
|
||||
@@ -169,7 +169,7 @@ export function openPaymentModal(options: {
|
||||
notes,
|
||||
});
|
||||
close();
|
||||
onSuccess();
|
||||
onSuccess(amount);
|
||||
} catch (err: unknown) {
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = "Confirmar Acreditación";
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
export type ToastType = "success" | "warning" | "error" | "info";
|
||||
|
||||
export interface ToastOptions {
|
||||
message: string;
|
||||
type?: ToastType;
|
||||
durationMs?: number;
|
||||
folio?: string;
|
||||
}
|
||||
|
||||
let toastContainer: HTMLElement | null = null;
|
||||
|
||||
function getToastContainer(): HTMLElement {
|
||||
if (!toastContainer || !document.body.contains(toastContainer)) {
|
||||
toastContainer = document.getElementById("toast-container");
|
||||
if (!toastContainer) {
|
||||
toastContainer = document.createElement("div");
|
||||
toastContainer.id = "toast-container";
|
||||
toastContainer.className = "toast-container";
|
||||
toastContainer.setAttribute("role", "status");
|
||||
toastContainer.setAttribute("aria-live", "polite");
|
||||
document.body.appendChild(toastContainer);
|
||||
}
|
||||
}
|
||||
return toastContainer;
|
||||
}
|
||||
|
||||
export function showToast(
|
||||
message: string,
|
||||
type: ToastType = "info",
|
||||
durationMs = 4000,
|
||||
options?: { folio?: string },
|
||||
): HTMLElement {
|
||||
const container = getToastContainer();
|
||||
|
||||
const toast = document.createElement("div");
|
||||
toast.className = `toast-item toast-${type}`;
|
||||
toast.setAttribute("role", type === "error" ? "alert" : "status");
|
||||
|
||||
const icons: Record<ToastType, string> = {
|
||||
success: "✓",
|
||||
warning: "⏳",
|
||||
error: "⚠️",
|
||||
info: "ℹ️",
|
||||
};
|
||||
|
||||
toast.innerHTML = `
|
||||
<div class="toast-icon" aria-hidden="true">${icons[type]}</div>
|
||||
<div class="toast-content">
|
||||
${options?.folio ? `<span class="toast-folio">${options.folio}</span>` : ""}
|
||||
<span class="toast-message">${message}</span>
|
||||
</div>
|
||||
<button type="button" class="toast-close-btn" aria-label="Cerrar notificación">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
`;
|
||||
|
||||
const removeToast = () => {
|
||||
toast.classList.add("toast-leaving");
|
||||
setTimeout(() => {
|
||||
toast.remove();
|
||||
}, 250);
|
||||
};
|
||||
|
||||
const closeBtn = toast.querySelector<HTMLButtonElement>(".toast-close-btn");
|
||||
closeBtn?.addEventListener("click", () => removeToast());
|
||||
|
||||
container.appendChild(toast);
|
||||
|
||||
// Trigger entry transition
|
||||
requestAnimationFrame(() => {
|
||||
toast.classList.add("toast-visible");
|
||||
});
|
||||
|
||||
if (durationMs > 0) {
|
||||
setTimeout(() => {
|
||||
if (toast.isConnected) {
|
||||
removeToast();
|
||||
}
|
||||
}, durationMs);
|
||||
}
|
||||
|
||||
return toast;
|
||||
}
|
||||
+46
-15
@@ -32,7 +32,7 @@ class OperatorDashboardApp {
|
||||
this.container.innerHTML = `
|
||||
<header class="app-header">
|
||||
<div class="brand-section">
|
||||
<span class="brand-lotus">🪷</span>
|
||||
<span class="brand-lotus" aria-hidden="true">🪷</span>
|
||||
<div>
|
||||
<h1 class="brand-title">Armonía del Ser</h1>
|
||||
<div class="text-xs text-muted">Panel Operativo de Consultas y Agenda</div>
|
||||
@@ -47,7 +47,8 @@ class OperatorDashboardApp {
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav class="nav-tabs" role="tablist">
|
||||
<!-- Desktop & Tablet Tabs Header -->
|
||||
<nav class="nav-tabs" role="tablist" aria-label="Navegación principal">
|
||||
<button class="nav-tab active" data-tab="queue" role="tab" aria-selected="true">
|
||||
<span>Cola 48h (Seguimiento)</span>
|
||||
<span id="queue-badge" class="tab-badge hidden">0</span>
|
||||
@@ -60,14 +61,32 @@ class OperatorDashboardApp {
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<!-- Main View Container -->
|
||||
<main id="tab-content" class="tab-main-content" role="tabpanel"></main>
|
||||
|
||||
<!-- Sticky Mobile Navigation Bar -->
|
||||
<nav class="mobile-sticky-nav" role="tablist" aria-label="Navegación móvil rápida">
|
||||
<button class="mobile-nav-item active" data-tab="queue" role="tab" aria-selected="true">
|
||||
<span class="mobile-nav-icon" aria-hidden="true">⏱️</span>
|
||||
<span class="mobile-nav-label">Cola 48h</span>
|
||||
<span id="queue-badge-mobile" class="tab-badge tab-badge-mobile hidden">0</span>
|
||||
</button>
|
||||
<button class="mobile-nav-item" data-tab="agenda" role="tab" aria-selected="false">
|
||||
<span class="mobile-nav-icon" aria-hidden="true">📅</span>
|
||||
<span class="mobile-nav-label">Agenda</span>
|
||||
</button>
|
||||
<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-label">Historial</span>
|
||||
</button>
|
||||
</nav>
|
||||
`;
|
||||
}
|
||||
|
||||
private bindEvents(): void {
|
||||
const tabButtons =
|
||||
this.container.querySelectorAll<HTMLButtonElement>(".nav-tab");
|
||||
tabButtons.forEach((btn) => {
|
||||
const allTabButtons =
|
||||
this.container.querySelectorAll<HTMLButtonElement>("[data-tab]");
|
||||
allTabButtons.forEach((btn) => {
|
||||
btn.addEventListener("click", () => {
|
||||
const targetTab = btn.getAttribute("data-tab") as TabId;
|
||||
if (targetTab) {
|
||||
@@ -75,15 +94,25 @@ class OperatorDashboardApp {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener("hashchange", () => {
|
||||
const hash = window.location.hash.replace("#", "") as TabId;
|
||||
if (hash === "queue" || hash === "agenda" || hash === "all") {
|
||||
if (this.activeTab !== hash) {
|
||||
this.switchTab(hash);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private switchTab(tab: TabId): void {
|
||||
this.activeTab = tab;
|
||||
window.location.hash = tab;
|
||||
|
||||
// Update tab button active states
|
||||
const tabButtons =
|
||||
this.container.querySelectorAll<HTMLButtonElement>(".nav-tab");
|
||||
tabButtons.forEach((btn) => {
|
||||
// Update both desktop and mobile active states
|
||||
const allTabButtons =
|
||||
this.container.querySelectorAll<HTMLButtonElement>("[data-tab]");
|
||||
allTabButtons.forEach((btn) => {
|
||||
const isCurrent = btn.getAttribute("data-tab") === tab;
|
||||
btn.classList.toggle("active", isCurrent);
|
||||
btn.setAttribute("aria-selected", isCurrent ? "true" : "false");
|
||||
@@ -109,16 +138,18 @@ class OperatorDashboardApp {
|
||||
private async refreshTabBadge(): Promise<void> {
|
||||
try {
|
||||
const queue = await fetchFollowUpQueue();
|
||||
const badge =
|
||||
this.container.querySelector<HTMLSpanElement>("#queue-badge");
|
||||
if (badge) {
|
||||
if (queue.length > 0) {
|
||||
badge.textContent = String(queue.length);
|
||||
const count = queue.length;
|
||||
const badges = this.container.querySelectorAll<HTMLSpanElement>(
|
||||
"#queue-badge, #queue-badge-mobile",
|
||||
);
|
||||
badges.forEach((badge) => {
|
||||
if (count > 0) {
|
||||
badge.textContent = String(count);
|
||||
badge.classList.remove("hidden");
|
||||
} else {
|
||||
badge.classList.add("hidden");
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch {
|
||||
// Ignore badge background fetch failure
|
||||
}
|
||||
|
||||
+565
-11
@@ -483,37 +483,101 @@ body {
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
min-height: 36px;
|
||||
padding: 6px 12px;
|
||||
min-height: 44px;
|
||||
padding: 8px 14px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.btn-xs {
|
||||
padding: 2px 6px;
|
||||
font-size: 11px;
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
border-radius: var(--radius-sm);
|
||||
border: 1px solid var(--color-border);
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-xs:hover {
|
||||
background: var(--color-surface-soft);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background-color: var(--color-danger);
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.btn-danger:hover {
|
||||
background-color: #991b1b;
|
||||
}
|
||||
|
||||
.secondary-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
width: 100%;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.btn-action-delay {
|
||||
flex: 1;
|
||||
min-height: 44px;
|
||||
background: var(--color-gold-light);
|
||||
border: 1px solid #fcd34d;
|
||||
color: #92400e;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-action-delay:hover {
|
||||
background: #fef3c7;
|
||||
}
|
||||
|
||||
.btn-action-release {
|
||||
flex: 1;
|
||||
min-height: 44px;
|
||||
background: var(--color-danger-light);
|
||||
border: 1px solid #fca5a5;
|
||||
color: var(--color-danger);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-action-release:hover {
|
||||
background: #fee2e2;
|
||||
}
|
||||
|
||||
.btn-text {
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 12px;
|
||||
font-size: 13px;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
padding: 4px 6px;
|
||||
min-height: 44px;
|
||||
min-width: 44px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 8px 12px;
|
||||
}
|
||||
|
||||
.btn-text:hover {
|
||||
@@ -705,7 +769,21 @@ body {
|
||||
line-height: 1;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
padding: 4px;
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: var(--radius-sm);
|
||||
padding: 0;
|
||||
transition:
|
||||
background 0.15s ease,
|
||||
color 0.15s ease;
|
||||
}
|
||||
|
||||
.modal-close-btn:hover {
|
||||
color: var(--color-text-main);
|
||||
background: var(--color-surface-soft);
|
||||
}
|
||||
|
||||
.summary-box {
|
||||
@@ -928,3 +1006,479 @@ body {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Toast Notification System
|
||||
========================================================================== */
|
||||
.toast-container {
|
||||
position: fixed;
|
||||
top: 16px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
z-index: 9999;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
width: calc(100% - 32px);
|
||||
max-width: 480px;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.toast-item {
|
||||
pointer-events: auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
border-radius: var(--radius-md);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
|
||||
font-size: 14px;
|
||||
line-height: 1.4;
|
||||
opacity: 0;
|
||||
transform: translateY(-12px);
|
||||
transition:
|
||||
opacity 0.25s ease,
|
||||
transform 0.25s ease;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.toast-item.toast-visible {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.toast-item.toast-leaving {
|
||||
opacity: 0;
|
||||
transform: translateY(-12px);
|
||||
}
|
||||
|
||||
.toast-icon {
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 50%;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.toast-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.toast-folio {
|
||||
display: inline-block;
|
||||
font-family: var(--font-mono);
|
||||
font-weight: 700;
|
||||
font-size: 12px;
|
||||
background: rgba(255, 255, 255, 0.25);
|
||||
padding: 1px 6px;
|
||||
border-radius: 4px;
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.toast-message {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.toast-close-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #ffffff;
|
||||
font-size: 22px;
|
||||
cursor: pointer;
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: var(--radius-sm);
|
||||
padding: 0;
|
||||
margin-right: -6px;
|
||||
opacity: 0.8;
|
||||
transition: opacity 0.15s ease;
|
||||
}
|
||||
|
||||
.toast-close-btn:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.toast-success {
|
||||
background-color: var(--color-success);
|
||||
}
|
||||
|
||||
.toast-warning {
|
||||
background-color: var(--color-warning);
|
||||
}
|
||||
|
||||
.toast-error {
|
||||
background-color: var(--color-danger);
|
||||
}
|
||||
|
||||
.toast-info {
|
||||
background-color: var(--color-sage-dark);
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
MicroModal Extensions & Warning Box
|
||||
========================================================================== */
|
||||
.modal-form-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.form-textarea {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
font-size: 14px;
|
||||
font-family: inherit;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
background: #fff;
|
||||
color: var(--color-text-main);
|
||||
line-height: 1.5;
|
||||
resize: vertical;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.form-textarea:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-border-focus);
|
||||
box-shadow: 0 0 0 3px rgba(45, 90, 70, 0.15);
|
||||
}
|
||||
|
||||
.reassuring-warning-box {
|
||||
background-color: #fff1f2;
|
||||
border: 1px solid #fecdd3;
|
||||
color: #9f1239;
|
||||
padding: 12px 14px;
|
||||
border-radius: var(--radius-md);
|
||||
font-size: 13.5px;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.modal-message-box {
|
||||
background-color: var(--color-surface-soft);
|
||||
padding: 12px 14px;
|
||||
border-radius: var(--radius-md);
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.modal-subtitle-text {
|
||||
font-size: 13px;
|
||||
color: var(--color-text-muted);
|
||||
margin-bottom: 12px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Agenda Date Navigation & Filter Pills
|
||||
========================================================================== */
|
||||
.agenda-nav-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.date-filter-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.btn-filter-pill {
|
||||
min-height: 44px;
|
||||
min-width: 44px;
|
||||
padding: 8px 16px;
|
||||
border-radius: 999px;
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-filter-pill:hover {
|
||||
border-color: var(--color-sage);
|
||||
color: var(--color-sage);
|
||||
background: var(--color-surface-soft);
|
||||
}
|
||||
|
||||
.btn-filter-pill.active {
|
||||
background: var(--color-sage);
|
||||
border-color: var(--color-sage);
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.custom-date-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.date-picker-label {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: var(--color-text-muted);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.form-input-date {
|
||||
min-height: 44px;
|
||||
padding: 8px 12px;
|
||||
font-size: 13px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
background: #ffffff;
|
||||
color: var(--color-text-main);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.form-input-date:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-border-focus);
|
||||
box-shadow: 0 0 0 3px rgba(45, 90, 70, 0.15);
|
||||
}
|
||||
|
||||
.filter-indicator-banner {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: var(--color-sage-light);
|
||||
color: var(--color-sage-dark);
|
||||
font-size: 13px;
|
||||
padding: 10px 14px;
|
||||
border-radius: var(--radius-md);
|
||||
margin-bottom: 16px;
|
||||
border: 1px solid rgba(45, 90, 70, 0.15);
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.indicator-count {
|
||||
background: var(--color-surface);
|
||||
color: var(--color-sage-dark);
|
||||
font-weight: 700;
|
||||
padding: 3px 9px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
border: 1px solid rgba(45, 90, 70, 0.2);
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Refined Collision Warnings with Visual Time Markers
|
||||
========================================================================== */
|
||||
.collision-alert {
|
||||
margin-top: 14px;
|
||||
padding: 14px 16px;
|
||||
border-radius: var(--radius-md);
|
||||
border-left: 5px solid;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.collision-warning {
|
||||
background: #fffbeb;
|
||||
border-left-color: var(--color-warning);
|
||||
color: #92400e;
|
||||
}
|
||||
|
||||
.collision-critical {
|
||||
background: #fef2f2;
|
||||
border-left-color: var(--color-danger);
|
||||
color: #991b1b;
|
||||
}
|
||||
|
||||
.collision-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.collision-icon {
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.collision-title {
|
||||
font-size: 13.5px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.collision-deficit-pill {
|
||||
background: rgba(0, 0, 0, 0.08);
|
||||
padding: 3px 8px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.collision-markers {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.marker-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 10px;
|
||||
background: #ffffff;
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.marker-chip-label {
|
||||
color: #4b5563;
|
||||
}
|
||||
|
||||
.marker-buffer {
|
||||
background: #f0fdf4;
|
||||
border-color: #86efac;
|
||||
color: #166534;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.marker-conflict {
|
||||
background: #fee2e2;
|
||||
border-color: #fca5a5;
|
||||
color: #991b1b;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.collision-explainer {
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Sticky Mobile Navigation Bar & Mobile Ergonomics
|
||||
========================================================================== */
|
||||
.mobile-sticky-nav {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.app-container {
|
||||
padding-bottom: 84px; /* Clearance for sticky bottom nav */
|
||||
}
|
||||
|
||||
.nav-tabs {
|
||||
display: none; /* Replaced by sticky mobile nav on narrow screens */
|
||||
}
|
||||
|
||||
.mobile-sticky-nav {
|
||||
display: flex;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #ffffff;
|
||||
border-top: 1px solid var(--color-border);
|
||||
box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
|
||||
z-index: 1000;
|
||||
padding: 4px 8px;
|
||||
padding-bottom: max(6px, env(safe-area-inset-bottom));
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.mobile-nav-item {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 2px;
|
||||
min-height: 52px;
|
||||
min-width: 44px;
|
||||
padding: 6px 4px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
border-radius: var(--radius-sm);
|
||||
transition: all 0.15s ease;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.mobile-nav-item.active {
|
||||
color: var(--color-sage);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.mobile-nav-icon {
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.mobile-nav-label {
|
||||
font-size: 11px;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.tab-badge-mobile {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: calc(50% - 22px);
|
||||
font-size: 10px;
|
||||
padding: 1px 5px;
|
||||
}
|
||||
|
||||
.agenda-nav-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.date-filter-group {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.btn-filter-pill {
|
||||
padding: 8px 4px;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.custom-date-container {
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.form-input-date {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.stats-row {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
@@ -83,3 +83,93 @@ export function getHoursRemainingBadge(hours: number): {
|
||||
urgencyClass: "badge-info",
|
||||
};
|
||||
}
|
||||
|
||||
export function isSameDay(d1: Date, d2: Date): boolean {
|
||||
return (
|
||||
d1.getFullYear() === d2.getFullYear() &&
|
||||
d1.getMonth() === d2.getMonth() &&
|
||||
d1.getDate() === d2.getDate()
|
||||
);
|
||||
}
|
||||
|
||||
export function isToday(date: Date, refDate: Date = new Date()): boolean {
|
||||
return isSameDay(date, refDate);
|
||||
}
|
||||
|
||||
export function isTomorrow(date: Date, refDate: Date = new Date()): boolean {
|
||||
const tomorrow = new Date(
|
||||
refDate.getFullYear(),
|
||||
refDate.getMonth(),
|
||||
refDate.getDate() + 1,
|
||||
);
|
||||
return isSameDay(date, tomorrow);
|
||||
}
|
||||
|
||||
export function isThisWeek(date: Date, refDate: Date = new Date()): boolean {
|
||||
const day = refDate.getDay();
|
||||
// Week starts on Monday: (day + 6) % 7 gives 0 for Monday, 6 for Sunday
|
||||
const diffToMonday = (day + 6) % 7;
|
||||
const startOfWeek = new Date(
|
||||
refDate.getFullYear(),
|
||||
refDate.getMonth(),
|
||||
refDate.getDate() - diffToMonday,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
);
|
||||
const endOfWeek = new Date(
|
||||
startOfWeek.getTime() + 7 * 24 * 60 * 60 * 1000 - 1,
|
||||
);
|
||||
return date >= startOfWeek && date <= endOfWeek;
|
||||
}
|
||||
|
||||
export function formatDateInput(date: Date): string {
|
||||
const y = date.getFullYear();
|
||||
const m = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const d = String(date.getDate()).padStart(2, "0");
|
||||
return `${y}-${m}-${d}`;
|
||||
}
|
||||
|
||||
export interface CollisionResult {
|
||||
hasCollision: boolean;
|
||||
isDirectCollision: boolean;
|
||||
isBufferCollision: boolean;
|
||||
deficitMinutes: number;
|
||||
}
|
||||
|
||||
export function checkBufferCollision(
|
||||
currentStartIso: string,
|
||||
currentDurationMinutes: number,
|
||||
currentBufferMinutes: number,
|
||||
nextStartIso: string,
|
||||
): CollisionResult {
|
||||
const currentStart = new Date(currentStartIso);
|
||||
const currentEnd = new Date(
|
||||
currentStart.getTime() + currentDurationMinutes * 60 * 1000,
|
||||
);
|
||||
const currentBufferEnd = new Date(
|
||||
currentEnd.getTime() + currentBufferMinutes * 60 * 1000,
|
||||
);
|
||||
const nextStart = new Date(nextStartIso);
|
||||
|
||||
if (nextStart >= currentBufferEnd) {
|
||||
return {
|
||||
hasCollision: false,
|
||||
isDirectCollision: false,
|
||||
isBufferCollision: false,
|
||||
deficitMinutes: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const isDirectCollision = nextStart < currentEnd;
|
||||
const deficitMs = currentBufferEnd.getTime() - nextStart.getTime();
|
||||
const deficitMinutes = Math.round(deficitMs / (60 * 1000));
|
||||
|
||||
return {
|
||||
hasCollision: true,
|
||||
isDirectCollision,
|
||||
isBufferCollision: !isDirectCollision,
|
||||
deficitMinutes,
|
||||
};
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
calculateInterval,
|
||||
checkBufferCollision,
|
||||
formatCurrency,
|
||||
formatDateInput,
|
||||
getHoursRemainingBadge,
|
||||
isSameDay,
|
||||
isThisWeek,
|
||||
isToday,
|
||||
isTomorrow,
|
||||
} from "../src/utils";
|
||||
|
||||
describe("Frontend Utilities", () => {
|
||||
@@ -32,4 +38,68 @@ describe("Frontend Utilities", () => {
|
||||
expect(getHoursRemainingBadge(36).urgencyClass).toBe("badge-warning");
|
||||
expect(getHoursRemainingBadge(72).urgencyClass).toBe("badge-info");
|
||||
});
|
||||
|
||||
describe("Date Filtering Utilities", () => {
|
||||
const baseDate = new Date("2026-10-20T10:00:00");
|
||||
|
||||
it("correctly identifies same calendar day", () => {
|
||||
const sameDay = new Date("2026-10-20T18:30:00");
|
||||
const diffDay = new Date("2026-10-21T10:00:00");
|
||||
expect(isSameDay(baseDate, sameDay)).toBe(true);
|
||||
expect(isSameDay(baseDate, diffDay)).toBe(false);
|
||||
});
|
||||
|
||||
it("identifies today and tomorrow relative to reference date", () => {
|
||||
const todayAppointment = new Date("2026-10-20T15:00:00");
|
||||
const tomorrowAppointment = new Date("2026-10-21T11:00:00");
|
||||
const nextWeekAppointment = new Date("2026-10-28T11:00:00");
|
||||
|
||||
expect(isToday(todayAppointment, baseDate)).toBe(true);
|
||||
expect(isToday(tomorrowAppointment, baseDate)).toBe(false);
|
||||
|
||||
expect(isTomorrow(tomorrowAppointment, baseDate)).toBe(true);
|
||||
expect(isTomorrow(todayAppointment, baseDate)).toBe(false);
|
||||
|
||||
expect(isThisWeek(todayAppointment, baseDate)).toBe(true);
|
||||
expect(isThisWeek(tomorrowAppointment, baseDate)).toBe(true);
|
||||
expect(isThisWeek(nextWeekAppointment, baseDate)).toBe(false);
|
||||
});
|
||||
|
||||
it("formats date to YYYY-MM-DD input string", () => {
|
||||
const testDate = new Date(2026, 9, 20); // October 20, 2026
|
||||
expect(formatDateInput(testDate)).toBe("2026-10-20");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Collision Detection Utilities", () => {
|
||||
it("detects no collision when next appointment starts after buffer", () => {
|
||||
const startIso = "2026-10-20T10:00:00";
|
||||
const nextStartIso = "2026-10-20T11:15:00"; // Exactly after 60m + 15m buffer
|
||||
const result = checkBufferCollision(startIso, 60, 15, nextStartIso);
|
||||
|
||||
expect(result.hasCollision).toBe(false);
|
||||
expect(result.deficitMinutes).toBe(0);
|
||||
});
|
||||
|
||||
it("detects buffer collision when next appointment invades buffer window", () => {
|
||||
const startIso = "2026-10-20T10:00:00";
|
||||
const nextStartIso = "2026-10-20T11:05:00"; // 5 min into 15m buffer (10 min deficit)
|
||||
const result = checkBufferCollision(startIso, 60, 15, nextStartIso);
|
||||
|
||||
expect(result.hasCollision).toBe(true);
|
||||
expect(result.isBufferCollision).toBe(true);
|
||||
expect(result.isDirectCollision).toBe(false);
|
||||
expect(result.deficitMinutes).toBe(10);
|
||||
});
|
||||
|
||||
it("detects direct collision when next appointment starts before session ends", () => {
|
||||
const startIso = "2026-10-20T10:00:00";
|
||||
const nextStartIso = "2026-10-20T10:45:00"; // 15 min before session ends
|
||||
const result = checkBufferCollision(startIso, 60, 15, nextStartIso);
|
||||
|
||||
expect(result.hasCollision).toBe(true);
|
||||
expect(result.isDirectCollision).toBe(true);
|
||||
expect(result.deficitMinutes).toBe(30); // 15 min session + 15 min buffer
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user