Layouts refactoring (#96)
* Refactor layouts so that we can use the hook useSidebar from within the content of the layouts * Updated packages
This commit is contained in:
committed by
GitHub
parent
4efe5f3f7b
commit
af6217b410
@@ -5,7 +5,6 @@ import {
|
||||
SidebarFooter,
|
||||
SidebarHeader,
|
||||
SidebarNavigation,
|
||||
SidebarProvider,
|
||||
} from '@kit/ui/shadcn-sidebar';
|
||||
import { cn } from '@kit/ui/utils';
|
||||
|
||||
@@ -21,46 +20,43 @@ import { HomeAccountSelector } from './home-account-selector';
|
||||
|
||||
interface HomeSidebarProps {
|
||||
workspace: UserWorkspace;
|
||||
minimized: boolean;
|
||||
}
|
||||
|
||||
const minimized = personalAccountNavigationConfig.sidebarCollapsed;
|
||||
|
||||
export function HomeSidebar(props: HomeSidebarProps) {
|
||||
const { workspace, user, accounts } = props.workspace;
|
||||
|
||||
return (
|
||||
<SidebarProvider minimized={minimized}>
|
||||
<Sidebar>
|
||||
<SidebarHeader className={'h-16 justify-center'}>
|
||||
<div className={'flex items-center justify-between space-x-2'}>
|
||||
<If
|
||||
condition={featuresFlagConfig.enableTeamAccounts}
|
||||
fallback={
|
||||
<AppLogo
|
||||
className={cn({
|
||||
'max-w-full': minimized,
|
||||
'py-2': !minimized,
|
||||
})}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<HomeAccountSelector userId={user.id} accounts={accounts} />
|
||||
</If>
|
||||
<Sidebar>
|
||||
<SidebarHeader className={'h-16 justify-center'}>
|
||||
<div className={'flex items-center justify-between space-x-2'}>
|
||||
<If
|
||||
condition={featuresFlagConfig.enableTeamAccounts}
|
||||
fallback={
|
||||
<AppLogo
|
||||
className={cn({
|
||||
'max-w-full': props.minimized,
|
||||
'py-2': !props.minimized,
|
||||
})}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<HomeAccountSelector userId={user.id} accounts={accounts} />
|
||||
</If>
|
||||
|
||||
<div className={'group-data-[minimized=true]:hidden'}>
|
||||
<UserNotifications userId={user.id} />
|
||||
</div>
|
||||
<div className={'group-data-[minimized=true]:hidden'}>
|
||||
<UserNotifications userId={user.id} />
|
||||
</div>
|
||||
</SidebarHeader>
|
||||
</div>
|
||||
</SidebarHeader>
|
||||
|
||||
<SidebarContent>
|
||||
<SidebarNavigation config={personalAccountNavigationConfig} />
|
||||
</SidebarContent>
|
||||
<SidebarContent>
|
||||
<SidebarNavigation config={personalAccountNavigationConfig} />
|
||||
</SidebarContent>
|
||||
|
||||
<SidebarFooter>
|
||||
<ProfileAccountDropdownContainer user={user} account={workspace} />
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
</SidebarProvider>
|
||||
<SidebarFooter>
|
||||
<ProfileAccountDropdownContainer user={user} account={workspace} />
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ import { use } from 'react';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
|
||||
import { If } from '@kit/ui/if';
|
||||
import {
|
||||
Page,
|
||||
PageLayoutStyle,
|
||||
PageMobileNavigation,
|
||||
PageNavigation,
|
||||
} from '@kit/ui/page';
|
||||
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
||||
|
||||
import { AppLogo } from '~/components/app-logo';
|
||||
import { personalAccountNavigationConfig } from '~/config/personal-account-navigation.config';
|
||||
@@ -22,36 +22,70 @@ import { HomeSidebar } from './_components/home-sidebar';
|
||||
import { loadUserWorkspace } from './_lib/server/load-user-workspace';
|
||||
|
||||
function UserHomeLayout({ children }: React.PropsWithChildren) {
|
||||
const workspace = use(loadUserWorkspace());
|
||||
const style = use(getLayoutStyle());
|
||||
|
||||
return (
|
||||
<Page style={style}>
|
||||
<PageNavigation>
|
||||
<If condition={style === 'header'}>
|
||||
<HomeMenuNavigation workspace={workspace} />
|
||||
</If>
|
||||
if (style === 'sidebar') {
|
||||
return <SidebarLayout>{children}</SidebarLayout>;
|
||||
}
|
||||
|
||||
<If condition={style === 'sidebar'}>
|
||||
<HomeSidebar workspace={workspace} />
|
||||
</If>
|
||||
</PageNavigation>
|
||||
|
||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||
<AppLogo />
|
||||
|
||||
<HomeMobileNavigation workspace={workspace} />
|
||||
</PageMobileNavigation>
|
||||
|
||||
<UserWorkspaceContextProvider value={workspace}>
|
||||
{children}
|
||||
</UserWorkspaceContextProvider>
|
||||
</Page>
|
||||
);
|
||||
return <HeaderLayout>{children}</HeaderLayout>;
|
||||
}
|
||||
|
||||
export default withI18n(UserHomeLayout);
|
||||
|
||||
function SidebarLayout({ children }: React.PropsWithChildren) {
|
||||
const workspace = use(loadUserWorkspace());
|
||||
const sidebarMinimized = personalAccountNavigationConfig.sidebarCollapsed;
|
||||
|
||||
return (
|
||||
<UserWorkspaceContextProvider value={workspace}>
|
||||
<SidebarProvider minimized={sidebarMinimized}>
|
||||
<Page style={'sidebar'}>
|
||||
<PageNavigation>
|
||||
<HomeSidebar workspace={workspace} minimized={sidebarMinimized} />
|
||||
</PageNavigation>
|
||||
|
||||
<MobileNavigation workspace={workspace} />
|
||||
|
||||
{children}
|
||||
</Page>
|
||||
</SidebarProvider>
|
||||
</UserWorkspaceContextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function HeaderLayout({ children }: React.PropsWithChildren) {
|
||||
const workspace = use(loadUserWorkspace());
|
||||
|
||||
return (
|
||||
<UserWorkspaceContextProvider value={workspace}>
|
||||
<Page style={'header'}>
|
||||
<PageNavigation>
|
||||
<HomeMenuNavigation workspace={workspace} />
|
||||
</PageNavigation>
|
||||
|
||||
<MobileNavigation workspace={workspace} />
|
||||
|
||||
{children}
|
||||
</Page>
|
||||
</UserWorkspaceContextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function MobileNavigation({
|
||||
workspace,
|
||||
}: {
|
||||
workspace: Awaited<ReturnType<typeof loadUserWorkspace>>;
|
||||
}) {
|
||||
return (
|
||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||
<AppLogo />
|
||||
|
||||
<HomeMobileNavigation workspace={workspace} />
|
||||
</PageMobileNavigation>
|
||||
);
|
||||
}
|
||||
|
||||
async function getLayoutStyle() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
|
||||
@@ -7,13 +7,11 @@ import {
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarHeader,
|
||||
SidebarProvider,
|
||||
useSidebar,
|
||||
} from '@kit/ui/shadcn-sidebar';
|
||||
import { cn } from '@kit/ui/utils';
|
||||
|
||||
import { ProfileAccountDropdownContainer } from '~/components//personal-account-dropdown-container';
|
||||
import { getTeamAccountSidebarConfig } from '~/config/team-account-navigation.config';
|
||||
import { TeamAccountNotifications } from '~/home/[account]/_components/team-account-notifications';
|
||||
|
||||
import { TeamAccountAccountsSelector } from '../_components/team-account-accounts-selector';
|
||||
@@ -31,17 +29,13 @@ export function TeamAccountLayoutSidebar(props: {
|
||||
accounts: AccountModel[];
|
||||
user: User;
|
||||
}) {
|
||||
const minimized = getTeamAccountSidebarConfig(props.account).sidebarCollapsed;
|
||||
|
||||
return (
|
||||
<SidebarProvider minimized={minimized}>
|
||||
<SidebarContainer
|
||||
account={props.account}
|
||||
accountId={props.accountId}
|
||||
accounts={props.accounts}
|
||||
user={props.user}
|
||||
/>
|
||||
</SidebarProvider>
|
||||
<SidebarContainer
|
||||
account={props.account}
|
||||
accountId={props.accountId}
|
||||
accounts={props.accounts}
|
||||
user={props.user}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@ import { use } from 'react';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import { TeamAccountWorkspaceContextProvider } from '@kit/team-accounts/components';
|
||||
import { If } from '@kit/ui/if';
|
||||
import {
|
||||
Page,
|
||||
PageLayoutStyle,
|
||||
PageMobileNavigation,
|
||||
PageNavigation,
|
||||
} from '@kit/ui/page';
|
||||
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
||||
|
||||
import { AppLogo } from '~/components/app-logo';
|
||||
import { getTeamAccountSidebarConfig } from '~/config/team-account-navigation.config';
|
||||
@@ -27,9 +27,71 @@ type TeamWorkspaceLayoutProps = React.PropsWithChildren<{
|
||||
|
||||
function TeamWorkspaceLayout({ children, params }: TeamWorkspaceLayoutProps) {
|
||||
const account = use(params).account;
|
||||
const data = use(loadTeamWorkspace(account));
|
||||
const style = use(getLayoutStyle(account));
|
||||
|
||||
if (style === 'sidebar') {
|
||||
return <SidebarLayout account={account}>{children}</SidebarLayout>;
|
||||
}
|
||||
|
||||
return <HeaderLayout account={account}>{children}</HeaderLayout>;
|
||||
}
|
||||
|
||||
function SidebarLayout({
|
||||
account,
|
||||
children,
|
||||
}: React.PropsWithChildren<{
|
||||
account: string;
|
||||
}>) {
|
||||
const data = use(loadTeamWorkspace(account));
|
||||
|
||||
const accounts = data.accounts.map(({ name, slug, picture_url }) => ({
|
||||
label: name,
|
||||
value: slug,
|
||||
image: picture_url,
|
||||
}));
|
||||
|
||||
const minimized = getTeamAccountSidebarConfig(account).sidebarCollapsed;
|
||||
|
||||
return (
|
||||
<TeamAccountWorkspaceContextProvider value={data}>
|
||||
<SidebarProvider minimized={minimized}>
|
||||
<Page style={'sidebar'}>
|
||||
<PageNavigation>
|
||||
<TeamAccountLayoutSidebar
|
||||
account={account}
|
||||
accountId={data.account.id}
|
||||
accounts={accounts}
|
||||
user={data.user}
|
||||
/>
|
||||
</PageNavigation>
|
||||
|
||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||
<AppLogo />
|
||||
|
||||
<div className={'flex space-x-4'}>
|
||||
<TeamAccountLayoutMobileNavigation
|
||||
userId={data.user.id}
|
||||
accounts={accounts}
|
||||
account={account}
|
||||
/>
|
||||
</div>
|
||||
</PageMobileNavigation>
|
||||
|
||||
{children}
|
||||
</Page>
|
||||
</SidebarProvider>
|
||||
</TeamAccountWorkspaceContextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function HeaderLayout({
|
||||
account,
|
||||
children,
|
||||
}: React.PropsWithChildren<{
|
||||
account: string;
|
||||
}>) {
|
||||
const data = use(loadTeamWorkspace(account));
|
||||
|
||||
const accounts = data.accounts.map(({ name, slug, picture_url }) => ({
|
||||
label: name,
|
||||
value: slug,
|
||||
@@ -37,38 +99,27 @@ function TeamWorkspaceLayout({ children, params }: TeamWorkspaceLayoutProps) {
|
||||
}));
|
||||
|
||||
return (
|
||||
<Page style={style}>
|
||||
<PageNavigation>
|
||||
<If condition={style === 'sidebar'}>
|
||||
<TeamAccountLayoutSidebar
|
||||
account={account}
|
||||
accountId={data.account.id}
|
||||
accounts={accounts}
|
||||
user={data.user}
|
||||
/>
|
||||
</If>
|
||||
|
||||
<If condition={style === 'header'}>
|
||||
<TeamAccountWorkspaceContextProvider value={data}>
|
||||
<Page style={'header'}>
|
||||
<PageNavigation>
|
||||
<TeamAccountNavigationMenu workspace={data} />
|
||||
</If>
|
||||
</PageNavigation>
|
||||
</PageNavigation>
|
||||
|
||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||
<AppLogo />
|
||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||
<AppLogo />
|
||||
|
||||
<div className={'flex space-x-4'}>
|
||||
<TeamAccountLayoutMobileNavigation
|
||||
userId={data.user.id}
|
||||
accounts={accounts}
|
||||
account={account}
|
||||
/>
|
||||
</div>
|
||||
</PageMobileNavigation>
|
||||
<div className={'group-data-[mobile:hidden]'}>
|
||||
<TeamAccountLayoutMobileNavigation
|
||||
userId={data.user.id}
|
||||
accounts={accounts}
|
||||
account={account}
|
||||
/>
|
||||
</div>
|
||||
</PageMobileNavigation>
|
||||
|
||||
<TeamAccountWorkspaceContextProvider value={data}>
|
||||
{children}
|
||||
</TeamAccountWorkspaceContextProvider>
|
||||
</Page>
|
||||
</Page>
|
||||
</TeamAccountWorkspaceContextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,9 +55,9 @@
|
||||
"@makerkit/data-loader-supabase-nextjs": "^1.2.3",
|
||||
"@marsidev/react-turnstile": "^1.1.0",
|
||||
"@radix-ui/react-icons": "^1.3.2",
|
||||
"@supabase/supabase-js": "2.47.5",
|
||||
"@supabase/supabase-js": "2.47.7",
|
||||
"@tanstack/react-query": "5.62.7",
|
||||
"@tanstack/react-table": "^8.20.5",
|
||||
"@tanstack/react-table": "^8.20.6",
|
||||
"date-fns": "^4.1.0",
|
||||
"lucide-react": "^0.468.0",
|
||||
"next": "15.1.0",
|
||||
|
||||
Reference in New Issue
Block a user