Adding an Annual Review Tab & Dynamic Period Handling to the Hotel‑IT Ops Dashboard

TL;DR: I added a new “Annual Review” panel with month‑based tabs, an Excel export template, and slide‑ready PNG assets. The change required extending the field schema, updating the API contract, and refactoring the front‑end to generate periods automatically based on the current year.

The Problem

The Ops Dashboard was built for day‑to‑day ticket monitoring, but management requested a yearly overview that could be printed as slides and exported to Excel. The existing UI only showed a single month view, and the period list was hard‑coded in Spanish only. When we tried to add a new tab manually, the UI broke because the month names were mismatched between the panel (Spanish) and the slide layer (English). Additionally, the property list still contained OFPAN, a hotel with no data, which caused empty rows in the export.

Symptoms

  • Adding a new tab in public/index.html caused duplicate IDs and CSS conflicts.
  • The export endpoint (api/v1/[action].js) returned null for the removed property, breaking the Excel generator.
  • The month selector displayed “Enero, Febrero…” on the panel but the slide still used English month names, leading to mismatched labels in the generated PNG (3840 × 1920 px).

What I Tried First

My first attempt was to hard‑code three new panels directly in public/index.html and duplicate the existing month selector logic in public/js/app.js. I also added a static JSON file (data/months.json) with both Spanish and English names and tried to import it with a <script> tag.

What went wrong:

  1. Duplication of logic – every time a new month was added, I had to edit three places (HTML, JS, and JSON).
  2. Scope leakage – the hard‑coded IDs (#annualTab) collided with the existing #monthlyTab listeners, causing the click handlers to fire twice.
  3. Export breakage – the property removal (OFPAN) was still referenced in the Excel generation code, resulting in a TypeError: Cannot read property 'length' of undefined.

The approach was unsustainable and produced the exact errors the team was seeing in the console.

The Implementation

1. Define a New UI Flag

In lib/fields.js I added a boolean field that toggles the annual view:

// lib/fields.js export const FIELDS = [ // … existing fields { "key": "in_show_annual", "label": "Mostrar revisión anual", "type": "checkbox", "section": "⚙️ Secciones visibles — marcar para mostrar · editar nombre" }, ]; 

This field appears in the admin panel, letting super‑admins enable the new tab without code changes.

2. Update Property List

Removed the obsolete OFPAN entry:

// lib/properties.js export const PROPERTIES = { CUNRP: "Residence INN Collection", ACMIA: "AC Hotel Miami", OFMVD: "Only You Hotel MVD", // OFPAN removed – data captured in OFMVD LGND: "Legendary Hotel" }; 

The change propagates automatically to the Excel generator because the export routine iterates over Object.keys(PROPERTIES).

3. Centralize Period Logic

Created a reusable period helper in public/js/annual.js. This file is now 745 lines long, but the core of the period handling lives in a few pure functions:

// public/js/annual.js const MONTHS_ES = ["Enero","Febrero","Marzo","Abril","Mayo","Junio", "Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"]; const MONTHS_EN = ["January","February","March","April","May","June", "July","August","September","October","November","December"]; /** * Returns the zero‑based month index for a given label (ES or EN). */ export function monthIdx(label) { const idx = MONTHS_ES.indexOf(label); return idx !== -1 ? idx : MONTHS_EN.indexOf(label); } /** * Generates a list of period objects for the current year. * Each object contains: * - month (ES) * - monthEn (EN) * - year (auto‑filled) */ export function buildPeriods() { const year = new Date().getFullYear(); return MONTHS_ES.map((es, i) => ({ month: es, monthEn: MONTHS_EN[i], year })); } 

The buildPeriods() function is called from app.js during initialization:

// public/js/app.js import { buildPeriods } from "./annual.js"; function initPeriods() { const periods = buildPeriods(); // Populate the selector in the panel (Spanish) const sel = document.getElementById("periodSelect"); periods.forEach(p => { const opt = document.createElement("option"); opt.value = `${p.month}-${p.year}`; opt.textContent = `${p.month} ${p.year}`; sel.appendChild(opt); }); } initPeriods(); 

4. Wire the Annual Tab into the UI

public/index.html now contains a single placeholder for the annual view, rendered conditionally:

<!-- public/index.html --> <div id="annualContainer" class="panel hidden"> <ul class="tabs" id="annualTabs"></ul> <div class="tab-content" id="annualContent"></div> </div> 

The tabs are generated dynamically based on the periods list:

// public/js/annual.js (continued) export function renderAnnualTabs(periods) { const tabs = document.getElementById("annualTabs"); const content = document.getElementById("annualContent"); tabs.innerHTML = ""; content.innerHTML = ""; periods.forEach(p => { const tab = document.createElement("li"); tab.className = "tab"; tab.dataset.month = p.monthEn; tab.textContent = `${p.month} ${p.year}`; tabs.appendChild(tab); const pane = document.createElement("div"); pane.className = "pane hidden"; pane.id = `pane-${p.monthEn}`; pane.innerHTML = `<h3>${p.monthEn} ${p.year}</h3>`; content.appendChild(pane); }); // Attach click handler tabs.addEventListener("click", e => { if (e.target.matches(".tab")) { const sel = e.target.dataset.month; document.querySelectorAll(".pane").forEach(p => p.classList.add("hidden")); document.getElementById(`pane-${sel}`).classList.remove("hidden"); } }); } 

app.js now calls renderAnnualTabs after the period list is built:

// public/js/app.js (excerpt) import { renderAnnualTabs } from "./annual.js"; function yrReset() { const periods = buildPeriods(); renderAnnualTabs(periods); } if (typeof yrReset === "function") yrReset(); 

5. Extend the API Contract

The back‑end needed to expose the

Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.

Repo: zaerohell/hotel-it-ops-dashboard · 2026-12-03

#playadev #buildinpublic