-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathwithSidebar.tsx
More file actions
47 lines (40 loc) · 1.22 KB
/
withSidebar.tsx
File metadata and controls
47 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use client';
import Sidebar from '@node-core/ui-components/Containers/Sidebar';
import { usePathname } from 'next/navigation';
import {
useLocale,
useTranslations,
type RichTranslationValues,
} from 'next-intl';
import type { FC } from 'react';
import Link from '@/components/Link';
import { useSiteNavigation } from '@/hooks/server';
import { useRouter } from '@/navigation.mjs';
import type { NavigationKeys } from '@/types';
type WithSidebarProps = {
navKeys: Array<NavigationKeys>;
context?: Record<string, RichTranslationValues>;
};
const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context }) => {
const { getSideNavigation } = useSiteNavigation();
const pathname = usePathname()!;
const locale = useLocale();
const t = useTranslations();
const { push } = useRouter();
const mappedSidebarItems = getSideNavigation(navKeys, context).map(
([, { label, items }]) => ({
groupName: label,
items: items.map(([, item]) => item),
})
);
return (
<Sidebar
groups={mappedSidebarItems}
pathname={pathname.replace(`/${locale}`, '')}
title={t('components.common.sidebar.title')}
onSelect={value => push(value)}
as={Link}
/>
);
};
export default WithSidebar;