refactor: ♻️ make breadcrumbs bulletproof
This commit is contained in:
parent
9d5636defc
commit
dc2483b85a
2 changed files with 2009 additions and 3134 deletions
|
@ -6,7 +6,7 @@ type Breadcrumb = {
|
|||
href?: string;
|
||||
};
|
||||
|
||||
const newProviderBreadcrumbs = [
|
||||
const newProviderBreadcrumbs: Breadcrumb[] = [
|
||||
{
|
||||
href: "/configuration",
|
||||
label: "Configuration",
|
||||
|
@ -15,9 +15,9 @@ const newProviderBreadcrumbs = [
|
|||
label: "Add provider",
|
||||
href: "/providers",
|
||||
},
|
||||
] as Breadcrumb[];
|
||||
];
|
||||
|
||||
const breadcrumbsForRoute = {
|
||||
const breadcrumbsForRoute: Record<string, Breadcrumb[]> = {
|
||||
"/configuration": [
|
||||
{
|
||||
href: "/configuration",
|
||||
|
@ -39,12 +39,16 @@ const breadcrumbsForRoute = {
|
|||
href: "/providers/avatax",
|
||||
},
|
||||
],
|
||||
} as Record<string, Breadcrumb[]>;
|
||||
};
|
||||
|
||||
const useBreadcrumbs = () => {
|
||||
const router = useRouter();
|
||||
const breadcrumbs = breadcrumbsForRoute[router.pathname];
|
||||
|
||||
if (!breadcrumbs) {
|
||||
throw new Error(`No breadcrumbs for route ${router.pathname}`);
|
||||
}
|
||||
|
||||
return breadcrumbs;
|
||||
};
|
||||
|
||||
|
@ -53,7 +57,7 @@ export const AppBreadcrumbs = () => {
|
|||
|
||||
return (
|
||||
<Breadcrumbs>
|
||||
{breadcrumbs?.map((breadcrumb) => (
|
||||
{breadcrumbs.map((breadcrumb) => (
|
||||
<Breadcrumbs.Item href={breadcrumb.href}>{breadcrumb.label}</Breadcrumbs.Item>
|
||||
))}
|
||||
</Breadcrumbs>
|
||||
|
|
5129
pnpm-lock.yaml
5129
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue