Add secondary mobile menu to Partner dashboard

This commit is contained in:
A R R R Associates
2026-07-10 21:34:55 +05:30
parent 7d1b38581b
commit 69b33fa486
@@ -28,19 +28,44 @@
('reports','Reports'),
('wizards','Wizards')
] %}
<section class="rounded-3xl border border-slate-200 bg-white p-2 shadow-soft">
<div class="sm:hidden">
<label for="partner-dashboard-tab-select" class="sr-only">Dashboard section</label>
<select id="partner-dashboard-tab-select" class="w-full rounded-2xl border border-slate-200 bg-white px-4 py-3 text-sm font-semibold text-slate-700 focus:border-brand-500 focus:outline-none focus:ring-4 focus:ring-brand-100">
{% for code, label in tabs %}
<option value="{{ code }}" {% if active_tab == code %}selected{% endif %}>{{ label }}</option>
{% endfor %}
</select>
</div>
<div class="hidden gap-2 overflow-x-auto sm:flex" id="partner-dashboard-tabs">
<section class="rounded-3xl border border-slate-200 bg-white p-2 shadow-soft">
<details id="partner-dashboard-mobile-menu" class="group sm:hidden">
<summary class="flex cursor-pointer list-none items-center justify-between rounded-2xl px-4 py-3 text-sm font-semibold text-slate-800 transition hover:bg-slate-50 focus:outline-none focus-visible:ring-4 focus-visible:ring-brand-100">
<span class="flex items-center gap-3">
<svg class="h-5 w-5 text-slate-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 12h16M4 18h16" />
</svg>
<span>Dashboard Menu</span>
</span>
<span class="flex items-center gap-2 text-xs font-medium text-slate-500">
<span>Partner dashboard sections</span>
<svg class="h-4 w-4 transition-transform group-open:rotate-180" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="m6 9 6 6 6-6" />
</svg>
</span>
</summary>
<div class="mt-2 space-y-1 border-t border-slate-100 px-2 pb-2 pt-3" role="navigation" aria-label="Partner dashboard sections">
{% for code, label in tabs %}
<button
type="button"
data-tab="{{ code }}"
class="partner-dashboard-mobile-tab flex w-full items-center justify-between rounded-xl px-3 py-3 text-left text-sm font-semibold transition {% if active_tab == code %}bg-brand-600 text-white{% else %}text-slate-700 hover:bg-slate-100{% endif %}"
{% if active_tab == code %}aria-current="page"{% endif %}
>
<span>{{ label }}</span>
{% if active_tab == code %}
<span class="rounded-full bg-white/20 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide">Current</span>
{% endif %}
</button>
{% endfor %}
</div>
</details>
<div class="hidden gap-2 overflow-x-auto sm:flex" id="partner-dashboard-tabs" role="navigation" aria-label="Partner dashboard sections">
{% for code, label in tabs %}
<button type="button" data-tab="{{ code }}" class="partner-dashboard-tab whitespace-nowrap rounded-2xl px-4 py-2 text-sm font-semibold transition {% if active_tab == code %}bg-brand-600 text-white{% else %}text-slate-600 hover:bg-slate-100{% endif %}">{{ label }}</button>
<button type="button" data-tab="{{ code }}" class="partner-dashboard-tab whitespace-nowrap rounded-2xl px-4 py-2 text-sm font-semibold transition {% if active_tab == code %}bg-brand-600 text-white{% else %}text-slate-600 hover:bg-slate-100{% endif %}" {% if active_tab == code %}aria-current="page"{% endif %}>{{ label }}</button>
{% endfor %}
</div>
</section>
@@ -53,39 +78,70 @@
<script>
(function(){
const panel = document.getElementById('partner-dashboard-panel');
const buttons = Array.from(document.querySelectorAll('.partner-dashboard-tab'));
const select = document.getElementById('partner-dashboard-tab-select');
const desktopButtons = Array.from(document.querySelectorAll('.partner-dashboard-tab'));
const mobileButtons = Array.from(document.querySelectorAll('.partner-dashboard-mobile-tab'));
const mobileMenu = document.getElementById('partner-dashboard-mobile-menu');
const allButtons = desktopButtons.concat(mobileButtons);
function applyActiveClasses(button, active) {
button.classList.toggle('bg-brand-600', active);
button.classList.toggle('text-white', active);
button.classList.toggle('text-slate-600', !active && button.classList.contains('partner-dashboard-tab'));
button.classList.toggle('text-slate-700', !active && button.classList.contains('partner-dashboard-mobile-tab'));
button.classList.toggle('hover:bg-slate-100', !active);
if (active) {
button.setAttribute('aria-current', 'page');
} else {
button.removeAttribute('aria-current');
}
if (button.classList.contains('partner-dashboard-mobile-tab')) {
let badge = button.querySelector('[data-current-badge]');
if (active && !badge) {
badge = document.createElement('span');
badge.dataset.currentBadge = 'true';
badge.className = 'rounded-full bg-white/20 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wide';
badge.textContent = 'Current';
button.appendChild(badge);
} else if (!active && badge) {
badge.remove();
}
}
}
function setActiveTab(tab) {
buttons.forEach(btn => {
const active = btn.dataset.tab === tab;
btn.classList.toggle('bg-brand-600', active);
btn.classList.toggle('text-white', active);
btn.classList.toggle('text-slate-600', !active);
btn.classList.toggle('hover:bg-slate-100', !active);
allButtons.forEach(button => {
applyActiveClasses(button, button.dataset.tab === tab);
});
if (select && select.value !== tab) {
select.value = tab;
}
}
async function loadTab(tab) {
setActiveTab(tab);
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 res = await fetch('/partner/dashboard/tab/' + encodeURIComponent(tab), {headers: {'X-Requested-With':'fetch'}});
if (!res.ok) throw new Error('HTTP ' + res.status);
panel.innerHTML = await res.text();
const response = await fetch('/partner/dashboard/tab/' + encodeURIComponent(tab), {
headers: {'X-Requested-With': 'fetch'}
});
if (!response.ok) {
throw new Error('HTTP ' + response.status);
}
panel.innerHTML = await response.text();
history.replaceState(null, '', '/partner/dashboard?tab=' + encodeURIComponent(tab));
} catch (err) {
} catch (error) {
panel.innerHTML = '<div class="rounded-3xl border border-red-200 bg-red-50 p-6 text-sm font-semibold text-red-700">Unable to load tab. Please refresh the page.</div>';
}
}
buttons.forEach(btn => btn.addEventListener('click', () => loadTab(btn.dataset.tab)));
if (select) {
select.addEventListener('change', () => loadTab(select.value));
}
allButtons.forEach(button => {
button.addEventListener('click', () => loadTab(button.dataset.tab));
});
})();
</script>
{% endblock %}