-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #777 from trash-lobster/next
- Loading branch information
Showing
7 changed files
with
229 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/react/src/components/header/userMenu/components/UserMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { useAuth } from "@/hooks/useAuth"; | ||
import { userAtom } from "@/store/auth"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuTrigger, | ||
DropdownMenuContent, | ||
DropdownMenuSeparator, | ||
} from "@radix-ui/react-dropdown-menu"; | ||
import { GearIcon, CalendarIcon, ExitIcon } from "@radix-ui/react-icons"; | ||
import { useAtomValue } from "jotai"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Link } from "react-router-dom"; | ||
import { UserMenuItem } from "./UserMenuItem"; | ||
import { Button } from "@/shadcn/ui/button"; | ||
import { DropdownMenuLabel } from "@/shadcn/ui/dropdown-menu"; | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/shadcn/ui/avatar"; | ||
|
||
export function UserMenu() { | ||
const { t } = useTranslation(); | ||
const user = useAtomValue(userAtom); | ||
const { logout } = useAuth(); | ||
|
||
const mockUserMenuItems = [ | ||
{ | ||
key: "settings", | ||
value: "Settings", | ||
fn: () => console.log("settings"), | ||
icon: <GearIcon />, | ||
}, | ||
{ | ||
key: "iCalFeed", | ||
value: "ICal Feed", | ||
fn: () => console.log("iCalFeed"), | ||
icon: <CalendarIcon />, | ||
}, | ||
{ key: "logout", value: "Logout", fn: logout, icon: <ExitIcon /> }, | ||
]; | ||
|
||
if (!user) { | ||
return ( | ||
<Button asChild> | ||
<Link to="/login">{t("component.mainNav.login")}</Link> | ||
</Button> | ||
); | ||
} | ||
|
||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="z-30 mx-2 w-8 shrink-0 overflow-hidden rounded-full bg-base-2"> | ||
<img | ||
src={`https://api.dicebear.com/7.x/shapes/svg?seed=${user.id}`} | ||
alt="User avatar" | ||
/> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="relative right-8 z-30 bg-base-2"> | ||
{/* user profile */} | ||
<div className="grid grid-cols-4 grid-rows-3 p-4"> | ||
<Avatar className="col-start-1 row-span-3 row-start-1 self-center justify-self-center"> | ||
<AvatarImage | ||
src={`https://api.dicebear.com/7.x/shapes/svg?seed=${user.id}`} | ||
alt="userIcon" | ||
/> | ||
<AvatarFallback>CN</AvatarFallback> | ||
</Avatar> | ||
<div className="col-span-3 col-start-2 row-span-2 row-start-1"> | ||
<DropdownMenuLabel>{user.username}</DropdownMenuLabel> | ||
<div className="flex flex-row gap-2 px-2 py-1.5 "> | ||
<div | ||
className={user.google_id ? "text-secondary-11" : "text-base"} | ||
> | ||
<div className="i-mdi:google p-1 text-xs" /> | ||
</div> | ||
<div | ||
className={user.discord_id ? "text-secondary-11" : "text-base"} | ||
> | ||
<div className="i-mdi:discord p-1 text-xs" /> | ||
</div> | ||
<div | ||
className={user.twitter_id ? "text-secondary-11" : "text-base"} | ||
> | ||
<div className="i-mdi:twitter p-1 text-xs" /> | ||
</div> | ||
</div> | ||
</div> | ||
<DropdownMenuLabel className="col-span-3 col-start-2 row-start-3 capitalize text-base-11"> | ||
{user.role} : {user.contribution_count} | ||
{t("component.mainNav.points")} | ||
</DropdownMenuLabel> | ||
</div> | ||
<DropdownMenuSeparator className="border-base" /> | ||
{mockUserMenuItems.map((item) => { | ||
return ( | ||
<UserMenuItem | ||
key={item.key + item.value} | ||
item={{ key: item.key, value: item.value, icon: item.icon }} | ||
onClick={item.fn} | ||
/> | ||
); | ||
})} | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/react/src/components/header/userMenu/components/UserMenuItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from "react"; | ||
import { DropdownMenuItem } from "@/shadcn/ui/dropdown-menu"; | ||
// import { useTranslation } from "react-i18next"; | ||
import { MenuItem } from "../types"; | ||
|
||
interface UserMenuItemProps { | ||
item: MenuItem; | ||
onClick: () => void; | ||
} | ||
|
||
export function UserMenuItem({ item, onClick }: UserMenuItemProps) { | ||
return ( | ||
<DropdownMenuItem | ||
onClick={() => onClick()} | ||
className="grid h-full w-full cursor-pointer grid-cols-4 p-4" | ||
> | ||
<div className="col-start-1 self-center justify-self-center"> | ||
{item.icon} | ||
</div> | ||
<div className="col-span-3 col-start-2 px-2">{item.value}</div> | ||
</DropdownMenuItem> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type MenuItem = { | ||
key: string; | ||
value: string; | ||
icon: React.JSX.Element; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as React from "react" | ||
import * as AvatarPrimitive from "@radix-ui/react-avatar" | ||
|
||
import { cn } from "@/lib/utils" | ||
|
||
const Avatar = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Root | ||
ref={ref} | ||
className={cn( | ||
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
Avatar.displayName = AvatarPrimitive.Root.displayName | ||
|
||
const AvatarImage = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Image>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Image | ||
ref={ref} | ||
className={cn("aspect-square h-full w-full", className)} | ||
{...props} | ||
/> | ||
)) | ||
AvatarImage.displayName = AvatarPrimitive.Image.displayName | ||
|
||
const AvatarFallback = React.forwardRef< | ||
React.ElementRef<typeof AvatarPrimitive.Fallback>, | ||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback> | ||
>(({ className, ...props }, ref) => ( | ||
<AvatarPrimitive.Fallback | ||
ref={ref} | ||
className={cn( | ||
"flex h-full w-full items-center justify-center rounded-full bg-muted", | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName | ||
|
||
export { Avatar, AvatarImage, AvatarFallback } |