Unify Partner navigation and align full-width header
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
{% extends "ui/templates/base/layout.html" %}
|
||||
{% block content %}
|
||||
{% include "ui/templates/components/partner_navigation_v2.html" %}
|
||||
|
||||
<div class="space-y-6">
|
||||
<section class="rounded-3xl border border-slate-200 bg-white p-6 shadow-soft">
|
||||
<section class="space-y-6">
|
||||
<div class="rounded-3xl border border-slate-200 bg-white p-6 shadow-soft">
|
||||
<div class="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
|
||||
<div>
|
||||
<p class="text-xs font-semibold uppercase tracking-[0.24em] text-brand-600">Branch Operations Control Centre</p>
|
||||
@@ -16,132 +14,90 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
{% set tabs = [
|
||||
('overview','Overview'),
|
||||
('branch-work','Branch Work'),
|
||||
('clients','Clients'),
|
||||
('staff','Staff'),
|
||||
('review','Review'),
|
||||
('billing','Billing'),
|
||||
('reports','Reports'),
|
||||
('wizards','Wizards')
|
||||
] %}
|
||||
{# Dashboard sections are now part of the unified Partner Dashboard submenu. #}
|
||||
|
||||
<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 %}" {% if active_tab == code %}aria-current="page"{% endif %}>{{ label }}</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="partner-dashboard-panel">
|
||||
{% include 'modules/partner_dashboard/templates/partner_dashboard/partials/' ~ (active_tab|replace('-', '_')) ~ '.html' ignore missing %}
|
||||
</section>
|
||||
</div>
|
||||
<div id="partner-dashboard-panel"
|
||||
data-initial-tab="{{ active_tab }}"
|
||||
class="min-h-[360px]">
|
||||
<div class="rounded-3xl border border-slate-200 bg-white p-8 text-center text-sm text-slate-500 shadow-soft">Loading dashboard...</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
(function(){
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const panel = document.getElementById('partner-dashboard-panel');
|
||||
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);
|
||||
if (!panel) return;
|
||||
|
||||
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);
|
||||
const dashboardLinks = Array.from(document.querySelectorAll(
|
||||
'[data-uiux-v2-pilot="partner"] a[href^="/partner/dashboard?tab="]'
|
||||
));
|
||||
|
||||
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 tabFromLink(link) {
|
||||
try {
|
||||
return new URL(link.href, window.location.origin).searchParams.get('tab') || 'overview';
|
||||
} catch (error) {
|
||||
return 'overview';
|
||||
}
|
||||
}
|
||||
|
||||
function setActiveTab(tab) {
|
||||
allButtons.forEach(button => {
|
||||
applyActiveClasses(button, button.dataset.tab === tab);
|
||||
function setActive(tabName) {
|
||||
dashboardLinks.forEach((link) => {
|
||||
const active = tabFromLink(link) === tabName;
|
||||
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 {
|
||||
link.removeAttribute('aria-current');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function loadTab(tab) {
|
||||
setActiveTab(tab);
|
||||
if (mobileMenu) {
|
||||
mobileMenu.open = false;
|
||||
}
|
||||
|
||||
async function loadTab(tabName, pushState) {
|
||||
setActive(tabName);
|
||||
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('/partner/dashboard/tab/' + encodeURIComponent(tab), {
|
||||
headers: {'X-Requested-With': 'fetch'}
|
||||
const response = await fetch('/partner/dashboard/tab/' + encodeURIComponent(tabName), {
|
||||
headers: { 'X-Requested-With': 'fetch' }
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('HTTP ' + response.status);
|
||||
}
|
||||
if (!response.ok) throw new Error('Tab load failed');
|
||||
|
||||
panel.innerHTML = await response.text();
|
||||
history.replaceState(null, '', '/partner/dashboard?tab=' + encodeURIComponent(tab));
|
||||
|
||||
if (pushState) {
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('tab', tabName);
|
||||
history.pushState({ tab: tabName }, '', url.toString());
|
||||
}
|
||||
|
||||
document.querySelectorAll('[data-uiux-v2-pilot="partner"] details[open]').forEach((details) => {
|
||||
details.open = false;
|
||||
});
|
||||
} 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>';
|
||||
panel.innerHTML = '<div class="rounded-3xl border border-red-200 bg-red-50 p-6 text-sm text-red-700 shadow-soft">Unable to load this dashboard section. Please refresh the page.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
allButtons.forEach(button => {
|
||||
button.addEventListener('click', () => loadTab(button.dataset.tab));
|
||||
dashboardLinks.forEach((link) => {
|
||||
link.addEventListener('click', function (event) {
|
||||
if (window.location.pathname !== '/partner/dashboard') return;
|
||||
event.preventDefault();
|
||||
loadTab(tabFromLink(link), true);
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener('popstate', function () {
|
||||
const url = new URL(window.location.href);
|
||||
loadTab(url.searchParams.get('tab') || 'overview', false);
|
||||
});
|
||||
|
||||
loadTab(panel.dataset.initialTab || 'overview', false);
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user