134 improvement add a button that allows closing the sidebar (#135)
* Enhance sidebar navigation and layout configuration - Added support for configurable sidebar collapsed style - Updated layout components to use new sidebar configuration - Added environment variable for sidebar trigger display - Simplified page header and navigation components - Improved sidebar responsiveness and user experience * Refactor admin account page layout and action buttons - Moved action buttons from sidebar to PageHeader for both personal and team account pages - Updated button variants and styling for better visual hierarchy - Improved spacing and layout of account page components - Added border to PageHeader for better visual separation * Update version updater dialog styling - Replaced `space-x-4` with `gap-x-2` for better spacing - Wrapped translation text in a `span` for improved layout - Maintained consistent icon and text alignment in dialog title * Refactor sidebar state management and configuration - Simplified sidebar context and removed minimized state - Updated layout components to use new sidebar open/closed state - Modified sidebar navigation to handle collapsed state dynamically - Added environment variable for sidebar trigger and collapsed style - Improved sidebar responsiveness and rendering logic * Remove sidebar configuration and environment variables - Simplified sidebar context by removing `minimized` state in components - Updated account selector components to use simplified sidebar state - Removed unused helper functions in sidebar implementation
This commit is contained in:
committed by
GitHub
parent
b319ceb5bb
commit
2a157e8baa
@@ -15,7 +15,6 @@ import {
|
|||||||
SidebarHeader,
|
SidebarHeader,
|
||||||
SidebarMenu,
|
SidebarMenu,
|
||||||
SidebarMenuButton,
|
SidebarMenuButton,
|
||||||
SidebarProvider,
|
|
||||||
} from '@kit/ui/shadcn-sidebar';
|
} from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
import { AppLogo } from '~/components/app-logo';
|
import { AppLogo } from '~/components/app-logo';
|
||||||
@@ -25,46 +24,44 @@ export function AdminSidebar() {
|
|||||||
const path = usePathname();
|
const path = usePathname();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarProvider>
|
<Sidebar collapsible="icon">
|
||||||
<Sidebar>
|
<SidebarHeader className={'m-2'}>
|
||||||
<SidebarHeader className={'m-2'}>
|
<AppLogo href={'/admin'} className="max-w-full" />
|
||||||
<AppLogo href={'/admin'} />
|
</SidebarHeader>
|
||||||
</SidebarHeader>
|
|
||||||
|
|
||||||
<SidebarContent>
|
<SidebarContent>
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
<SidebarGroupLabel>Admin</SidebarGroupLabel>
|
<SidebarGroupLabel>Admin</SidebarGroupLabel>
|
||||||
|
|
||||||
<SidebarGroupContent>
|
<SidebarGroupContent>
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
<SidebarMenuButton isActive={path === '/admin'} asChild>
|
<SidebarMenuButton isActive={path === '/admin'} asChild>
|
||||||
<Link className={'flex gap-2.5'} href={'/admin'}>
|
<Link className={'flex gap-2.5'} href={'/admin'}>
|
||||||
<LayoutDashboard className={'h-4'} />
|
<LayoutDashboard className={'h-4'} />
|
||||||
<span>Dashboard</span>
|
<span>Dashboard</span>
|
||||||
</Link>
|
</Link>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
|
|
||||||
<SidebarMenuButton
|
<SidebarMenuButton
|
||||||
isActive={path.includes('/admin/accounts')}
|
isActive={path.includes('/admin/accounts')}
|
||||||
asChild
|
asChild
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
className={'flex size-full gap-2.5'}
|
||||||
|
href={'/admin/accounts'}
|
||||||
>
|
>
|
||||||
<Link
|
<Users className={'h-4'} />
|
||||||
className={'flex size-full gap-2.5'}
|
<span>Accounts</span>
|
||||||
href={'/admin/accounts'}
|
</Link>
|
||||||
>
|
</SidebarMenuButton>
|
||||||
<Users className={'h-4'} />
|
</SidebarMenu>
|
||||||
<span>Accounts</span>
|
</SidebarGroupContent>
|
||||||
</Link>
|
</SidebarGroup>
|
||||||
</SidebarMenuButton>
|
</SidebarContent>
|
||||||
</SidebarMenu>
|
|
||||||
</SidebarGroupContent>
|
|
||||||
</SidebarGroup>
|
|
||||||
</SidebarContent>
|
|
||||||
|
|
||||||
<SidebarFooter>
|
<SidebarFooter>
|
||||||
<ProfileAccountDropdownContainer />
|
<ProfileAccountDropdownContainer />
|
||||||
</SidebarFooter>
|
</SidebarFooter>
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
</SidebarProvider>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { cache } from 'react';
|
|||||||
import { AdminAccountPage } from '@kit/admin/components/admin-account-page';
|
import { AdminAccountPage } from '@kit/admin/components/admin-account-page';
|
||||||
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
import { PageBody } from '@kit/ui/page';
|
|
||||||
|
|
||||||
interface Params {
|
interface Params {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
@@ -24,11 +23,7 @@ async function AccountPage(props: Params) {
|
|||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
const account = await loadAccount(params.id);
|
const account = await loadAccount(params.id);
|
||||||
|
|
||||||
return (
|
return <AdminAccountPage account={account} />;
|
||||||
<PageBody className={'py-4'}>
|
|
||||||
<AdminAccountPage account={account} />
|
|
||||||
</PageBody>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AdminGuard(AccountPage);
|
export default AdminGuard(AccountPage);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { ServerDataLoader } from '@makerkit/data-loader-supabase-nextjs';
|
|||||||
import { AdminAccountsTable } from '@kit/admin/components/admin-accounts-table';
|
import { AdminAccountsTable } from '@kit/admin/components/admin-accounts-table';
|
||||||
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
|
import { AppBreadcrumbs } from '@kit/ui/app-breadcrumbs';
|
||||||
import { PageBody, PageHeader } from '@kit/ui/page';
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
|
|
||||||
interface SearchParams {
|
interface SearchParams {
|
||||||
@@ -28,10 +29,7 @@ async function AccountsPage(props: AdminAccountsPageProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader
|
<PageHeader description={<AppBreadcrumbs />} />
|
||||||
title={'Accounts'}
|
|
||||||
description={`Below is the list of all the accounts in your application.`}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<ServerDataLoader
|
<ServerDataLoader
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
|
import { use } from 'react';
|
||||||
|
|
||||||
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
||||||
|
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
import { AdminSidebar } from '~/admin/_components/admin-sidebar';
|
import { AdminSidebar } from '~/admin/_components/admin-sidebar';
|
||||||
import { AdminMobileNavigation } from '~/admin/_components/mobile-navigation';
|
import { AdminMobileNavigation } from '~/admin/_components/mobile-navigation';
|
||||||
@@ -10,17 +15,30 @@ export const metadata = {
|
|||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
export default function AdminLayout(props: React.PropsWithChildren) {
|
export default function AdminLayout(props: React.PropsWithChildren) {
|
||||||
|
const state = use(getLayoutState());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page style={'sidebar'}>
|
<SidebarProvider defaultOpen={state.open}>
|
||||||
<PageNavigation>
|
<Page style={'sidebar'}>
|
||||||
<AdminSidebar />
|
<PageNavigation>
|
||||||
</PageNavigation>
|
<AdminSidebar />
|
||||||
|
</PageNavigation>
|
||||||
|
|
||||||
<PageMobileNavigation>
|
<PageMobileNavigation>
|
||||||
<AdminMobileNavigation />
|
<AdminMobileNavigation />
|
||||||
</PageMobileNavigation>
|
</PageMobileNavigation>
|
||||||
|
|
||||||
{props.children}
|
{props.children}
|
||||||
</Page>
|
</Page>
|
||||||
|
</SidebarProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getLayoutState() {
|
||||||
|
const cookieStore = await cookies();
|
||||||
|
const sidebarOpenCookie = cookieStore.get('sidebar:state');
|
||||||
|
|
||||||
|
return {
|
||||||
|
open: sidebarOpenCookie?.value !== 'true',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import { PageBody, PageHeader } from '@kit/ui/page';
|
|||||||
function AdminPage() {
|
function AdminPage() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader
|
<PageHeader description={`Super Admin`} />
|
||||||
title={'Super Admin'}
|
|
||||||
description={`Your SaaS stats at a glance`}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<AdminDashboard />
|
<AdminDashboard />
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export function HomeAccountSelector(props: {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<AccountSelector
|
<AccountSelector
|
||||||
collapsed={context?.minimized}
|
collapsed={!context?.open}
|
||||||
collisionPadding={props.collisionPadding ?? 20}
|
collisionPadding={props.collisionPadding ?? 20}
|
||||||
accounts={props.accounts}
|
accounts={props.accounts}
|
||||||
features={features}
|
features={features}
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ export function HomeLayoutPageHeader(
|
|||||||
}>,
|
}>,
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<PageHeader title={props.title} description={props.description}>
|
<PageHeader description={props.description}>{props.children}</PageHeader>
|
||||||
{props.children}
|
|
||||||
</PageHeader>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,24 +20,23 @@ import { HomeAccountSelector } from './home-account-selector';
|
|||||||
|
|
||||||
interface HomeSidebarProps {
|
interface HomeSidebarProps {
|
||||||
workspace: UserWorkspace;
|
workspace: UserWorkspace;
|
||||||
minimized: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function HomeSidebar(props: HomeSidebarProps) {
|
export function HomeSidebar(props: HomeSidebarProps) {
|
||||||
const { workspace, user, accounts } = props.workspace;
|
const { workspace, user, accounts } = props.workspace;
|
||||||
|
const collapsible = personalAccountNavigationConfig.sidebarCollapsedStyle;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar>
|
<Sidebar collapsible={collapsible}>
|
||||||
<SidebarHeader className={'h-16 justify-center'}>
|
<SidebarHeader className={'h-16 justify-center'}>
|
||||||
<div className={'flex items-center justify-between gap-x-3'}>
|
<div className={'flex items-center justify-between gap-x-3'}>
|
||||||
<If
|
<If
|
||||||
condition={featuresFlagConfig.enableTeamAccounts}
|
condition={featuresFlagConfig.enableTeamAccounts}
|
||||||
fallback={
|
fallback={
|
||||||
<AppLogo
|
<AppLogo
|
||||||
className={cn({
|
className={cn(
|
||||||
'max-w-full': props.minimized,
|
'py-2 group-data-[minimized=true]:max-w-full group-data-[minimized=true]:py-0',
|
||||||
'py-2': !props.minimized,
|
)}
|
||||||
})}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -3,12 +3,7 @@ import { use } from 'react';
|
|||||||
import { cookies } from 'next/headers';
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
|
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
|
||||||
import {
|
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
||||||
Page,
|
|
||||||
PageLayoutStyle,
|
|
||||||
PageMobileNavigation,
|
|
||||||
PageNavigation,
|
|
||||||
} from '@kit/ui/page';
|
|
||||||
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
import { AppLogo } from '~/components/app-logo';
|
import { AppLogo } from '~/components/app-logo';
|
||||||
@@ -22,9 +17,9 @@ import { HomeSidebar } from './_components/home-sidebar';
|
|||||||
import { loadUserWorkspace } from './_lib/server/load-user-workspace';
|
import { loadUserWorkspace } from './_lib/server/load-user-workspace';
|
||||||
|
|
||||||
function UserHomeLayout({ children }: React.PropsWithChildren) {
|
function UserHomeLayout({ children }: React.PropsWithChildren) {
|
||||||
const style = use(getLayoutStyle());
|
const state = use(getLayoutState());
|
||||||
|
|
||||||
if (style === 'sidebar') {
|
if (state.style === 'sidebar') {
|
||||||
return <SidebarLayout>{children}</SidebarLayout>;
|
return <SidebarLayout>{children}</SidebarLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,14 +30,16 @@ export default withI18n(UserHomeLayout);
|
|||||||
|
|
||||||
function SidebarLayout({ children }: React.PropsWithChildren) {
|
function SidebarLayout({ children }: React.PropsWithChildren) {
|
||||||
const workspace = use(loadUserWorkspace());
|
const workspace = use(loadUserWorkspace());
|
||||||
const sidebarMinimized = personalAccountNavigationConfig.sidebarCollapsed;
|
const state = use(getLayoutState());
|
||||||
|
|
||||||
|
console.log('state', state);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserWorkspaceContextProvider value={workspace}>
|
<UserWorkspaceContextProvider value={workspace}>
|
||||||
<SidebarProvider minimized={sidebarMinimized}>
|
<SidebarProvider defaultOpen={state.open}>
|
||||||
<Page style={'sidebar'}>
|
<Page style={'sidebar'}>
|
||||||
<PageNavigation>
|
<PageNavigation>
|
||||||
<HomeSidebar workspace={workspace} minimized={sidebarMinimized} />
|
<HomeSidebar workspace={workspace} />
|
||||||
</PageNavigation>
|
</PageNavigation>
|
||||||
|
|
||||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||||
@@ -90,11 +87,21 @@ function MobileNavigation({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLayoutStyle() {
|
async function getLayoutState() {
|
||||||
const cookieStore = await cookies();
|
const cookieStore = await cookies();
|
||||||
|
|
||||||
return (
|
const layoutStyleCookie = cookieStore.get('layout-style');
|
||||||
(cookieStore.get('layout-style')?.value as PageLayoutStyle) ??
|
const sidebarOpenCookie = cookieStore.get('sidebar:state');
|
||||||
personalAccountNavigationConfig.style
|
|
||||||
);
|
const sidebarOpenCookieValue = sidebarOpenCookie
|
||||||
|
? sidebarOpenCookie.value === 'false'
|
||||||
|
: personalAccountNavigationConfig.sidebarCollapsed;
|
||||||
|
|
||||||
|
const style =
|
||||||
|
layoutStyleCookie?.value ?? personalAccountNavigationConfig.style;
|
||||||
|
|
||||||
|
return {
|
||||||
|
open: sidebarOpenCookieValue,
|
||||||
|
style,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useContext } from 'react';
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { AccountSelector } from '@kit/accounts/account-selector';
|
import { AccountSelector } from '@kit/accounts/account-selector';
|
||||||
|
import { SidebarContext } from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
import featureFlagsConfig from '~/config/feature-flags.config';
|
import featureFlagsConfig from '~/config/feature-flags.config';
|
||||||
import pathsConfig from '~/config/paths.config';
|
import pathsConfig from '~/config/paths.config';
|
||||||
@@ -20,17 +23,16 @@ export function TeamAccountAccountsSelector(params: {
|
|||||||
value: string | null;
|
value: string | null;
|
||||||
image: string | null;
|
image: string | null;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
collapsed?: boolean;
|
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const ctx = useContext(SidebarContext);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AccountSelector
|
<AccountSelector
|
||||||
selectedAccount={params.selectedAccount}
|
selectedAccount={params.selectedAccount}
|
||||||
accounts={params.accounts}
|
accounts={params.accounts}
|
||||||
userId={params.userId}
|
userId={params.userId}
|
||||||
collapsed={params.collapsed}
|
collapsed={!ctx?.open}
|
||||||
features={features}
|
features={features}
|
||||||
onAccountChange={(value) => {
|
onAccountChange={(value) => {
|
||||||
const path = value
|
const path = value
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ export function TeamAccountLayoutPageHeader(
|
|||||||
}>,
|
}>,
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<PageHeader title={props.title} description={props.description}>
|
<PageHeader description={props.description}>{props.children}</PageHeader>
|
||||||
{props.children}
|
|
||||||
</PageHeader>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import { NavigationConfigSchema } from '@kit/ui/navigation-schema';
|
||||||
import { SidebarNavigation } from '@kit/ui/shadcn-sidebar';
|
import { SidebarNavigation } from '@kit/ui/shadcn-sidebar';
|
||||||
|
|
||||||
import { getTeamAccountSidebarConfig } from '~/config/team-account-navigation.config';
|
|
||||||
|
|
||||||
export function TeamAccountLayoutSidebarNavigation({
|
export function TeamAccountLayoutSidebarNavigation({
|
||||||
account,
|
config,
|
||||||
}: React.PropsWithChildren<{
|
}: React.PropsWithChildren<{
|
||||||
account: string;
|
config: z.infer<typeof NavigationConfigSchema>;
|
||||||
}>) {
|
}>) {
|
||||||
const routes = getTeamAccountSidebarConfig(account);
|
return <SidebarNavigation config={config} />;
|
||||||
|
|
||||||
return <SidebarNavigation config={routes} />;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import type { User } from '@supabase/supabase-js';
|
import type { User } from '@supabase/supabase-js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -7,11 +5,10 @@ import {
|
|||||||
SidebarContent,
|
SidebarContent,
|
||||||
SidebarFooter,
|
SidebarFooter,
|
||||||
SidebarHeader,
|
SidebarHeader,
|
||||||
useSidebar,
|
|
||||||
} from '@kit/ui/shadcn-sidebar';
|
} from '@kit/ui/shadcn-sidebar';
|
||||||
import { cn } from '@kit/ui/utils';
|
|
||||||
|
|
||||||
import { ProfileAccountDropdownContainer } from '~/components//personal-account-dropdown-container';
|
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 { TeamAccountNotifications } from '~/home/[account]/_components/team-account-notifications';
|
||||||
|
|
||||||
import { TeamAccountAccountsSelector } from '../_components/team-account-accounts-selector';
|
import { TeamAccountAccountsSelector } from '../_components/team-account-accounts-selector';
|
||||||
@@ -47,27 +44,21 @@ function SidebarContainer(props: {
|
|||||||
}) {
|
}) {
|
||||||
const { account, accounts, user } = props;
|
const { account, accounts, user } = props;
|
||||||
const userId = user.id;
|
const userId = user.id;
|
||||||
const { minimized } = useSidebar();
|
|
||||||
|
|
||||||
const className = cn(
|
const config = getTeamAccountSidebarConfig(account);
|
||||||
'flex max-w-full items-center justify-between space-x-4',
|
const collapsible = config.sidebarCollapsedStyle;
|
||||||
{
|
|
||||||
'w-full justify-start space-x-0': minimized,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar>
|
<Sidebar collapsible={collapsible}>
|
||||||
<SidebarHeader className={'h-16 justify-center'}>
|
<SidebarHeader className={'h-16 justify-center'}>
|
||||||
<div className={className}>
|
<div className={'flex items-center justify-between gap-x-3'}>
|
||||||
<TeamAccountAccountsSelector
|
<TeamAccountAccountsSelector
|
||||||
userId={userId}
|
userId={userId}
|
||||||
selectedAccount={account}
|
selectedAccount={account}
|
||||||
accounts={accounts}
|
accounts={accounts}
|
||||||
collapsed={minimized}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="group-data-[minimized=true]:hidden">
|
<div className={'group-data-[minimized=true]:hidden'}>
|
||||||
<TeamAccountNotifications
|
<TeamAccountNotifications
|
||||||
userId={userId}
|
userId={userId}
|
||||||
accountId={props.accountId}
|
accountId={props.accountId}
|
||||||
@@ -77,7 +68,7 @@ function SidebarContainer(props: {
|
|||||||
</SidebarHeader>
|
</SidebarHeader>
|
||||||
|
|
||||||
<SidebarContent className={`mt-5 h-[calc(100%-160px)] overflow-y-auto`}>
|
<SidebarContent className={`mt-5 h-[calc(100%-160px)] overflow-y-auto`}>
|
||||||
<TeamAccountLayoutSidebarNavigation account={account} />
|
<TeamAccountLayoutSidebarNavigation config={config} />
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
|
|
||||||
<SidebarFooter>
|
<SidebarFooter>
|
||||||
|
|||||||
@@ -20,10 +20,7 @@ export default function BillingErrorPage({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PageHeader
|
<PageHeader description={<AppBreadcrumbs />} />
|
||||||
title={<Trans i18nKey={'common:routes.billing'} />}
|
|
||||||
description={<AppBreadcrumbs />}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<div className={'flex flex-col space-y-4'}>
|
<div className={'flex flex-col space-y-4'}>
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ type TeamWorkspaceLayoutProps = React.PropsWithChildren<{
|
|||||||
|
|
||||||
function TeamWorkspaceLayout({ children, params }: TeamWorkspaceLayoutProps) {
|
function TeamWorkspaceLayout({ children, params }: TeamWorkspaceLayoutProps) {
|
||||||
const account = use(params).account;
|
const account = use(params).account;
|
||||||
const style = use(getLayoutStyle(account));
|
const state = use(getLayoutState(account));
|
||||||
|
|
||||||
if (style === 'sidebar') {
|
if (state.style === 'sidebar') {
|
||||||
return <SidebarLayout account={account}>{children}</SidebarLayout>;
|
return <SidebarLayout account={account}>{children}</SidebarLayout>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +43,7 @@ function SidebarLayout({
|
|||||||
account: string;
|
account: string;
|
||||||
}>) {
|
}>) {
|
||||||
const data = use(loadTeamWorkspace(account));
|
const data = use(loadTeamWorkspace(account));
|
||||||
|
const state = use(getLayoutState(account));
|
||||||
|
|
||||||
const accounts = data.accounts.map(({ name, slug, picture_url }) => ({
|
const accounts = data.accounts.map(({ name, slug, picture_url }) => ({
|
||||||
label: name,
|
label: name,
|
||||||
@@ -50,11 +51,9 @@ function SidebarLayout({
|
|||||||
image: picture_url,
|
image: picture_url,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const minimized = getTeamAccountSidebarConfig(account).sidebarCollapsed;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TeamAccountWorkspaceContextProvider value={data}>
|
<TeamAccountWorkspaceContextProvider value={data}>
|
||||||
<SidebarProvider minimized={minimized}>
|
<SidebarProvider defaultOpen={state.open}>
|
||||||
<Page style={'sidebar'}>
|
<Page style={'sidebar'}>
|
||||||
<PageNavigation>
|
<PageNavigation>
|
||||||
<TeamAccountLayoutSidebar
|
<TeamAccountLayoutSidebar
|
||||||
@@ -123,13 +122,21 @@ function HeaderLayout({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLayoutStyle(account: string) {
|
async function getLayoutState(account: string) {
|
||||||
const cookieStore = await cookies();
|
const cookieStore = await cookies();
|
||||||
|
const sidebarOpenCookie = cookieStore.get('sidebar:state');
|
||||||
|
const layoutCookie = cookieStore.get('layout-style');
|
||||||
|
const layoutStyle = layoutCookie?.value as PageLayoutStyle;
|
||||||
|
const config = getTeamAccountSidebarConfig(account);
|
||||||
|
|
||||||
return (
|
const sidebarOpenCookieValue = sidebarOpenCookie
|
||||||
(cookieStore.get('layout-style')?.value as PageLayoutStyle) ??
|
? sidebarOpenCookie.value === 'false'
|
||||||
getTeamAccountSidebarConfig(account).style
|
: config.sidebarCollapsed;
|
||||||
);
|
|
||||||
|
return {
|
||||||
|
open: sidebarOpenCookieValue,
|
||||||
|
style: layoutStyle ?? config.style,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withI18n(TeamWorkspaceLayout);
|
export default withI18n(TeamWorkspaceLayout);
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ export const personalAccountNavigationConfig = NavigationConfigSchema.parse({
|
|||||||
routes,
|
routes,
|
||||||
style: process.env.NEXT_PUBLIC_USER_NAVIGATION_STYLE,
|
style: process.env.NEXT_PUBLIC_USER_NAVIGATION_STYLE,
|
||||||
sidebarCollapsed: process.env.NEXT_PUBLIC_HOME_SIDEBAR_COLLAPSED,
|
sidebarCollapsed: process.env.NEXT_PUBLIC_HOME_SIDEBAR_COLLAPSED,
|
||||||
|
sidebarCollapsedStyle: process.env.NEXT_PUBLIC_SIDEBAR_COLLAPSED_STYLE,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export function getTeamAccountSidebarConfig(account: string) {
|
|||||||
routes: getRoutes(account),
|
routes: getRoutes(account),
|
||||||
style: process.env.NEXT_PUBLIC_TEAM_NAVIGATION_STYLE,
|
style: process.env.NEXT_PUBLIC_TEAM_NAVIGATION_STYLE,
|
||||||
sidebarCollapsed: process.env.NEXT_PUBLIC_TEAM_SIDEBAR_COLLAPSED,
|
sidebarCollapsed: process.env.NEXT_PUBLIC_TEAM_SIDEBAR_COLLAPSED,
|
||||||
|
sidebarCollapsedStyle: process.env.NEXT_PUBLIC_SIDEBAR_COLLAPSED_STYLE,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { Badge } from '@kit/ui/badge';
|
|||||||
import { Button } from '@kit/ui/button';
|
import { Button } from '@kit/ui/button';
|
||||||
import { Heading } from '@kit/ui/heading';
|
import { Heading } from '@kit/ui/heading';
|
||||||
import { If } from '@kit/ui/if';
|
import { If } from '@kit/ui/if';
|
||||||
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
||||||
import { ProfileAvatar } from '@kit/ui/profile-avatar';
|
import { ProfileAvatar } from '@kit/ui/profile-avatar';
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
@@ -61,38 +62,22 @@ async function PersonalAccountPage(props: { account: Account }) {
|
|||||||
'banned_until' in data.user && data.user.banned_until !== 'none';
|
'banned_until' in data.user && data.user.banned_until !== 'none';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'flex flex-col space-y-4'}>
|
<>
|
||||||
<AppBreadcrumbs
|
<PageHeader
|
||||||
values={{
|
className="border-b"
|
||||||
[props.account.id]:
|
description={
|
||||||
props.account.name ?? props.account.email ?? 'Account',
|
<AppBreadcrumbs
|
||||||
}}
|
values={{
|
||||||
/>
|
[props.account.id]:
|
||||||
|
props.account.name ?? props.account.email ?? 'Account',
|
||||||
<div className={'flex items-center justify-between'}>
|
}}
|
||||||
<div className={'flex items-center gap-x-4'}>
|
/>
|
||||||
<div className={'flex items-center gap-x-2.5'}>
|
}
|
||||||
<ProfileAvatar
|
>
|
||||||
pictureUrl={props.account.picture_url}
|
<div className={'flex gap-x-2.5'}>
|
||||||
displayName={props.account.name}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<span className={'text-sm font-semibold capitalize'}>
|
|
||||||
{props.account.name}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Badge variant={'outline'}>Personal Account</Badge>
|
|
||||||
|
|
||||||
<If condition={isBanned}>
|
|
||||||
<Badge variant={'destructive'}>Banned</Badge>
|
|
||||||
</If>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className={'flex gap-x-1'}>
|
|
||||||
<If condition={isBanned}>
|
<If condition={isBanned}>
|
||||||
<AdminReactivateUserDialog userId={props.account.id}>
|
<AdminReactivateUserDialog userId={props.account.id}>
|
||||||
<Button size={'sm'} variant={'ghost'}>
|
<Button size={'sm'} variant={'secondary'}>
|
||||||
<ShieldPlus className={'mr-1 h-4'} />
|
<ShieldPlus className={'mr-1 h-4'} />
|
||||||
Reactivate
|
Reactivate
|
||||||
</Button>
|
</Button>
|
||||||
@@ -101,15 +86,15 @@ async function PersonalAccountPage(props: { account: Account }) {
|
|||||||
|
|
||||||
<If condition={!isBanned}>
|
<If condition={!isBanned}>
|
||||||
<AdminBanUserDialog userId={props.account.id}>
|
<AdminBanUserDialog userId={props.account.id}>
|
||||||
<Button size={'sm'} variant={'ghost'}>
|
<Button size={'sm'} variant={'secondary'}>
|
||||||
<Ban className={'mr-1 h-4'} />
|
<Ban className={'text-destructive mr-1 h-3'} />
|
||||||
Ban
|
Ban
|
||||||
</Button>
|
</Button>
|
||||||
</AdminBanUserDialog>
|
</AdminBanUserDialog>
|
||||||
|
|
||||||
<AdminImpersonateUserDialog userId={props.account.id}>
|
<AdminImpersonateUserDialog userId={props.account.id}>
|
||||||
<Button size={'sm'} variant={'ghost'}>
|
<Button size={'sm'} variant={'secondary'}>
|
||||||
<VenetianMask className={'mr-1 h-4'} />
|
<VenetianMask className={'mr-1 h-4 text-blue-500'} />
|
||||||
Impersonate
|
Impersonate
|
||||||
</Button>
|
</Button>
|
||||||
</AdminImpersonateUserDialog>
|
</AdminImpersonateUserDialog>
|
||||||
@@ -122,20 +107,43 @@ async function PersonalAccountPage(props: { account: Account }) {
|
|||||||
</Button>
|
</Button>
|
||||||
</AdminDeleteUserDialog>
|
</AdminDeleteUserDialog>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</PageHeader>
|
||||||
|
|
||||||
<div className={'flex flex-col gap-y-8'}>
|
<PageBody className={'space-y-6 py-4'}>
|
||||||
<SubscriptionsTable accountId={props.account.id} />
|
<div className={'flex items-center justify-between'}>
|
||||||
|
<div className={'flex items-center gap-x-4'}>
|
||||||
|
<div className={'flex items-center gap-x-2.5'}>
|
||||||
|
<ProfileAvatar
|
||||||
|
pictureUrl={props.account.picture_url}
|
||||||
|
displayName={props.account.name}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className={'divider-divider-x flex flex-col gap-y-2.5'}>
|
<span className={'text-sm font-semibold capitalize'}>
|
||||||
<Heading level={6}>Teams</Heading>
|
{props.account.name}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<Badge variant={'outline'}>Personal Account</Badge>
|
||||||
<AdminMembershipsTable memberships={memberships} />
|
|
||||||
|
<If condition={isBanned}>
|
||||||
|
<Badge variant={'destructive'}>Banned</Badge>
|
||||||
|
</If>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
<div className={'flex flex-col gap-y-8'}>
|
||||||
|
<SubscriptionsTable accountId={props.account.id} />
|
||||||
|
|
||||||
|
<div className={'divider-divider-x flex flex-col gap-y-2.5'}>
|
||||||
|
<Heading level={6}>Teams</Heading>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<AdminMembershipsTable memberships={memberships} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</PageBody>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,50 +153,57 @@ async function TeamAccountPage(props: {
|
|||||||
const members = await getMembers(props.account.slug ?? '');
|
const members = await getMembers(props.account.slug ?? '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'flex flex-col gap-y-4'}>
|
<>
|
||||||
<AppBreadcrumbs
|
<PageHeader
|
||||||
values={{
|
className="border-b"
|
||||||
[props.account.id]:
|
description={
|
||||||
props.account.name ?? props.account.email ?? 'Account',
|
<AppBreadcrumbs
|
||||||
}}
|
values={{
|
||||||
/>
|
[props.account.id]:
|
||||||
|
props.account.name ?? props.account.email ?? 'Account',
|
||||||
<div className={'flex justify-between'}>
|
}}
|
||||||
<div className={'flex items-center gap-x-4'}>
|
/>
|
||||||
<div className={'flex items-center gap-x-2.5'}>
|
}
|
||||||
<ProfileAvatar
|
>
|
||||||
pictureUrl={props.account.picture_url}
|
|
||||||
displayName={props.account.name}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<span className={'text-sm font-semibold capitalize'}>
|
|
||||||
{props.account.name}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Badge variant={'outline'}>Team Account</Badge>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<AdminDeleteAccountDialog accountId={props.account.id}>
|
<AdminDeleteAccountDialog accountId={props.account.id}>
|
||||||
<Button size={'sm'} variant={'destructive'}>
|
<Button size={'sm'} variant={'destructive'}>
|
||||||
<BadgeX className={'mr-1 h-4'} />
|
<BadgeX className={'mr-1 h-4'} />
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</AdminDeleteAccountDialog>
|
</AdminDeleteAccountDialog>
|
||||||
</div>
|
</PageHeader>
|
||||||
|
|
||||||
<div>
|
<PageBody className={'space-y-6 py-4'}>
|
||||||
<div className={'flex flex-col gap-y-8'}>
|
<div className={'flex justify-between'}>
|
||||||
<SubscriptionsTable accountId={props.account.id} />
|
<div className={'flex items-center gap-x-4'}>
|
||||||
|
<div className={'flex items-center gap-x-2.5'}>
|
||||||
|
<ProfileAvatar
|
||||||
|
pictureUrl={props.account.picture_url}
|
||||||
|
displayName={props.account.name}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className={'flex flex-col gap-y-2.5'}>
|
<span className={'text-sm font-semibold capitalize'}>
|
||||||
<Heading level={6}>Team Members</Heading>
|
{props.account.name}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<AdminMembersTable members={members} />
|
<Badge variant={'outline'}>Team Account</Badge>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
<div>
|
||||||
|
<div className={'flex flex-col gap-y-8'}>
|
||||||
|
<SubscriptionsTable accountId={props.account.id} />
|
||||||
|
|
||||||
|
<div className={'flex flex-col gap-y-2.5'}>
|
||||||
|
<Heading level={6}>Team Members</Heading>
|
||||||
|
|
||||||
|
<AdminMembersTable members={members} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</PageBody>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ export const NavigationConfigSchema = z.object({
|
|||||||
style: z.enum(['custom', 'sidebar', 'header']).default('sidebar'),
|
style: z.enum(['custom', 'sidebar', 'header']).default('sidebar'),
|
||||||
sidebarCollapsed: z
|
sidebarCollapsed: z
|
||||||
.enum(['false', 'true'])
|
.enum(['false', 'true'])
|
||||||
.default('false')
|
.default('true')
|
||||||
.optional()
|
.optional()
|
||||||
.transform((value) => value === `true`),
|
.transform((value) => value === `true`),
|
||||||
|
sidebarCollapsedStyle: z.enum(['offcanvas', 'icon', 'none']).default('icon'),
|
||||||
routes: z.array(z.union([RouteGroup, Divider])),
|
routes: z.array(z.union([RouteGroup, Divider])),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { cn } from '../lib/utils';
|
import { cn } from '../lib/utils';
|
||||||
|
import { Separator } from '../shadcn/separator';
|
||||||
|
import { SidebarTrigger } from '../shadcn/sidebar';
|
||||||
import { If } from './if';
|
import { If } from './if';
|
||||||
|
|
||||||
export type PageLayoutStyle = 'sidebar' | 'header' | 'custom';
|
export type PageLayoutStyle = 'sidebar' | 'header' | 'custom';
|
||||||
@@ -12,6 +14,10 @@ type PageProps = React.PropsWithChildren<{
|
|||||||
sticky?: boolean;
|
sticky?: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
const ENABLE_SIDEBAR_TRIGGER = process.env.NEXT_PUBLIC_ENABLE_SIDEBAR_TRIGGER
|
||||||
|
? process.env.NEXT_PUBLIC_ENABLE_SIDEBAR_TRIGGER === 'true'
|
||||||
|
: true;
|
||||||
|
|
||||||
export function Page(props: PageProps) {
|
export function Page(props: PageProps) {
|
||||||
switch (props.style) {
|
switch (props.style) {
|
||||||
case 'header':
|
case 'header':
|
||||||
@@ -118,7 +124,7 @@ export function PageNavigation(props: React.PropsWithChildren) {
|
|||||||
|
|
||||||
export function PageDescription(props: React.PropsWithChildren) {
|
export function PageDescription(props: React.PropsWithChildren) {
|
||||||
return (
|
return (
|
||||||
<div className={'h-6'}>
|
<div className={'flex h-6 items-center'}>
|
||||||
<div className={'text-muted-foreground text-xs leading-none font-normal'}>
|
<div className={'text-muted-foreground text-xs leading-none font-normal'}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
@@ -130,7 +136,7 @@ export function PageTitle(props: React.PropsWithChildren) {
|
|||||||
return (
|
return (
|
||||||
<h1
|
<h1
|
||||||
className={
|
className={
|
||||||
'font-heading text-xl leading-none font-bold tracking-tight dark:text-white'
|
'font-heading text-base leading-none font-bold tracking-tight dark:text-white'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
@@ -147,10 +153,12 @@ export function PageHeader({
|
|||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
className,
|
className,
|
||||||
|
displaySidebarTrigger = ENABLE_SIDEBAR_TRIGGER,
|
||||||
}: React.PropsWithChildren<{
|
}: React.PropsWithChildren<{
|
||||||
className?: string;
|
className?: string;
|
||||||
title?: string | React.ReactNode;
|
title?: string | React.ReactNode;
|
||||||
description?: string | React.ReactNode;
|
description?: string | React.ReactNode;
|
||||||
|
displaySidebarTrigger?: boolean;
|
||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -159,10 +167,20 @@ export function PageHeader({
|
|||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className={'flex flex-col'}>
|
<div className={'flex flex-col gap-y-2'}>
|
||||||
<If condition={description}>
|
<div className="flex items-center gap-x-2.5">
|
||||||
<PageDescription>{description}</PageDescription>
|
{displaySidebarTrigger ? (
|
||||||
</If>
|
<SidebarTrigger className="text-muted-foreground hover:text-secondary-foreground h-4.5 w-4.5 cursor-pointer" />
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<If condition={description}>
|
||||||
|
<If condition={displaySidebarTrigger}>
|
||||||
|
<Separator orientation="vertical" className="h-4 w-px" />
|
||||||
|
</If>
|
||||||
|
|
||||||
|
<PageDescription>{description}</PageDescription>
|
||||||
|
</If>
|
||||||
|
</div>
|
||||||
|
|
||||||
<If condition={title}>
|
<If condition={title}>
|
||||||
<PageTitle>{title}</PageTitle>
|
<PageTitle>{title}</PageTitle>
|
||||||
|
|||||||
@@ -50,9 +50,11 @@ export function VersionUpdater(props: { intervalTimeInSecond?: number }) {
|
|||||||
<AlertDialog open={showDialog} onOpenChange={setShowDialog}>
|
<AlertDialog open={showDialog} onOpenChange={setShowDialog}>
|
||||||
<AlertDialogContent>
|
<AlertDialogContent>
|
||||||
<AlertDialogHeader>
|
<AlertDialogHeader>
|
||||||
<AlertDialogTitle className={'flex items-center space-x-4'}>
|
<AlertDialogTitle className={'flex items-center gap-x-2'}>
|
||||||
<RocketIcon className={'h-4'} />
|
<RocketIcon className={'h-4'} />
|
||||||
<Trans i18nKey="common:newVersionAvailable" />
|
<span>
|
||||||
|
<Trans i18nKey="common:newVersionAvailable" />
|
||||||
|
</span>
|
||||||
</AlertDialogTitle>
|
</AlertDialogTitle>
|
||||||
|
|
||||||
<AlertDialogDescription>
|
<AlertDialogDescription>
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ const SIDEBAR_COOKIE_NAME = 'sidebar:state';
|
|||||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
||||||
const SIDEBAR_WIDTH = '16rem';
|
const SIDEBAR_WIDTH = '16rem';
|
||||||
const SIDEBAR_WIDTH_MOBILE = '18rem';
|
const SIDEBAR_WIDTH_MOBILE = '18rem';
|
||||||
const SIDEBAR_WIDTH_ICON = '3rem';
|
const SIDEBAR_WIDTH_ICON = '4rem';
|
||||||
const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
|
const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
|
||||||
const SIDEBAR_MINIMIZED_WIDTH = '4rem';
|
const SIDEBAR_MINIMIZED_WIDTH = SIDEBAR_WIDTH_ICON;
|
||||||
|
|
||||||
type SidebarContext = {
|
type SidebarContext = {
|
||||||
state: 'expanded' | 'collapsed';
|
state: 'expanded' | 'collapsed';
|
||||||
@@ -46,12 +46,8 @@ type SidebarContext = {
|
|||||||
setOpen: (open: boolean) => void;
|
setOpen: (open: boolean) => void;
|
||||||
openMobile: boolean;
|
openMobile: boolean;
|
||||||
setOpenMobile: (open: boolean) => void;
|
setOpenMobile: (open: boolean) => void;
|
||||||
setMinimized: (minimized: boolean) => void;
|
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
toggleSidebar: () => void;
|
toggleSidebar: () => void;
|
||||||
minimized: boolean;
|
|
||||||
startMinimized: boolean;
|
|
||||||
expandOnHover: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SidebarContext = React.createContext<SidebarContext | null>(null);
|
export const SidebarContext = React.createContext<SidebarContext | null>(null);
|
||||||
@@ -71,13 +67,10 @@ const SidebarProvider: React.FC<
|
|||||||
defaultOpen?: boolean;
|
defaultOpen?: boolean;
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
onOpenChange?: (open: boolean) => void;
|
onOpenChange?: (open: boolean) => void;
|
||||||
minimized?: boolean;
|
|
||||||
expandOnHover?: boolean;
|
|
||||||
}
|
}
|
||||||
> = ({
|
> = ({
|
||||||
ref,
|
ref,
|
||||||
defaultOpen = true,
|
defaultOpen = true,
|
||||||
minimized: isMinimized = false,
|
|
||||||
open: openProp,
|
open: openProp,
|
||||||
onOpenChange: setOpenProp,
|
onOpenChange: setOpenProp,
|
||||||
className,
|
className,
|
||||||
@@ -87,11 +80,7 @@ const SidebarProvider: React.FC<
|
|||||||
}) => {
|
}) => {
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
const [openMobile, setOpenMobile] = React.useState(false);
|
const [openMobile, setOpenMobile] = React.useState(false);
|
||||||
const [minimized, setMinimized] = React.useState(isMinimized);
|
const collapsibleStyle = process.env.NEXT_PUBLIC_SIDEBAR_COLLAPSIBLE_STYLE;
|
||||||
|
|
||||||
const expandOnHover =
|
|
||||||
props.expandOnHover ??
|
|
||||||
process.env.NEXT_PUBLIC_EXPAND_SIDEBAR_ON_HOVER === 'true';
|
|
||||||
|
|
||||||
// This is the internal state of the sidebar.
|
// This is the internal state of the sidebar.
|
||||||
// We use openProp and setOpenProp for control from outside the component.
|
// We use openProp and setOpenProp for control from outside the component.
|
||||||
@@ -136,7 +125,6 @@ const SidebarProvider: React.FC<
|
|||||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||||
// This makes it easier to style the sidebar with Tailwind classes.
|
// This makes it easier to style the sidebar with Tailwind classes.
|
||||||
const state = open ? 'expanded' : 'collapsed';
|
const state = open ? 'expanded' : 'collapsed';
|
||||||
const startMinimized = isMinimized;
|
|
||||||
|
|
||||||
const contextValue = React.useMemo<SidebarContext>(
|
const contextValue = React.useMemo<SidebarContext>(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -144,43 +132,33 @@ const SidebarProvider: React.FC<
|
|||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
isMobile,
|
isMobile,
|
||||||
minimized,
|
|
||||||
setMinimized,
|
|
||||||
expandOnHover,
|
|
||||||
openMobile,
|
openMobile,
|
||||||
setOpenMobile,
|
setOpenMobile,
|
||||||
toggleSidebar,
|
toggleSidebar,
|
||||||
startMinimized,
|
|
||||||
}),
|
}),
|
||||||
[
|
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar],
|
||||||
state,
|
|
||||||
open,
|
|
||||||
setOpen,
|
|
||||||
isMobile,
|
|
||||||
openMobile,
|
|
||||||
setOpenMobile,
|
|
||||||
toggleSidebar,
|
|
||||||
expandOnHover,
|
|
||||||
minimized,
|
|
||||||
setMinimized,
|
|
||||||
startMinimized,
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const sidebarWidth = !open
|
||||||
|
? collapsibleStyle === 'icon'
|
||||||
|
? SIDEBAR_WIDTH_ICON
|
||||||
|
: collapsibleStyle === 'offcanvas'
|
||||||
|
? 0
|
||||||
|
: SIDEBAR_MINIMIZED_WIDTH
|
||||||
|
: SIDEBAR_WIDTH;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarContext.Provider value={contextValue}>
|
<SidebarContext.Provider value={contextValue}>
|
||||||
<TooltipProvider delayDuration={0}>
|
<TooltipProvider delayDuration={0}>
|
||||||
<div
|
<div
|
||||||
style={
|
style={
|
||||||
{
|
{
|
||||||
'--sidebar-width': minimized
|
'--sidebar-width': sidebarWidth,
|
||||||
? SIDEBAR_MINIMIZED_WIDTH
|
|
||||||
: SIDEBAR_WIDTH,
|
|
||||||
'--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
|
'--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
|
||||||
...style,
|
...style,
|
||||||
} as React.CSSProperties
|
} as React.CSSProperties
|
||||||
}
|
}
|
||||||
data-minimized={minimized}
|
data-minimized={!open}
|
||||||
className={cn(
|
className={cn(
|
||||||
'group text-sidebar-foreground has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full',
|
'group text-sidebar-foreground has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full',
|
||||||
className,
|
className,
|
||||||
@@ -212,42 +190,7 @@ const Sidebar: React.FC<
|
|||||||
ref,
|
ref,
|
||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
||||||
isMobile,
|
|
||||||
state,
|
|
||||||
openMobile,
|
|
||||||
setOpenMobile,
|
|
||||||
minimized,
|
|
||||||
setMinimized,
|
|
||||||
expandOnHover,
|
|
||||||
startMinimized,
|
|
||||||
} = useSidebar();
|
|
||||||
useSidebar();
|
|
||||||
|
|
||||||
const isExpandedRef = React.useRef<boolean>(false);
|
|
||||||
|
|
||||||
const onMouseEnter =
|
|
||||||
startMinimized && expandOnHover
|
|
||||||
? () => {
|
|
||||||
setMinimized(false);
|
|
||||||
isExpandedRef.current = true;
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const onMouseLeave =
|
|
||||||
startMinimized && expandOnHover
|
|
||||||
? () => {
|
|
||||||
if (!isRadixPopupOpen()) {
|
|
||||||
setMinimized(true);
|
|
||||||
isExpandedRef.current = false;
|
|
||||||
} else {
|
|
||||||
onRadixPopupClose(() => {
|
|
||||||
setMinimized(true);
|
|
||||||
isExpandedRef.current = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (collapsible === 'none') {
|
if (collapsible === 'none') {
|
||||||
return (
|
return (
|
||||||
@@ -256,7 +199,7 @@ const Sidebar: React.FC<
|
|||||||
'bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col',
|
'bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col',
|
||||||
className,
|
className,
|
||||||
{
|
{
|
||||||
[SIDEBAR_MINIMIZED_WIDTH]: minimized,
|
[SIDEBAR_MINIMIZED_WIDTH]: !open,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
@@ -301,8 +244,6 @@ const Sidebar: React.FC<
|
|||||||
data-collapsible={state === 'collapsed' ? collapsible : ''}
|
data-collapsible={state === 'collapsed' ? collapsible : ''}
|
||||||
data-variant={variant}
|
data-variant={variant}
|
||||||
data-side={side}
|
data-side={side}
|
||||||
onMouseEnter={onMouseEnter}
|
|
||||||
onMouseLeave={onMouseLeave}
|
|
||||||
>
|
>
|
||||||
{/* This is what handles the sidebar gap on desktop */}
|
{/* This is what handles the sidebar gap on desktop */}
|
||||||
<div
|
<div
|
||||||
@@ -569,7 +510,10 @@ const SidebarMenu: React.FC<React.ComponentProps<'ul'>> = ({
|
|||||||
}) => (
|
}) => (
|
||||||
<ul
|
<ul
|
||||||
data-sidebar="menu"
|
data-sidebar="menu"
|
||||||
className={cn('flex w-full min-w-0 flex-col gap-1', className)}
|
className={cn(
|
||||||
|
'flex w-full min-w-0 flex-col gap-1 group-data-[minimized=true]:items-center',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -581,7 +525,10 @@ const SidebarMenuItem: React.FC<React.ComponentProps<'li'>> = ({
|
|||||||
}) => (
|
}) => (
|
||||||
<li
|
<li
|
||||||
data-sidebar="menu-item"
|
data-sidebar="menu-item"
|
||||||
className={cn('group/menu-item relative', className)}
|
className={cn(
|
||||||
|
'group/menu-item relative flex group-data-[collapsible=icon]:justify-center',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -625,7 +572,7 @@ const SidebarMenuButton: React.FC<
|
|||||||
...props
|
...props
|
||||||
}) => {
|
}) => {
|
||||||
const Comp = asChild ? Slot : 'button';
|
const Comp = asChild ? Slot : 'button';
|
||||||
const { isMobile, minimized } = useSidebar();
|
const { isMobile, open } = useSidebar();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const button = (
|
const button = (
|
||||||
@@ -656,7 +603,7 @@ const SidebarMenuButton: React.FC<
|
|||||||
<TooltipContent
|
<TooltipContent
|
||||||
side="right"
|
side="right"
|
||||||
align="center"
|
align="center"
|
||||||
hidden={isMobile || !minimized}
|
hidden={isMobile || open}
|
||||||
{...tooltip}
|
{...tooltip}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
@@ -806,7 +753,7 @@ export function SidebarNavigation({
|
|||||||
config: SidebarConfig;
|
config: SidebarConfig;
|
||||||
}>) {
|
}>) {
|
||||||
const currentPath = usePathname() ?? '';
|
const currentPath = usePathname() ?? '';
|
||||||
const { minimized } = useSidebar();
|
const { open } = useSidebar();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -847,15 +794,12 @@ export function SidebarNavigation({
|
|||||||
<If
|
<If
|
||||||
condition={item.collapsible}
|
condition={item.collapsible}
|
||||||
fallback={
|
fallback={
|
||||||
<SidebarGroupLabel className={cn({ hidden: minimized })}>
|
<SidebarGroupLabel className={cn({ hidden: !open })}>
|
||||||
<Trans i18nKey={item.label} defaults={item.label} />
|
<Trans i18nKey={item.label} defaults={item.label} />
|
||||||
</SidebarGroupLabel>
|
</SidebarGroupLabel>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SidebarGroupLabel
|
<SidebarGroupLabel className={cn({ hidden: !open })} asChild>
|
||||||
className={cn({ hidden: minimized })}
|
|
||||||
asChild
|
|
||||||
>
|
|
||||||
<CollapsibleTrigger>
|
<CollapsibleTrigger>
|
||||||
<Trans i18nKey={item.label} defaults={item.label} />
|
<Trans i18nKey={item.label} defaults={item.label} />
|
||||||
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
|
<ChevronDown className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-180" />
|
||||||
@@ -910,15 +854,15 @@ export function SidebarNavigation({
|
|||||||
<div
|
<div
|
||||||
className={cn('flex items-center gap-2', {
|
className={cn('flex items-center gap-2', {
|
||||||
'mx-auto w-full gap-0 [&>svg]:flex-1 [&>svg]:shrink-0':
|
'mx-auto w-full gap-0 [&>svg]:flex-1 [&>svg]:shrink-0':
|
||||||
minimized,
|
!open,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{child.Icon}
|
{child.Icon}
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-auto transition-opacity duration-300',
|
'transition-width w-auto transition-opacity duration-500',
|
||||||
{
|
{
|
||||||
'w-0 opacity-0': minimized,
|
'w-0 opacity-0': !open,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -927,11 +871,12 @@ export function SidebarNavigation({
|
|||||||
defaults={child.label}
|
defaults={child.label}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<ChevronDown
|
<ChevronDown
|
||||||
className={cn(
|
className={cn(
|
||||||
'ml-auto size-4 transition-transform group-data-[state=open]/collapsible:rotate-180',
|
'ml-auto size-4 transition-transform group-data-[state=open]/collapsible:rotate-180',
|
||||||
{
|
{
|
||||||
'hidden size-0': minimized,
|
'hidden size-0': !open,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@@ -958,8 +903,7 @@ export function SidebarNavigation({
|
|||||||
>
|
>
|
||||||
<Link
|
<Link
|
||||||
className={cn('flex items-center', {
|
className={cn('flex items-center', {
|
||||||
'mx-auto w-full gap-0! [&>svg]:flex-1':
|
'mx-auto w-full gap-0! [&>svg]:flex-1': !open,
|
||||||
minimized,
|
|
||||||
})}
|
})}
|
||||||
href={path}
|
href={path}
|
||||||
>
|
>
|
||||||
@@ -968,7 +912,7 @@ export function SidebarNavigation({
|
|||||||
className={cn(
|
className={cn(
|
||||||
'w-auto transition-opacity duration-300',
|
'w-auto transition-opacity duration-300',
|
||||||
{
|
{
|
||||||
'w-0 opacity-0': minimized,
|
'w-0 opacity-0': !open,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -992,7 +936,7 @@ export function SidebarNavigation({
|
|||||||
{(children) => (
|
{(children) => (
|
||||||
<SidebarMenuSub
|
<SidebarMenuSub
|
||||||
className={cn({
|
className={cn({
|
||||||
'mx-0 px-1.5': minimized,
|
'mx-0 px-1.5': !open,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{children.map((child) => {
|
{children.map((child) => {
|
||||||
@@ -1023,7 +967,7 @@ export function SidebarNavigation({
|
|||||||
'flex items-center',
|
'flex items-center',
|
||||||
{
|
{
|
||||||
'mx-auto w-full gap-0! [&>svg]:flex-1':
|
'mx-auto w-full gap-0! [&>svg]:flex-1':
|
||||||
minimized,
|
!open,
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
href={child.path}
|
href={child.path}
|
||||||
@@ -1033,8 +977,7 @@ export function SidebarNavigation({
|
|||||||
className={cn(
|
className={cn(
|
||||||
'w-auto transition-opacity duration-300',
|
'w-auto transition-opacity duration-300',
|
||||||
{
|
{
|
||||||
'w-0 opacity-0':
|
'w-0 opacity-0': !open,
|
||||||
minimized,
|
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -1065,7 +1008,7 @@ export function SidebarNavigation({
|
|||||||
</SidebarGroupContent>
|
</SidebarGroupContent>
|
||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
|
|
||||||
<If condition={minimized && !isLast}>
|
<If condition={!open && !isLast}>
|
||||||
<SidebarSeparator />
|
<SidebarSeparator />
|
||||||
</If>
|
</If>
|
||||||
</Container>
|
</Container>
|
||||||
@@ -1102,30 +1045,3 @@ export {
|
|||||||
SidebarTrigger,
|
SidebarTrigger,
|
||||||
useSidebar,
|
useSidebar,
|
||||||
};
|
};
|
||||||
|
|
||||||
function getRadixPopup() {
|
|
||||||
return document.querySelector('[data-radix-popper-content-wrapper]');
|
|
||||||
}
|
|
||||||
|
|
||||||
function isRadixPopupOpen() {
|
|
||||||
return getRadixPopup() !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onRadixPopupClose(callback: () => void) {
|
|
||||||
const element = getRadixPopup();
|
|
||||||
|
|
||||||
if (element) {
|
|
||||||
const observer = new MutationObserver(() => {
|
|
||||||
if (!getRadixPopup()) {
|
|
||||||
callback();
|
|
||||||
|
|
||||||
observer.disconnect();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
observer.observe(element.parentElement!, {
|
|
||||||
childList: true,
|
|
||||||
subtree: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user