Files
myeasycms-v2/apps/web/app/(dashboard)/home/_components/home-sidebar.tsx
giancarlo df239e9903 Update user authentication and refactor UI components
Refactored the user authentication method in the dashboard from getSession to getUser, and updated its related variables accordingly. UI components have also been modified, which includes streamlining the importation of the 'cn' function and exporting the 'Stepper' function directly. Lastly, the 'Stepper' function is now included in the package.json for the UI component package.
2024-04-15 19:07:59 +08:00

51 lines
1.6 KiB
TypeScript

import { use } from 'react';
import { cookies } from 'next/headers';
import { If } from '@kit/ui/if';
import { Sidebar, SidebarContent, SidebarNavigation } from '@kit/ui/sidebar';
import { AppLogo } from '~/components/app-logo';
import featuresFlagConfig from '~/config/feature-flags.config';
import { personalAccountSidebarConfig } from '~/config/personal-account-sidebar.config';
// home imports
import { HomeSidebarAccountSelector } from '../_components/home-sidebar-account-selector';
import { ProfileAccountDropdownContainer } from '../_components/personal-account-dropdown-container';
import { loadUserWorkspace } from '../_lib/load-user-workspace';
export function HomeSidebar() {
const collapsed = getSidebarCollapsed();
const { accounts, user } = use(loadUserWorkspace());
return (
<Sidebar collapsed={collapsed}>
<SidebarContent className={'my-4'}>
<If
condition={featuresFlagConfig.enableTeamAccounts}
fallback={<AppLogo className={'py-2'} />}
>
<HomeSidebarAccountSelector
collapsed={collapsed}
accounts={accounts}
/>
</If>
</SidebarContent>
<SidebarContent className={`h-[calc(100%-160px)] overflow-y-auto`}>
<SidebarNavigation config={personalAccountSidebarConfig} />
</SidebarContent>
<div className={'absolute bottom-4 left-0 w-full'}>
<SidebarContent>
<ProfileAccountDropdownContainer collapsed={collapsed} user={user} />
</SidebarContent>
</div>
</Sidebar>
);
}
function getSidebarCollapsed() {
return cookies().get('sidebar-collapsed')?.value === 'true';
}