Add secondary mobile menu to Staff dashboard

This commit is contained in:
A R R R Associates
2026-07-10 20:57:07 +05:30
parent d0b2984fb3
commit 7d1b38581b
@@ -30,15 +30,57 @@
('reports','Reports') ('reports','Reports')
] %} ] %}
<section class="rounded-2xl border border-slate-200 bg-white p-3 shadow-soft"> <section class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-soft">
<div class="mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-slate-500">Employee Workspace</div> <div class="sm:hidden">
<div class="overflow-x-auto pb-1"> <details id="employee-dashboard-mobile-menu" class="group">
<div class="flex min-w-max flex-nowrap gap-2" id="employee-portal-tabs"> <summary class="flex min-h-12 cursor-pointer list-none items-center justify-between gap-3 px-4 py-3 text-sm font-semibold text-slate-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-brand-500">
{% for code, label in main_tabs %} <span class="inline-flex items-center gap-2">
<button type="button" data-tab="{{ code }}" class="employee-portal-tab employee-portal-main-tab inline-flex shrink-0 items-center rounded-xl px-4 py-2 text-sm font-semibold whitespace-nowrap transition {% if active_tab == code %}bg-brand-600 text-white shadow-soft{% else %}border border-slate-300 bg-white text-slate-700 hover:bg-slate-50{% endif %}"> <svg class="h-5 w-5 group-open:hidden" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
{{ label }}{% if code == 'hr' and unread_alert_count is defined and unread_alert_count > 0 %}<span class="ml-2 rounded-full bg-white/20 px-2 py-0.5 text-[10px]">{{ unread_alert_count }}</span>{% endif %} <path stroke-linecap="round" d="M4 6h16M4 12h16M4 18h16" />
</button> </svg>
{% endfor %} <svg class="hidden h-5 w-5 group-open:block" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path stroke-linecap="round" d="M6 6l12 12M18 6 6 18" />
</svg>
<span>Dashboard Menu</span>
</span>
<span class="text-xs font-medium text-slate-500">Employee workspace sections</span>
</summary>
<nav aria-label="Employee workspace sections" class="border-t border-slate-100 bg-slate-50/80 px-4 py-3">
<ul class="space-y-1" role="list">
{% for code, label in main_tabs %}
<li>
<button
type="button"
data-tab="{{ code }}"
class="employee-portal-tab employee-portal-main-tab flex w-full items-center justify-between gap-3 rounded-xl px-3 py-2.5 text-left text-sm font-semibold transition {% if active_tab == code %}bg-brand-50 text-brand-700{% else %}bg-white text-slate-800 hover:bg-slate-100{% endif %}"
{% if active_tab == code %}aria-current="page"{% endif %}
>
<span class="inline-flex items-center gap-2">
<span>{{ label }}</span>
{% if code == 'hr' and unread_alert_count is defined and unread_alert_count > 0 %}
<span class="rounded-full bg-brand-100 px-2 py-0.5 text-[10px] font-bold text-brand-700">{{ unread_alert_count }}</span>
{% endif %}
</span>
{% if active_tab == code %}<span class="h-2 w-2 rounded-full bg-brand-600" data-active-marker aria-hidden="true"></span>{% endif %}
</button>
</li>
{% endfor %}
</ul>
</nav>
</details>
</div>
<div class="hidden p-3 sm:block">
<div class="mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-slate-500">Employee Workspace</div>
<div class="overflow-x-auto pb-1">
<div class="flex min-w-max flex-nowrap gap-2" id="employee-portal-tabs">
{% for code, label in main_tabs %}
<button type="button" data-tab="{{ code }}" class="employee-portal-tab employee-portal-main-tab inline-flex shrink-0 items-center rounded-xl px-4 py-2 text-sm font-semibold whitespace-nowrap transition {% if active_tab == code %}bg-brand-600 text-white shadow-soft{% else %}border border-slate-300 bg-white text-slate-700 hover:bg-slate-50{% endif %}">
{{ label }}{% if code == 'hr' and unread_alert_count is defined and unread_alert_count > 0 %}<span class="ml-2 rounded-full bg-white/20 px-2 py-0.5 text-[10px]">{{ unread_alert_count }}</span>{% endif %}
</button>
{% endfor %}
</div>
</div> </div>
</div> </div>
</section> </section>
@@ -52,6 +94,7 @@
(function () { (function () {
const panel = document.getElementById('employee-portal-panel'); const panel = document.getElementById('employee-portal-panel');
const mainTabs = Array.from(document.querySelectorAll('.employee-portal-main-tab')); const mainTabs = Array.from(document.querySelectorAll('.employee-portal-main-tab'));
const mobileMenu = document.getElementById('employee-dashboard-mobile-menu');
if (!panel || !mainTabs.length) return; if (!panel || !mainTabs.length) return;
const groupMap = { const groupMap = {
@@ -80,20 +123,47 @@
const activeGroup = groupMap[tabName] || tabName || 'overview'; const activeGroup = groupMap[tabName] || tabName || 'overview';
mainTabs.forEach(function (button) { mainTabs.forEach(function (button) {
const active = button.dataset.tab === activeGroup; const active = button.dataset.tab === activeGroup;
button.classList.toggle('bg-brand-600', active); const isMobileButton = button.closest('#employee-dashboard-mobile-menu') !== null;
button.classList.toggle('text-white', active);
button.classList.toggle('shadow-soft', active); if (isMobileButton) {
button.classList.toggle('border', !active); button.classList.toggle('bg-brand-50', active);
button.classList.toggle('border-slate-300', !active); button.classList.toggle('text-brand-700', active);
button.classList.toggle('bg-white', !active); button.classList.toggle('bg-white', !active);
button.classList.toggle('text-slate-700', !active); button.classList.toggle('text-slate-800', !active);
button.classList.toggle('hover:bg-slate-50', !active); button.classList.toggle('hover:bg-slate-100', !active);
if (active) {
button.setAttribute('aria-current', 'page');
} else {
button.removeAttribute('aria-current');
}
let marker = button.querySelector('[data-active-marker]');
if (active && !marker) {
marker = document.createElement('span');
marker.dataset.activeMarker = 'true';
marker.className = 'h-2 w-2 rounded-full bg-brand-600';
marker.setAttribute('aria-hidden', 'true');
button.appendChild(marker);
} else if (!active && marker) {
marker.remove();
}
} else {
button.classList.toggle('bg-brand-600', active);
button.classList.toggle('text-white', active);
button.classList.toggle('shadow-soft', active);
button.classList.toggle('border', !active);
button.classList.toggle('border-slate-300', !active);
button.classList.toggle('bg-white', !active);
button.classList.toggle('text-slate-700', !active);
button.classList.toggle('hover:bg-slate-50', !active);
}
}); });
} }
async function loadTab(tabName, pushState) { async function loadTab(tabName, pushState) {
const safeTab = tabName || 'overview'; const safeTab = tabName || 'overview';
setActive(safeTab); setActive(safeTab);
if (mobileMenu) mobileMenu.open = false;
panel.innerHTML = '<div class="rounded-3xl border border-slate-200 bg-white p-8 text-center text-sm text-slate-500 shadow-soft">Loading...</div>'; panel.innerHTML = '<div class="rounded-3xl border border-slate-200 bg-white p-8 text-center text-sm text-slate-500 shadow-soft">Loading...</div>';
try { try {
const response = await fetch('/employee/dashboard/tab/' + encodeURIComponent(safeTab), { const response = await fetch('/employee/dashboard/tab/' + encodeURIComponent(safeTab), {