From ee18af7877a11e98141334dd980adb5b76b68ca6 Mon Sep 17 00:00:00 2001 From: mariomitte Date: Fri, 7 Aug 2026 07:36:58 +0200 Subject: [PATCH] fix: correct work-order navbar state and actions Use prefix path matching so nested putni-nalozi routes highlight the correct nav item, load current user data in Navbar when auth token exists, and group PDF/DOCX work-order download buttons in one action block. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- frontend/src/components/Navbar.jsx | 14 ++++++-- .../dashboard/WorkOrderInvoicesPdfPage.jsx | 34 ++++++++++--------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx index c732828..2e2c03f 100644 --- a/frontend/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -4,7 +4,7 @@ import AuthWidget from './AuthWidget'; import UserDisplay from './ui/UserDisplay'; import { useEffect, useRef, useState } from 'preact/hooks'; import { useSpring, animated } from '@react-spring/web'; -import { hydrateAuthFromStorage } from '../stores/authStore'; +import { hydrateAuthFromStorage, loadCurrentUser, $user, $accessToken } from '../stores/authStore'; const ITEMS = [ { id: 'dashboard', label: 'Dashboard', href: '/' }, @@ -21,8 +21,12 @@ function normalizePath(p) { } function getActiveIndex(path) { - const idx = ITEMS.findIndex((item) => item.href === path); - return idx >= 0 ? idx : 0; + // Exact match (e.g. '/' → Dashboard) + const exact = ITEMS.findIndex((item) => item.href === path); + if (exact >= 0) return exact; + // Prefix match for sub-paths (e.g. '/putni-nalozi/racuni' → Putni nalozi) + const prefix = ITEMS.findIndex((item) => item.href !== '/' && path.startsWith(item.href)); + return prefix >= 0 ? prefix : 0; } export default function Navbar({ minimal = false }) { @@ -55,6 +59,10 @@ export default function Navbar({ minimal = false }) { // Mount: izmjeri početnu poziciju bez animacije, pa uključi animaciju za buduće navigacije useEffect(() => { hydrateAuthFromStorage(); + // Učitaj korisnika ako token postoji ali $user još nije popunjen + if (!$user.get() && $accessToken.get()) { + loadCurrentUser(); + } const timer = setTimeout(() => { measureIndicator(); diff --git a/frontend/src/components/dashboard/WorkOrderInvoicesPdfPage.jsx b/frontend/src/components/dashboard/WorkOrderInvoicesPdfPage.jsx index 9c1cd74..fe54e7c 100644 --- a/frontend/src/components/dashboard/WorkOrderInvoicesPdfPage.jsx +++ b/frontend/src/components/dashboard/WorkOrderInvoicesPdfPage.jsx @@ -321,22 +321,24 @@ export default function WorkOrderInvoicesPdfPage() { {workOrder ? `Dizalica: ${workOrder.crane_label || workOrder.crane || '-'}` : 'Pregled računa prije kreiranja PDF-a.'}

- - +
+ + +