From f38f17cc1ab5972ab9018c662f32b468f6f61768 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 9 Apr 2026 12:22:20 +0000 Subject: [PATCH] modified toolbar --- .../components/building-passport/Toolbar.tsx | 174 +++++++----------- .../building-passport/[propertyId]/layout.tsx | 2 +- 2 files changed, 68 insertions(+), 108 deletions(-) diff --git a/src/app/components/building-passport/Toolbar.tsx b/src/app/components/building-passport/Toolbar.tsx index 329c33a1..5dc25708 100644 --- a/src/app/components/building-passport/Toolbar.tsx +++ b/src/app/components/building-passport/Toolbar.tsx @@ -1,22 +1,17 @@ "use client"; -import { useState } from "react"; +import { useState, useTransition } from "react"; +import { useRouter, usePathname } from "next/navigation"; import { NewspaperIcon, HomeModernIcon, WrenchScrewdriverIcon, - SunIcon, CircleStackIcon, HeartIcon, + ArrowPathIcon, + ClipboardDocumentCheckIcon, } from "@heroicons/react/24/outline"; -import { - NavigationMenu, - NavigationMenuItem, - NavigationMenuList, - NavigationMenuLink, -} from "@/app/shadcn_components/ui/navigation-menu"; -import { Button } from "@/app/shadcn_components/ui/button"; -import { cva } from "class-variance-authority"; +import { cn } from "@/lib/utils"; import { getUploadedFile } from "@/app/db/surveyDB/schema/surveyDB"; import BookSurveyModal from "@/app/portfolio/[slug]/components/BookSurveyModal"; import SuccessToast from "@/app/portfolio/[slug]/components/SuccessToast"; @@ -29,36 +24,6 @@ interface ToolbarProps { decentHomes: getUploadedFile; } -const navigationMenuTriggerStyle = cva( - [ - "bg-gray-50", - "cursor-pointer", - "group", - "inline-flex", - "h-10", - "w-max", - "items-center", - "justify-center", - "rounded-md", - "bg-background", - "px-4", - "py-2", - "text-sm", - "font-medium", - "transition-colors", - "hover:bg-gray-200", - "hover:text-accent-foreground", - "focus:bg-accent", - "focus:text-accent-foreground", - "focus:outline-none", - "disabled:pointer-events-none", - "disabled:opacity-50", - "data-[active]:bg-accent/50", - "data-[state=open]:bg-gray-200", - "text-gray-900", - ].join(" "), -); - export function Toolbar({ propertyId, portfolioId, @@ -67,82 +32,78 @@ export function Toolbar({ }: ToolbarProps) { const [openModal, setOpenModal] = useState(false); const [showToast, setShowToast] = useState(false); + const [loadingTab, setLoadingTab] = useState(null); + const [isPending, startTransition] = useTransition(); + const router = useRouter(); + const pathname = usePathname(); - const preAssessmentReportButton = ( - - - Property Details - - ); + const baseUrl = `/portfolio/${portfolioId}/building-passport/${propertyId}`; - const documentsButton = ( - - - Documents - - ); + const tabs = [ + { href: baseUrl, label: "Overview", icon: HomeModernIcon, exact: true }, + { href: `${baseUrl}/assessment`, label: "Property Details", icon: NewspaperIcon }, + ...(Object.keys(decentHomes).length > 0 && decentHomes.uprn + ? [{ href: `${baseUrl}/decent-homes`, label: "Decent Homes", icon: HeartIcon }] + : []), + { href: `${baseUrl}/plans`, label: "Retrofit Plans", icon: WrenchScrewdriverIcon }, + { href: `${baseUrl}/documents`, label: "Documents", icon: CircleStackIcon }, + ] as { href: string; label: string; icon: React.ElementType; exact?: boolean }[]; - const recommendationsButton = ( - - - Retrofit Plans - - ); - - const decentHomesButton = ( - - - Decent Homes - - ); + const handleNav = (href: string) => { + if (pathname === href) return; + setLoadingTab(href); + startTransition(() => { + router.push(href); + }); + }; return ( <> -
- {/* Left side: navigation */} - - - - Overview - +
+ {/* Tabs */} +
+ {tabs.map((tab) => { + const isActive = tab.exact + ? pathname === tab.href + : pathname.startsWith(tab.href); + const isLoading = loadingTab === tab.href && isPending; + const Icon = tab.icon; - - {preAssessmentReportButton} - {Object.keys(decentHomes).length > 0 && - decentHomes.uprn && - decentHomesButton} - {recommendationsButton} - {documentsButton} - - - - {/* ✅ Right side: Book a Survey button */} -
- + return ( + + ); + })}
+ + {/* Book Assessment button */} +
- {/* ✅ Modal */} {openModal && ( )} - {/* ✅ Toast */}

{propertyMeta.postcode}

-
+