feat(MED-100): show cart in mobile menu
This commit is contained in:
@@ -7,6 +7,8 @@ import { z } from 'zod';
|
|||||||
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
|
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
|
||||||
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
||||||
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
|
||||||
|
import { StoreCart } from '@medusajs/types';
|
||||||
|
import { retrieveCart } from '@lib/data';
|
||||||
|
|
||||||
import { AppLogo } from '~/components/app-logo';
|
import { AppLogo } from '~/components/app-logo';
|
||||||
import { personalAccountNavigationConfig } from '~/config/personal-account-navigation.config';
|
import { personalAccountNavigationConfig } from '~/config/personal-account-navigation.config';
|
||||||
@@ -17,7 +19,6 @@ import { HomeMenuNavigation } from '../_components/home-menu-navigation';
|
|||||||
import { HomeMobileNavigation } from '../_components/home-mobile-navigation';
|
import { HomeMobileNavigation } from '../_components/home-mobile-navigation';
|
||||||
import { HomeSidebar } from '../_components/home-sidebar';
|
import { HomeSidebar } from '../_components/home-sidebar';
|
||||||
import { loadUserWorkspace } from '../_lib/server/load-user-workspace';
|
import { loadUserWorkspace } from '../_lib/server/load-user-workspace';
|
||||||
import { retrieveCart } from '@lib/data';
|
|
||||||
|
|
||||||
function UserHomeLayout({ children }: React.PropsWithChildren) {
|
function UserHomeLayout({ children }: React.PropsWithChildren) {
|
||||||
const state = use(getLayoutState());
|
const state = use(getLayoutState());
|
||||||
@@ -44,7 +45,7 @@ function SidebarLayout({ children }: React.PropsWithChildren) {
|
|||||||
</PageNavigation>
|
</PageNavigation>
|
||||||
|
|
||||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||||
<MobileNavigation workspace={workspace} />
|
<MobileNavigation workspace={workspace} cart={null} />
|
||||||
</PageMobileNavigation>
|
</PageMobileNavigation>
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
@@ -66,7 +67,7 @@ function HeaderLayout({ children }: React.PropsWithChildren) {
|
|||||||
</PageNavigation>
|
</PageNavigation>
|
||||||
|
|
||||||
<PageMobileNavigation className={'flex items-center justify-between'}>
|
<PageMobileNavigation className={'flex items-center justify-between'}>
|
||||||
<MobileNavigation workspace={workspace} />
|
<MobileNavigation workspace={workspace} cart={cart} />
|
||||||
</PageMobileNavigation>
|
</PageMobileNavigation>
|
||||||
|
|
||||||
<SidebarProvider defaultOpen>
|
<SidebarProvider defaultOpen>
|
||||||
@@ -84,14 +85,16 @@ function HeaderLayout({ children }: React.PropsWithChildren) {
|
|||||||
|
|
||||||
function MobileNavigation({
|
function MobileNavigation({
|
||||||
workspace,
|
workspace,
|
||||||
|
cart,
|
||||||
}: {
|
}: {
|
||||||
workspace: Awaited<ReturnType<typeof loadUserWorkspace>>;
|
workspace: Awaited<ReturnType<typeof loadUserWorkspace>>;
|
||||||
|
cart: StoreCart | null;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AppLogo />
|
<AppLogo />
|
||||||
|
|
||||||
<HomeMobileNavigation workspace={workspace} />
|
<HomeMobileNavigation workspace={workspace} cart={cart} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export async function HomeMenuNavigation(props: { workspace: UserWorkspace, cart
|
|||||||
<Link href='/home/cart'>
|
<Link href='/home/cart'>
|
||||||
<Button variant="ghost" className='relative px-4 py-2 h-10 border-1 mr-0 cursor-pointer' >
|
<Button variant="ghost" className='relative px-4 py-2 h-10 border-1 mr-0 cursor-pointer' >
|
||||||
<ShoppingCart className="stroke-[1.5px]" />
|
<ShoppingCart className="stroke-[1.5px]" />
|
||||||
<Trans i18nKey="common:shoppingCart" /> ({hasCartItems ? cartItemsCount : 0})
|
<Trans i18nKey="common:shoppingCartCount" values={{ count: cartItemsCount }} />
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<UserNotifications userId={user.id} />
|
<UserNotifications userId={user.id} />
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import { LogOut, Menu } from 'lucide-react';
|
import { LogOut, Menu, ShoppingCart } from 'lucide-react';
|
||||||
|
|
||||||
import { useSignOut } from '@kit/supabase/hooks/use-sign-out';
|
import { useSignOut } from '@kit/supabase/hooks/use-sign-out';
|
||||||
import {
|
import {
|
||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
} from '@kit/ui/dropdown-menu';
|
} from '@kit/ui/dropdown-menu';
|
||||||
import { If } from '@kit/ui/if';
|
import { If } from '@kit/ui/if';
|
||||||
import { Trans } from '@kit/ui/trans';
|
import { Trans } from '@kit/ui/trans';
|
||||||
|
import { StoreCart } from '@medusajs/types';
|
||||||
|
|
||||||
import featuresFlagConfig from '~/config/feature-flags.config';
|
import featuresFlagConfig from '~/config/feature-flags.config';
|
||||||
import { personalAccountNavigationConfig } from '~/config/personal-account-navigation.config';
|
import { personalAccountNavigationConfig } from '~/config/personal-account-navigation.config';
|
||||||
@@ -24,7 +25,7 @@ import { personalAccountNavigationConfig } from '~/config/personal-account-navig
|
|||||||
import { HomeAccountSelector } from '../_components/home-account-selector';
|
import { HomeAccountSelector } from '../_components/home-account-selector';
|
||||||
import type { UserWorkspace } from '../_lib/server/load-user-workspace';
|
import type { UserWorkspace } from '../_lib/server/load-user-workspace';
|
||||||
|
|
||||||
export function HomeMobileNavigation(props: { workspace: UserWorkspace }) {
|
export function HomeMobileNavigation(props: { workspace: UserWorkspace, cart: StoreCart | null }) {
|
||||||
const signOut = useSignOut();
|
const signOut = useSignOut();
|
||||||
|
|
||||||
const Links = personalAccountNavigationConfig.routes.map((item, index) => {
|
const Links = personalAccountNavigationConfig.routes.map((item, index) => {
|
||||||
@@ -46,6 +47,10 @@ export function HomeMobileNavigation(props: { workspace: UserWorkspace }) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const cartItemsCount = props.cart?.items?.length ?? 0;
|
||||||
|
const hasCartItems = cartItemsCount > 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger>
|
<DropdownMenuTrigger>
|
||||||
@@ -69,6 +74,18 @@ export function HomeMobileNavigation(props: { workspace: UserWorkspace }) {
|
|||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
</If>
|
</If>
|
||||||
|
|
||||||
|
<If condition={props.cart && hasCartItems}>
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownLink
|
||||||
|
path="/home/cart"
|
||||||
|
label="common:shoppingCartCount"
|
||||||
|
Icon={<ShoppingCart className="stroke-[1.5px]" />}
|
||||||
|
labelOptions={{ count: cartItemsCount }}
|
||||||
|
/>
|
||||||
|
</DropdownMenuGroup>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
</If>
|
||||||
|
|
||||||
<DropdownMenuGroup>{Links}</DropdownMenuGroup>
|
<DropdownMenuGroup>{Links}</DropdownMenuGroup>
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
@@ -83,6 +100,7 @@ function DropdownLink(
|
|||||||
props: React.PropsWithChildren<{
|
props: React.PropsWithChildren<{
|
||||||
path: string;
|
path: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
labelOptions?: Record<string, any>;
|
||||||
Icon: React.ReactNode;
|
Icon: React.ReactNode;
|
||||||
}>,
|
}>,
|
||||||
) {
|
) {
|
||||||
@@ -95,7 +113,7 @@ function DropdownLink(
|
|||||||
{props.Icon}
|
{props.Icon}
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
<Trans i18nKey={props.label} defaults={props.label} />
|
<Trans i18nKey={props.label} defaults={props.label} values={props.labelOptions} />
|
||||||
</span>
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
"back": "Back",
|
"back": "Back",
|
||||||
"welcome": "Welcome",
|
"welcome": "Welcome",
|
||||||
"shoppingCart": "Shopping cart",
|
"shoppingCart": "Shopping cart",
|
||||||
|
"shoppingCartCount": "Shopping cart ({{count}})",
|
||||||
"search": "Search{{end}}",
|
"search": "Search{{end}}",
|
||||||
"myActions": "My actions",
|
"myActions": "My actions",
|
||||||
"healthPackageComparison": {
|
"healthPackageComparison": {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
"back": "Back",
|
"back": "Back",
|
||||||
"welcome": "Tere tulemast",
|
"welcome": "Tere tulemast",
|
||||||
"shoppingCart": "Ostukorv",
|
"shoppingCart": "Ostukorv",
|
||||||
|
"shoppingCartCount": "Ostukorv ({{count}})",
|
||||||
"search": "Otsi{{end}}",
|
"search": "Otsi{{end}}",
|
||||||
"myActions": "Minu toimingud",
|
"myActions": "Minu toimingud",
|
||||||
"healthPackageComparison": {
|
"healthPackageComparison": {
|
||||||
|
|||||||
Reference in New Issue
Block a user