Group employee portal tabs

This commit is contained in:
A R R R Associates
2026-07-05 21:33:32 +05:30
parent 765f6acc29
commit eb15d76a4d
5 changed files with 134 additions and 30 deletions
@@ -7,7 +7,7 @@
<div>
<p class="text-xs font-semibold uppercase tracking-[0.22em] text-brand-100">My Workspace</p>
<h2 class="mt-2 text-2xl font-semibold">Employee Portal</h2>
<p class="mt-2 max-w-3xl text-sm text-brand-100">Punch attendance, view priority work, track documents, leave, payslips and alerts from one staff workspace.</p>
<p class="mt-2 max-w-3xl text-sm text-brand-100">Punch attendance, view priority work, track HR details, documents, payslips and alerts from one staff workspace.</p>
</div>
<div class="flex flex-wrap gap-2">
{% if employee %}
@@ -21,30 +21,21 @@
</div>
</section>
{% set tabs = [
{% set main_tabs = [
('overview','Overview'),
('work','My Work Board'),
('due-today','Due Today'),
('overdue','Overdue'),
('client-pending','Client Pending'),
('returned','Returned / Blocked'),
('attendance','My Attendance'),
('profile','My Profile'),
('leave','My Leave'),
('documents','My Documents'),
('payslips','My Payslips'),
('offboarding','My Offboarding'),
('alerts','My Alert'),
('reports','My Reports')
('work','Work'),
('attendance','Attendance'),
('hr','HR & Profile'),
('reports','Reports')
] %}
<section class="rounded-2xl border border-slate-200 bg-white p-3 shadow-soft">
<div class="mb-2 px-1 text-xs font-semibold uppercase tracking-wide text-slate-500">My Workspace</div>
<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 tabs %}
<button type="button" data-tab="{{ code }}" class="employee-portal-tab inline-flex shrink-0 items-center rounded-xl px-3 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 == 'alerts' 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 %}
{% 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>
@@ -59,12 +50,35 @@
<script>
(function () {
const panel = document.getElementById('employee-portal-panel');
const tabs = Array.from(document.querySelectorAll('.employee-portal-tab'));
if (!panel || !tabs.length) return;
const mainTabs = Array.from(document.querySelectorAll('.employee-portal-main-tab'));
if (!panel || !mainTabs.length) return;
const groupMap = {
'overview': 'overview',
'work': 'work',
'work-board': 'work',
'due-today': 'work',
'overdue': 'work',
'client-pending': 'work',
'returned': 'work',
'documents': 'work',
'attendance': 'attendance',
'attendance-details': 'attendance',
'attendance-punch': 'attendance',
'attendance-history': 'attendance',
'hr': 'hr',
'profile': 'hr',
'leave': 'hr',
'payslips': 'hr',
'offboarding': 'hr',
'alerts': 'hr',
'reports': 'reports'
};
function setActive(tabName) {
tabs.forEach(function (button) {
const active = button.dataset.tab === tabName;
const activeGroup = groupMap[tabName] || tabName || 'overview';
mainTabs.forEach(function (button) {
const active = button.dataset.tab === activeGroup;
button.classList.toggle('bg-brand-600', active);
button.classList.toggle('text-white', active);
button.classList.toggle('shadow-soft', active);
@@ -77,18 +91,19 @@
}
async function loadTab(tabName, pushState) {
setActive(tabName);
const safeTab = tabName || 'overview';
setActive(safeTab);
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(tabName), {
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', tabName);
window.history.pushState({tab: tabName}, '', url.toString());
url.searchParams.set('tab', safeTab);
window.history.pushState({tab: safeTab}, '', url.toString());
}
if (window.EmployeePortalGeo && typeof window.EmployeePortalGeo.bind === 'function') {
window.EmployeePortalGeo.bind();