From fbbc2f87603a191d2254f99a17f4ea930627bcdd Mon Sep 17 00:00:00 2001 From: devmc-ee Date: Sun, 29 Jun 2025 19:25:50 +0300 Subject: [PATCH] B2B-31: refactor profile menu, header --- .../_components/home-menu-navigation.tsx | 39 +++++++------ .../team-account-navigation-menu.tsx | 35 +++++------ .../server/team-account-workspace.loader.ts | 9 +-- app/home/[account]/layout.tsx | 2 +- .../personal-account-dropdown-container.tsx | 8 ++- .../src/components/account-selector.tsx | 10 ++-- .../components/personal-account-dropdown.tsx | 58 ++++++++++++++++--- .../src/components/notifications-popover.tsx | 4 +- .../features/team-accounts/src/server/api.ts | 19 +++++- packages/ui/src/makerkit/page.tsx | 2 +- packages/ui/src/makerkit/profile-avatar.tsx | 2 +- public/locales/en/billing.json | 3 + public/locales/et/billing.json | 5 +- public/locales/ru/billing.json | 5 +- 14 files changed, 132 insertions(+), 69 deletions(-) diff --git a/app/home/(user)/_components/home-menu-navigation.tsx b/app/home/(user)/_components/home-menu-navigation.tsx index 7d78633..33e2408 100644 --- a/app/home/(user)/_components/home-menu-navigation.tsx +++ b/app/home/(user)/_components/home-menu-navigation.tsx @@ -1,38 +1,41 @@ -import { If } from '@kit/ui/if'; - import { AppLogo } from '~/components/app-logo'; import { ProfileAccountDropdownContainer } from '~/components/personal-account-dropdown-container'; -import featuresFlagConfig from '~/config/feature-flags.config'; +import { Trans } from '@kit/ui/trans'; // home imports -import { HomeAccountSelector } from '../_components/home-account-selector'; import { UserNotifications } from '../_components/user-notifications'; import { type UserWorkspace } from '../_lib/server/load-user-workspace'; +import { Button } from '@kit/ui/button'; +import { ShoppingCart } from 'lucide-react'; export function HomeMenuNavigation(props: { workspace: UserWorkspace }) { const { workspace, user, accounts } = props.workspace; - + console.log('HomeMenuNavigation', accounts) return (
+ {/* searbar */} +
+ {/* TODO: implement account budget */} + + {/* TODO: implement cart */} + - - - - - -
- -
+
); diff --git a/app/home/[account]/_components/team-account-navigation-menu.tsx b/app/home/[account]/_components/team-account-navigation-menu.tsx index 4eb9747..ba20d8d 100644 --- a/app/home/[account]/_components/team-account-navigation-menu.tsx +++ b/app/home/[account]/_components/team-account-navigation-menu.tsx @@ -6,16 +6,22 @@ import { import { AppLogo } from '~/components/app-logo'; import { ProfileAccountDropdownContainer } from '~/components/personal-account-dropdown-container'; import { getTeamAccountSidebarConfig } from '~/config/team-account-navigation.config'; -import { TeamAccountAccountsSelector } from '~/home/[account]/_components/team-account-accounts-selector'; // local imports import { TeamAccountWorkspace } from '../_lib/server/team-account-workspace.loader'; import { TeamAccountNotifications } from './team-account-notifications'; +import { useMemo } from 'react'; export function TeamAccountNavigationMenu(props: { workspace: TeamAccountWorkspace; }) { - const { account, user, accounts } = props.workspace; + const { account, user, accounts: rawAccounts } = props.workspace; + + const accounts = useMemo(() => rawAccounts.map((account) => ({ + label: account.name, + value: account.slug, + image: account.picture_url, + })),[rawAccounts]) const routes = getTeamAccountSidebarConfig(account.slug).routes.reduce< Array<{ @@ -40,7 +46,6 @@ export function TeamAccountNavigationMenu(props: {
- {routes.map((route) => ( @@ -48,26 +53,14 @@ export function TeamAccountNavigationMenu(props: {
-
+
- - ({ - label: account.name, - value: account.slug, - image: account.picture_url, - }))} + - -
- -
); diff --git a/app/home/[account]/_lib/server/team-account-workspace.loader.ts b/app/home/[account]/_lib/server/team-account-workspace.loader.ts index 4a38994..7ca21ed 100644 --- a/app/home/[account]/_lib/server/team-account-workspace.loader.ts +++ b/app/home/[account]/_lib/server/team-account-workspace.loader.ts @@ -28,12 +28,8 @@ export const loadTeamWorkspace = cache(workspaceLoader); async function workspaceLoader(accountSlug: string) { const client = getSupabaseServerClient(); const api = createTeamAccountsApi(client); - - const [workspace, user] = await Promise.all([ - api.getAccountWorkspace(accountSlug), - requireUserInServerComponent(), - ]); - + const user = await requireUserInServerComponent(); + const workspace = await api.getAccountWorkspace(accountSlug, user.id); // we cannot find any record for the selected account // so we redirect the user to the home page if (!workspace.data?.account) { @@ -42,6 +38,7 @@ async function workspaceLoader(accountSlug: string) { return { ...workspace.data, + accounts: workspace.data.accounts.map(({ user_accounts }) => ({...user_accounts})), user, }; } diff --git a/app/home/[account]/layout.tsx b/app/home/[account]/layout.tsx index f4ffec6..cbb77d1 100644 --- a/app/home/[account]/layout.tsx +++ b/app/home/[account]/layout.tsx @@ -30,7 +30,7 @@ function TeamWorkspaceLayout({ children, params }: TeamWorkspaceLayoutProps) { return {children}; } - return {children}; + return {children}; } function SidebarLayout({ diff --git a/components/personal-account-dropdown-container.tsx b/components/personal-account-dropdown-container.tsx index 50b28bc..bf4d2d2 100644 --- a/components/personal-account-dropdown-container.tsx +++ b/components/personal-account-dropdown-container.tsx @@ -26,6 +26,11 @@ export function ProfileAccountDropdownContainer(props: { name: string | null; picture_url: string | null; }; + accounts: { + label: string | null; + value: string | null; + image?: string | null; +}[] }) { const signOut = useSignOut(); const user = useUser(props.user); @@ -34,7 +39,7 @@ export function ProfileAccountDropdownContainer(props: { if (!userData) { return null; } - + console.log(props.accounts) return ( signOut.mutateAsync()} showProfileName={props.showProfileName} /> diff --git a/packages/features/accounts/src/components/account-selector.tsx b/packages/features/accounts/src/components/account-selector.tsx index 909a929..ab7965f 100644 --- a/packages/features/accounts/src/components/account-selector.tsx +++ b/packages/features/accounts/src/components/account-selector.tsx @@ -112,10 +112,10 @@ export function AccountSelector({ role="combobox" aria-expanded={open} className={cn( - 'dark:shadow-primary/10 group w-full min-w-0 px-2 lg:w-auto lg:max-w-fit', + 'dark:shadow-primary/10 group w-full min-w-0 px-4 py-2 h-10 border-1 lg:w-auto lg:max-w-fit', { 'justify-start': !collapsed, - 'm-auto justify-center px-2 lg:w-full': collapsed, + 'm-auto justify-center px-4 lg:w-full': collapsed, }, className, )} @@ -124,7 +124,7 @@ export function AccountSelector({ condition={selected} fallback={ - + + ); diff --git a/packages/features/accounts/src/components/personal-account-dropdown.tsx b/packages/features/accounts/src/components/personal-account-dropdown.tsx index c1a7128..39705ca 100644 --- a/packages/features/accounts/src/components/personal-account-dropdown.tsx +++ b/packages/features/accounts/src/components/personal-account-dropdown.tsx @@ -28,6 +28,9 @@ import { Trans } from '@kit/ui/trans'; import { cn } from '@kit/ui/utils'; import { usePersonalAccountData } from '../hooks/use-personal-account-data'; +import { Avatar, AvatarFallback, AvatarImage } from '@kit/ui/avatar'; + +const PERSONAL_ACCOUNT_SLUG = 'personal'; export function PersonalAccountDropdown({ className, @@ -37,6 +40,7 @@ export function PersonalAccountDropdown({ paths, features, account, + accounts }: { user: User; @@ -45,7 +49,11 @@ export function PersonalAccountDropdown({ name: string | null; picture_url: string | null; }; - + accounts: { + label: string | null; + value: string | null; + image?: string | null; + }[]; signOutRequested: () => unknown; paths: { @@ -95,7 +103,7 @@ export function PersonalAccountDropdown({ className ?? '', { ['active:bg-secondary/50 items-center gap-4 rounded-md' + - ' hover:bg-secondary p-2 transition-colors']: showProfileName, + ' hover:bg-secondary p-0 m-0 transition-colors border-1 rounded-md px-4 py-1 h-10']: showProfileName, }, )} > @@ -119,12 +127,6 @@ export function PersonalAccountDropdown({ {displayName} - - {signedInAsLabel} -
+ 0}> + + + + + {(accounts ?? []).map((account) => ( + + +
+ + + + + {account.label ? account.label[0] : ''} + + + + + {account.label} + +
+ +
+ ))} +
+ + + -