2024-04-19 13:26:27 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { Button } from "@nextui-org/button";
|
|
|
|
|
import { BreadcrumbItem, Breadcrumbs } from "@nextui-org/react";
|
|
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
|
|
|
|
import { Image } from "@nextui-org/react";
|
|
|
|
|
import { FormLayoutIcon } from "../icons";
|
|
|
|
|
|
|
|
|
|
export const Breadcrumb = () => {
|
2024-11-13 08:29:27 +00:00
|
|
|
const [currentPage, setCurrentPage] = useState<React.Key>("");
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
const pathnameSplit = pathname.split("/");
|
|
|
|
|
pathnameSplit.shift();
|
|
|
|
|
let pathnameTransformed = pathnameSplit.map((item) => {
|
|
|
|
|
let words = item.split("-");
|
|
|
|
|
let capitalizedWords = words.map(
|
|
|
|
|
(word) => word.charAt(0).toUpperCase() + word.slice(1)
|
|
|
|
|
);
|
|
|
|
|
return capitalizedWords.join(" ");
|
|
|
|
|
});
|
2024-04-19 13:26:27 +00:00
|
|
|
|
2024-11-13 08:29:27 +00:00
|
|
|
console.log("pathname : ", pathnameTransformed);
|
2024-04-19 13:26:27 +00:00
|
|
|
|
2024-11-13 08:29:27 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
setCurrentPage(pathnameSplit[pathnameSplit.length - 1]);
|
|
|
|
|
}, [pathnameSplit]);
|
2024-04-19 13:26:27 +00:00
|
|
|
|
2024-11-13 08:29:27 +00:00
|
|
|
const handleAction = (key: any) => {
|
|
|
|
|
const keyIndex = pathnameSplit.indexOf(key);
|
|
|
|
|
const combinedPath = pathnameSplit.slice(0, keyIndex + 1).join("/");
|
|
|
|
|
router.push("/" + combinedPath);
|
|
|
|
|
};
|
2024-04-19 13:26:27 +00:00
|
|
|
|
2024-11-13 08:29:27 +00:00
|
|
|
return (
|
2025-01-17 02:57:45 +00:00
|
|
|
<div className="h-[100px] border-b-2">
|
2024-11-13 08:29:27 +00:00
|
|
|
<div className="px-4 md:px-8">
|
2025-01-17 02:57:45 +00:00
|
|
|
<div className="flex flex-row justify-between items-center py-3">
|
|
|
|
|
<div className="">
|
2024-11-13 08:29:27 +00:00
|
|
|
<p className="text-2xl font-semibold mb-2">
|
|
|
|
|
{pathnameTransformed[pathnameTransformed.length - 1]}
|
|
|
|
|
</p>
|
|
|
|
|
<Breadcrumbs
|
|
|
|
|
underline="active"
|
|
|
|
|
onAction={(key) => handleAction(key)}
|
|
|
|
|
>
|
2025-01-17 02:57:45 +00:00
|
|
|
{pathnameTransformed?.map(
|
|
|
|
|
(item, index) =>
|
|
|
|
|
item !== "Admin" && (
|
|
|
|
|
<BreadcrumbItem
|
|
|
|
|
key={pathnameSplit[index]}
|
|
|
|
|
isCurrent={pathnameSplit[index] === currentPage}
|
|
|
|
|
>
|
|
|
|
|
{item}
|
|
|
|
|
</BreadcrumbItem>
|
|
|
|
|
)
|
|
|
|
|
)}
|
2024-11-13 08:29:27 +00:00
|
|
|
</Breadcrumbs>
|
|
|
|
|
</div>
|
2025-01-17 02:57:45 +00:00
|
|
|
<FormLayoutIcon width={50} height={50} />
|
2024-11-13 08:29:27 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2024-04-19 13:26:27 +00:00
|
|
|
};
|