Unify Firm Admin navigation and align full-width header
This commit is contained in:
@@ -17,80 +17,88 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% set tabs = [
|
||||
('overview','Overview'),
|
||||
('branches','Branches'),
|
||||
('users','Users & Roles'),
|
||||
('firm-settings','Firm Settings'),
|
||||
('services','Services Setup'),
|
||||
('financial-years','Financial Years'),
|
||||
('reports','Reports'),
|
||||
('wizards','Wizards'),
|
||||
('audit-logs','Audit Logs')
|
||||
] %}
|
||||
<div class="hidden rounded-3xl border border-slate-200 bg-white p-2 shadow-soft sm:block">
|
||||
<div class="flex gap-2 overflow-x-auto" id="firm-admin-tabs">
|
||||
{% for code, label in tabs %}
|
||||
<button type="button" data-tab="{{ code }}" class="firm-admin-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>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{# Dashboard sections are now part of the unified Firm Admin Dashboard submenu. #}
|
||||
|
||||
<details id="firm-admin-mobile-menu" class="group overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-soft sm:hidden">
|
||||
<summary class="flex cursor-pointer list-none items-center justify-between gap-3 px-4 py-3 text-sm font-semibold text-slate-800">
|
||||
<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">Firm administration sections</span>
|
||||
</summary>
|
||||
<div class="space-y-1 border-t border-slate-100 bg-slate-50/80 p-3">
|
||||
{% for code, label in tabs %}
|
||||
<button type="button" data-tab="{{ code }}" class="firm-admin-tab block w-full rounded-xl px-3 py-2.5 text-left text-sm font-semibold transition {% if active_tab == code %}bg-brand-600 text-white{% else %}bg-white text-slate-700 hover:bg-slate-100{% endif %}">{{ label }}</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<div id="firm-admin-panel" class="min-h-[24rem]">
|
||||
{% include "modules/firm_admin_dashboard/templates/firm_admin_dashboard/partials/" ~ active_tab ~ ".html" ignore missing %}
|
||||
<div id="firm-admin-panel"
|
||||
data-initial-tab="{{ active_tab }}"
|
||||
class="min-h-[24rem]">
|
||||
<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('firm-admin-panel');
|
||||
const buttons = Array.from(document.querySelectorAll('.firm-admin-tab'));
|
||||
if (!panel || !buttons.length) return;
|
||||
function activate(tab){
|
||||
buttons.forEach(btn => {
|
||||
const on = btn.dataset.tab === tab;
|
||||
btn.classList.toggle('bg-brand-600', on);
|
||||
btn.classList.toggle('text-white', on);
|
||||
btn.classList.toggle('text-slate-600', !on);
|
||||
btn.classList.toggle('hover:bg-slate-100', !on);
|
||||
});
|
||||
}
|
||||
async function loadTab(tab){
|
||||
activate(tab);
|
||||
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>';
|
||||
if (!panel) return;
|
||||
|
||||
const dashboardLinks = Array.from(document.querySelectorAll(
|
||||
'[data-uiux-v2-pilot="firm-admin"] a[href^="/firm-admin/dashboard?tab="]'
|
||||
));
|
||||
|
||||
function tabFromLink(link) {
|
||||
try {
|
||||
const res = await fetch('/firm-admin/dashboard/tab/' + encodeURIComponent(tab), {headers: {'X-Requested-With':'fetch'}});
|
||||
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||
panel.innerHTML = await res.text();
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('tab', tab);
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
} catch (err) {
|
||||
panel.innerHTML = '<div class="rounded-3xl border border-red-200 bg-red-50 p-6 text-sm font-semibold text-red-800 shadow-soft">Unable to load tab. Please refresh the page.</div>';
|
||||
return new URL(link.href, window.location.origin).searchParams.get('tab') || 'overview';
|
||||
} catch (error) {
|
||||
return 'overview';
|
||||
}
|
||||
}
|
||||
buttons.forEach(btn => btn.addEventListener('click', () => {
|
||||
loadTab(btn.dataset.tab);
|
||||
const mobileMenu = document.getElementById('firm-admin-mobile-menu');
|
||||
if (mobileMenu) mobileMenu.open = false;
|
||||
}));
|
||||
|
||||
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(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('/firm-admin/dashboard/tab/' + encodeURIComponent(tabName), {
|
||||
headers: { 'X-Requested-With': 'fetch' }
|
||||
});
|
||||
if (!response.ok) throw new Error('Tab load failed');
|
||||
|
||||
panel.innerHTML = await response.text();
|
||||
|
||||
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="firm-admin"] 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-800 shadow-soft">Unable to load this dashboard section. Please refresh the page.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
dashboardLinks.forEach((link) => {
|
||||
link.addEventListener('click', function (event) {
|
||||
if (window.location.pathname !== '/firm-admin/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