| 21 | } |
| 22 | |
| 23 | export function ProfileToggle({ className }: Props) { |
| 24 | const router = useRouter(); |
| 25 | const { organizationId } = useParams({ strict: false }); |
| 26 | const { setTheme, userTheme, themes } = useTheme(); |
| 27 | const logout = useLogout(); |
| 28 | |
| 29 | const goToAccount = () => { |
| 30 | if (organizationId) { |
| 31 | router.navigate({ |
| 32 | to: '/$organizationId/account', |
| 33 | params: { organizationId }, |
| 34 | }); |
| 35 | return; |
| 36 | } |
| 37 | router.navigate({ to: '/account' }); |
| 38 | }; |
| 39 | |
| 40 | return ( |
| 41 | <DropdownMenu> |
| 42 | <DropdownMenuTrigger asChild> |
| 43 | <button |
| 44 | className={cn(className, 'center-center outline-0')} |
| 45 | type="button" |
| 46 | > |
| 47 | <UserIcon className="size-4" /> |
| 48 | <span className="sr-only">Profile</span> |
| 49 | </button> |
| 50 | </DropdownMenuTrigger> |
| 51 | <DropdownMenuContent align="center" className="w-56"> |
| 52 | <DropdownMenuItem onClick={goToAccount}>Account</DropdownMenuItem> |
| 53 | <DropdownMenuSeparator /> |
| 54 | <DropdownMenuSub> |
| 55 | <DropdownMenuSubTrigger className="flex w-full items-center justify-between"> |
| 56 | Theme |
| 57 | <DropdownMenuShortcut> |
| 58 | <span className="mr-2">{themeConfig[userTheme].icon}</span> |
| 59 | {themeConfig[userTheme].label} |
| 60 | </DropdownMenuShortcut> |
| 61 | </DropdownMenuSubTrigger> |
| 62 | <DropdownMenuSubContent className="p-0"> |
| 63 | {themes.map((themeOption) => ( |
| 64 | <DropdownMenuItem |
| 65 | className="capitalize" |
| 66 | key={themeOption.key} |
| 67 | onClick={() => setTheme(themeOption.key)} |
| 68 | > |
| 69 | <span className="mr-2">{themeOption.icon}</span> |
| 70 | {themeOption.label} |
| 71 | {userTheme === themeOption.key && ( |
| 72 | <CheckIcon className="ml-2 h-4 w-4" /> |
| 73 | )} |
| 74 | </DropdownMenuItem> |
| 75 | ))} |
| 76 | </DropdownMenuSubContent> |
| 77 | </DropdownMenuSub> |
| 78 | <DropdownMenuSeparator /> |
| 79 | <DropdownMenuItem |
| 80 | className="text-red-600" |