|
| 1 | +import { |
| 2 | + Avatar, |
| 3 | + AvatarFallback, |
| 4 | + AvatarImage, |
| 5 | + Tooltip, |
| 6 | + TooltipContent, |
| 7 | + TooltipProvider, |
| 8 | + TooltipTrigger, |
| 9 | +} from '@/components/ui'; |
| 10 | +import { useUserStore } from '@/store/use-user'; |
| 11 | +import { Link, LinkProps } from '@tanstack/react-router'; |
| 12 | +import { |
| 13 | + Bot, |
| 14 | + BrainCircuit, |
| 15 | + Cable, |
| 16 | + MessageSquareCode, |
| 17 | + Settings, |
| 18 | +} from 'lucide-react'; |
| 19 | +import { useTranslation } from 'react-i18next'; |
| 20 | + |
| 21 | +const SIDEBAR_ITEMS: Array<{ |
| 22 | + Icon: JSX.Element; |
| 23 | + i18n: string; |
| 24 | + to: LinkProps['to']; |
| 25 | +}> = [ |
| 26 | + { |
| 27 | + Icon: ( |
| 28 | + <MessageSquareCode className="w-5 h-5 text-white group-hover:opacity-85 transition-all" /> |
| 29 | + ), |
| 30 | + i18n: 'chatbots', |
| 31 | + to: '/chatbots', |
| 32 | + }, |
| 33 | + { |
| 34 | + Icon: ( |
| 35 | + <BrainCircuit className="w-5 h-5 text-white group-hover:opacity-85 transition-all" /> |
| 36 | + ), |
| 37 | + i18n: 'training', |
| 38 | + to: '/chatbots', |
| 39 | + }, |
| 40 | + { |
| 41 | + Icon: ( |
| 42 | + <Cable className="w-5 h-5 text-white group-hover:opacity-85 transition-all" /> |
| 43 | + ), |
| 44 | + i18n: 'integrations', |
| 45 | + to: '/chatbots', |
| 46 | + }, |
| 47 | +]; |
| 48 | + |
| 49 | +const Sidebar = () => { |
| 50 | + const { t } = useTranslation('common'); |
| 51 | + const { user } = useUserStore(); |
| 52 | + |
| 53 | + return ( |
| 54 | + <aside className="w-sidebar bg-stone-800 min-h-svh flex flex-col fixed left-0 top-0 bottom-0"> |
| 55 | + <Link |
| 56 | + className="bg-primary w-sidebar h-sidebar flex items-center justify-center" |
| 57 | + to="/dashboard" |
| 58 | + > |
| 59 | + <Bot size={32} className="text-white" /> |
| 60 | + </Link> |
| 61 | + <nav className="flex flex-col flex-1"> |
| 62 | + <ul className="flex flex-col"> |
| 63 | + {SIDEBAR_ITEMS.map((item, index) => ( |
| 64 | + <TooltipProvider key={item.i18n + index}> |
| 65 | + <Tooltip> |
| 66 | + <TooltipTrigger> |
| 67 | + <li className="h-12 w-full flex items-center justify-center group"> |
| 68 | + <Link |
| 69 | + search |
| 70 | + to={item.to} |
| 71 | + className="w-full h-full flex items-center justify-center" |
| 72 | + > |
| 73 | + {item.Icon} |
| 74 | + </Link> |
| 75 | + </li> |
| 76 | + </TooltipTrigger> |
| 77 | + <TooltipContent side="right"> |
| 78 | + <p>{t(item.i18n as any)}</p> |
| 79 | + </TooltipContent> |
| 80 | + </Tooltip> |
| 81 | + </TooltipProvider> |
| 82 | + ))} |
| 83 | + </ul> |
| 84 | + |
| 85 | + <div className="mt-auto"> |
| 86 | + <TooltipProvider> |
| 87 | + <Tooltip> |
| 88 | + <TooltipTrigger className="h-12 w-full flex items-center justify-center group"> |
| 89 | + <Link |
| 90 | + search |
| 91 | + to="/settings" |
| 92 | + className="w-full h-full flex items-center justify-center" |
| 93 | + > |
| 94 | + <Settings className="w-5 h-5 text-white group-hover:opacity-85 transition-all" /> |
| 95 | + </Link> |
| 96 | + </TooltipTrigger> |
| 97 | + <TooltipContent side="right"> |
| 98 | + <p>{t('settings')}</p> |
| 99 | + </TooltipContent> |
| 100 | + </Tooltip> |
| 101 | + </TooltipProvider> |
| 102 | + <div className="flex items-center justify-center cursor-pointer w-sidebar h-sidebar"> |
| 103 | + <Avatar className="w-9 h-9"> |
| 104 | + <AvatarImage |
| 105 | + src={user?.avatar as string} |
| 106 | + alt={user?.name} |
| 107 | + /> |
| 108 | + <AvatarFallback> |
| 109 | + <span>{user?.name?.[0]}</span> |
| 110 | + </AvatarFallback> |
| 111 | + </Avatar> |
| 112 | + </div> |
| 113 | + </div> |
| 114 | + </nav> |
| 115 | + </aside> |
| 116 | + ); |
| 117 | +}; |
| 118 | + |
| 119 | +export default Sidebar; |
0 commit comments