Unify Employee navigation and align full-width header

This commit is contained in:
A R R R Associates
2026-07-11 08:05:15 +05:30
parent 5d5a0d9bd6
commit 2fbd1b5069
3 changed files with 107 additions and 117 deletions
@@ -1,7 +1,6 @@
{% extends "ui/templates/base/layout.html" %}
{% block content %}
<div class="space-y-6" id="employee-portal-root">
{% include "ui/templates/components/staff_navigation_v2.html" %}
<section class="overflow-hidden rounded-3xl border border-slate-200 bg-white shadow-soft">
<div class="bg-gradient-to-r from-brand-700 via-brand-600 to-slate-900 px-6 py-6 text-white">
<div class="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
@@ -22,80 +21,25 @@
</div>
</section>
{% set main_tabs = [
('overview','Overview'),
('work','Work'),
('attendance','Attendance'),
('hr','HR & Profile'),
('reports','Reports')
] %}
{# Dashboard sections are now part of the unified Staff Dashboard submenu. #}
<section class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-soft">
<div class="sm:hidden">
<details id="employee-dashboard-mobile-menu" class="group">
<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">
<span class="inline-flex items-center gap-2">
<svg class="h-5 w-5 group-open:hidden" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path stroke-linecap="round" d="M4 6h16M4 12h16M4 18h16" />
</svg>
<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>
</section>
<section id="employee-portal-panel" class="space-y-6">
{% include "modules/employees/templates/employees/portal_partials/overview.html" %}
<section id="employee-portal-panel"
data-initial-tab="{{ active_tab }}"
class="space-y-6">
<div class="rounded-3xl border border-slate-200 bg-white p-8 text-center text-sm text-slate-500 shadow-soft">Loading dashboard...</div>
</section>
</div>
<script>
(function () {
"use strict";
const panel = document.getElementById('employee-portal-panel');
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) return;
const dashboardLinks = Array.from(document.querySelectorAll(
'[data-uiux-v2-pilot="staff"] a[href^="/employee/dashboard?tab="]'
));
const groupMap = {
'overview': 'overview',
@@ -119,43 +63,25 @@
'reports': 'reports'
};
function tabFromLink(link) {
try {
return new URL(link.href, window.location.origin).searchParams.get('tab') || 'overview';
} catch (error) {
return 'overview';
}
}
function setActive(tabName) {
const activeGroup = groupMap[tabName] || tabName || 'overview';
mainTabs.forEach(function (button) {
const active = button.dataset.tab === activeGroup;
const isMobileButton = button.closest('#employee-dashboard-mobile-menu') !== null;
if (isMobileButton) {
button.classList.toggle('bg-brand-50', active);
button.classList.toggle('text-brand-700', active);
button.classList.toggle('bg-white', !active);
button.classList.toggle('text-slate-800', !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();
}
dashboardLinks.forEach(function (link) {
const active = tabFromLink(link) === activeGroup;
link.classList.toggle('bg-brand-50', active);
link.classList.toggle('text-brand-700', active);
link.classList.toggle('text-slate-700', !active);
if (active) {
link.setAttribute('aria-current', 'page');
} 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);
link.removeAttribute('aria-current');
}
});
}
@@ -163,19 +89,26 @@
async function loadTab(tabName, pushState) {
const safeTab = tabName || 'overview';
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>';
try {
const response = await fetch('/employee/dashboard/tab/' + encodeURIComponent(safeTab), {
headers: {'X-Requested-With': 'fetch'}
});
if (!response.ok) throw new Error('HTTP ' + response.status);
panel.innerHTML = await response.text();
if (pushState) {
const url = new URL(window.location.href);
url.searchParams.set('tab', safeTab);
window.history.pushState({tab: safeTab}, '', url.toString());
}
document.querySelectorAll('[data-uiux-v2-pilot="staff"] details[open]').forEach(function (details) {
details.open = false;
});
if (window.EmployeePortalGeo && typeof window.EmployeePortalGeo.bind === 'function') {
window.EmployeePortalGeo.bind();
}
@@ -184,17 +117,20 @@
}
}
document.addEventListener('click', function (event) {
const button = event.target.closest('.employee-portal-tab');
if (!button || !button.dataset.tab) return;
event.preventDefault();
loadTab(button.dataset.tab || 'overview', true);
dashboardLinks.forEach(function (link) {
link.addEventListener('click', function (event) {
if (window.location.pathname !== '/employee/dashboard') return;
event.preventDefault();
loadTab(tabFromLink(link), true);
});
});
window.addEventListener('popstate', function (event) {
const params = new URLSearchParams(window.location.search);
loadTab((event.state && event.state.tab) || params.get('tab') || 'overview', false);
});
loadTab(panel.dataset.initialTab || 'overview', false);
})();
</script>
{% endblock %}