* add doctor jobs view * change translation * another translation change * clean up * add analaysis detail view to paths config * translation * merge fix * fix path * move components to shared * refactor * imports * clean up
148 lines
3.6 KiB
TypeScript
148 lines
3.6 KiB
TypeScript
'use client';
|
|
|
|
import Link from 'next/link';
|
|
|
|
import { StoreCart } from '@medusajs/types';
|
|
import { LogOut, Menu, ShoppingCart } from 'lucide-react';
|
|
|
|
import {
|
|
featureFlagsConfig,
|
|
personalAccountNavigationConfig,
|
|
} from '@kit/shared/config';
|
|
import { useSignOut } from '@kit/supabase/hooks/use-sign-out';
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuLabel,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from '@kit/ui/dropdown-menu';
|
|
import { If } from '@kit/ui/if';
|
|
import { Trans } from '@kit/ui/trans';
|
|
|
|
// home imports
|
|
import { HomeAccountSelector } from '../_components/home-account-selector';
|
|
import type { UserWorkspace } from '../_lib/server/load-user-workspace';
|
|
|
|
export function HomeMobileNavigation(props: {
|
|
workspace: UserWorkspace;
|
|
cart: StoreCart | null;
|
|
}) {
|
|
const signOut = useSignOut();
|
|
|
|
const Links = personalAccountNavigationConfig.routes.map((item, index) => {
|
|
if ('children' in item) {
|
|
return item.children.map((child) => {
|
|
return (
|
|
<DropdownLink
|
|
key={child.path}
|
|
Icon={child.Icon}
|
|
path={child.path}
|
|
label={child.label}
|
|
/>
|
|
);
|
|
});
|
|
}
|
|
|
|
if ('divider' in item) {
|
|
return <DropdownMenuSeparator key={index} />;
|
|
}
|
|
});
|
|
|
|
const cartItemsCount = props.cart?.items?.length ?? 0;
|
|
const hasCartItems = cartItemsCount > 0;
|
|
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger>
|
|
<Menu className={'h-9'} />
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent sideOffset={10} className={'w-screen rounded-none'}>
|
|
<If condition={featureFlagsConfig.enableTeamAccounts}>
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuLabel>
|
|
<Trans i18nKey={'common:yourAccounts'} />
|
|
</DropdownMenuLabel>
|
|
|
|
<HomeAccountSelector
|
|
userId={props.workspace.user.id}
|
|
accounts={props.workspace.accounts}
|
|
collisionPadding={0}
|
|
/>
|
|
</DropdownMenuGroup>
|
|
|
|
<DropdownMenuSeparator />
|
|
</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>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<SignOutDropdownItem onSignOut={() => signOut.mutateAsync()} />
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|
|
|
|
function DropdownLink(
|
|
props: React.PropsWithChildren<{
|
|
path: string;
|
|
label: string;
|
|
labelOptions?: Record<string, any>;
|
|
Icon: React.ReactNode;
|
|
}>,
|
|
) {
|
|
return (
|
|
<DropdownMenuItem asChild key={props.path}>
|
|
<Link
|
|
href={props.path}
|
|
className={'flex h-12 w-full items-center space-x-4'}
|
|
>
|
|
{props.Icon}
|
|
|
|
<span>
|
|
<Trans
|
|
i18nKey={props.label}
|
|
defaults={props.label}
|
|
values={props.labelOptions}
|
|
/>
|
|
</span>
|
|
</Link>
|
|
</DropdownMenuItem>
|
|
);
|
|
}
|
|
|
|
function SignOutDropdownItem(
|
|
props: React.PropsWithChildren<{
|
|
onSignOut: () => unknown;
|
|
}>,
|
|
) {
|
|
return (
|
|
<DropdownMenuItem
|
|
className={'flex h-12 w-full items-center space-x-4'}
|
|
onClick={props.onSignOut}
|
|
>
|
|
<LogOut className={'h-6'} />
|
|
|
|
<span>
|
|
<Trans i18nKey={'common:signOut'} defaults={'Sign out'} />
|
|
</span>
|
|
</DropdownMenuItem>
|
|
);
|
|
}
|