BranchButton.js 734 B

123456789101112131415161718192021222324252627282930
  1. // components/BranchButton.js
  2. "use client";
  3. import { Button } from "@nextui-org/react";
  4. import { useRouter, usePathname } from "next/navigation";
  5. export default function BranchButton({ branchName }) {
  6. const router = useRouter();
  7. const pathname = usePathname();
  8. const handleNavigation = () => {
  9. router.push(`/admin-view/${branchName}`);
  10. };
  11. // Überprüfe, ob der aktuelle Pfad aktiv ist oder mit dem Branch-Namen beginnt
  12. const isActive = pathname.startsWith(`/admin-view/${branchName}`);
  13. return (
  14. <Button
  15. variant="flat"
  16. color="primary"
  17. onClick={handleNavigation}
  18. className={`hover:bg-orange-500 hover:text-white ${
  19. isActive ? "bg-orange-500 text-white" : ""
  20. }`}
  21. >
  22. {branchName}
  23. </Button>
  24. );
  25. }