freshyo/apps/admin-web/src/routes/dashboard.index.tsx
2026-09-06 23:05:20 +05:30

305 lines
9.3 KiB
TypeScript

import React from 'react'
import { createFileRoute, useNavigate } from '@tanstack/react-router'
import {
ShoppingBag,
Route as RouteIcon,
CalendarClock,
CirclePlus,
TriangleAlert,
Package,
DollarSign,
Tag,
Shapes,
Store,
TicketPercent,
Settings,
Users,
Megaphone,
ReceiptText,
ChevronRight,
} from 'lucide-react'
import { p as MyText } from 'web-components'
import { trpc } from '../lib/trpc-client'
import { useNavigationTarget } from '../lib/navigation-target'
import { theme } from '../lib/theme'
export const Route = createFileRoute('/dashboard/')({
component: Dashboard,
})
interface MenuItem {
title: string
icon: React.ReactNode
description?: string
route: string
category: 'quick' | 'products' | 'orders' | 'marketing' | 'settings' | 'users'
iconColor?: string
iconBg?: string
badgeCount?: number
onPress?: () => void
testID?: string
}
const MenuItemComponent: React.FC<{ item: MenuItem; go: (item: MenuItem) => void }> = ({
item,
go,
}) => {
return (
<button
onClick={() => go(item)}
className="mb-3 flex w-full flex-row items-center rounded-xl border border-gray-100 bg-white p-4 text-left shadow-sm transition-colors hover:bg-gray-50 active:bg-gray-50"
>
<span
className="mr-4 flex h-12 w-12 items-center justify-center rounded-xl"
style={{ backgroundColor: item.iconBg }}
>
{item.icon}
</span>
<span className="flex min-w-0 flex-1 flex-col">
<MyText className="mb-0.5 text-base font-bold text-gray-900">{item.title}</MyText>
{item.description && <MyText className="text-xs text-gray-500">{item.description}</MyText>}
</span>
{item.badgeCount ? (
<span className="rounded-full bg-red-500 px-2 py-1">
<MyText className="text-xs font-bold text-white">{item.badgeCount}</MyText>
</span>
) : null}
<ChevronRight size={24} color="#D1D5DB" className="ml-2" />
</button>
)
}
function Dashboard() {
const navigate = useNavigate()
const { setNavigationTarget } = useNavigationTarget()
const { data: essentialsData } = trpc.admin.user.getEssentials.useQuery()
const go = (item: MenuItem) => {
if (item.onPress) {
item.onPress()
} else {
navigate({ to: item.route as any })
}
}
const handleManageOrdersPress = () => {
setNavigationTarget('/dashboard/orders/list')
navigate({ to: '/dashboard/orders' })
}
const handleDeliverySequencesPress = () => {
setNavigationTarget('/dashboard/orders/sequence')
navigate({ to: '/dashboard/orders' })
}
const menuItems: MenuItem[] = [
{
title: 'Manage Orders',
icon: <ShoppingBag size={24} color="#10B981" />,
description: 'View and manage customer orders',
route: '/dashboard/orders',
category: 'orders',
iconColor: '#10B981',
iconBg: '#D1FAE5',
onPress: handleManageOrdersPress,
},
{
title: 'Delivery Sequences',
icon: <RouteIcon size={24} color="#8B5CF6" />,
description: 'Plan and optimize delivery routes',
route: '/dashboard/orders/sequence',
category: 'orders',
iconColor: '#8B5CF6',
iconBg: '#EDE9FE',
onPress: handleDeliverySequencesPress,
},
{
title: 'Delivery Slots',
icon: <CalendarClock size={24} color="#06B6D4" />,
description: 'Configure delivery times',
route: '/dashboard/slots',
category: 'quick',
iconColor: '#06B6D4',
iconBg: '#CFFAFE',
testID: 'delivery-slots-menu-item',
},
{
title: 'Add Product',
icon: <CirclePlus size={24} color={theme.colors.brand500} />,
description: 'Create a new product listing',
route: '/dashboard/products/new',
category: 'quick',
iconColor: theme.colors.brand500,
iconBg: theme.colors.brand50,
},
{
title: 'Complaints',
icon: <TriangleAlert size={24} color="#F59E0B" />,
description: 'Handle customer complaints',
route: '/dashboard/complaints',
category: 'quick',
iconColor: '#F59E0B',
iconBg: '#FEF3C7',
badgeCount: essentialsData?.unresolvedComplaints,
},
{
title: 'Products',
icon: <Package size={24} color="#6366F1" />,
description: 'Manage product catalog',
route: '/dashboard/products',
category: 'products',
iconColor: '#6366F1',
iconBg: '#E0E7FF',
},
{
title: 'Prices Overview',
icon: <DollarSign size={24} color="#059669" />,
description: 'Update product pricing',
route: '/dashboard/prices',
category: 'products',
iconColor: '#059669',
iconBg: '#ECFDF5',
},
{
title: 'Product Tags',
icon: <Tag size={24} color="#EC4899" />,
description: 'Organize with tags',
route: '/dashboard/product-tags',
category: 'products',
iconColor: '#EC4899',
iconBg: '#FCE7F3',
},
{
title: 'Product Groupings',
icon: <Shapes size={24} color="#8B5CF6" />,
description: 'Group products together',
route: '/dashboard/product-groupings',
category: 'products',
iconColor: '#8B5CF6',
iconBg: '#F3E8FF',
},
{
title: 'Stores',
icon: <Store size={24} color="#14B8A6" />,
description: 'Manage store locations',
route: '/dashboard/stores',
category: 'settings',
iconColor: '#14B8A6',
iconBg: '#CCFBF1',
},
{
title: 'Coupons',
icon: <TicketPercent size={24} color="#F97316" />,
description: 'Create discount coupons',
route: '/dashboard/coupons',
category: 'marketing',
iconColor: '#F97316',
iconBg: '#FFEDD5',
},
{
title: 'App Constants',
icon: <Settings size={24} color="#7C3AED" />,
description: 'Customize app settings',
route: '/dashboard/customize-app',
category: 'settings',
iconColor: '#7C3AED',
iconBg: '#F3E8FF',
},
{
title: 'User Management',
icon: <Users size={24} color="#0EA5E9" />,
description: 'View and manage all users',
route: '/dashboard/users',
category: 'users',
iconColor: '#0EA5E9',
iconBg: '#E0F2FE',
},
{
title: 'Send Notifications',
icon: <Megaphone size={24} color="#8B5CF6" />,
description: 'Send push notifications to users',
route: '/dashboard/notifications',
category: 'users',
iconColor: '#8B5CF6',
iconBg: '#F3E8FF',
},
]
const quickActions = menuItems.filter((item) => item.category === 'quick')
const categories = [
{ key: 'orders', title: 'Orders', icon: <ReceiptText size={18} color={theme.colors.gray600} /> },
{
key: 'products',
title: 'Products & Inventory',
icon: <Package size={18} color={theme.colors.gray600} />,
},
{
key: 'marketing',
title: 'Marketing & Promotions',
icon: <Megaphone size={18} color={theme.colors.gray600} />,
},
{ key: 'users', title: 'User Management', icon: <Users size={18} color={theme.colors.gray600} /> },
{
key: 'settings',
title: 'Settings & Configuration',
icon: <Settings size={18} color={theme.colors.gray600} />,
},
]
return (
<div className="min-h-full flex-1 bg-gray-50">
{/* Quick Actions */}
<div className="mb-4 mt-2 px-6">
<MyText className="mb-4 text-lg font-bold text-gray-900">Quick Actions</MyText>
<div className="flex flex-row flex-wrap gap-3">
{quickActions.map((item) => (
<button
key={`quick-${item.route}`}
data-testid={item.testID}
aria-label={item.testID}
onClick={() => go(item)}
className="flex flex-1 flex-col items-center rounded-xl border border-gray-100 bg-white p-3 shadow-sm transition-colors hover:bg-gray-50 active:bg-gray-50"
>
<span
className="relative mb-2 flex h-10 w-10 items-center justify-center rounded-lg"
style={{ backgroundColor: item.iconBg }}
>
{item.icon}
{item.badgeCount ? (
<span className="absolute -right-1 -top-1 flex h-5 min-w-5 items-center justify-center rounded-full bg-red-500 px-1">
<MyText className="text-[10px] font-bold text-white">{item.badgeCount}</MyText>
</span>
) : null}
</span>
<MyText className="text-center text-xs font-bold text-gray-900" numberOfLines={2}>{item.title}</MyText>
</button>
))}
</div>
</div>
{/* Categorized Menu Items */}
<div className="px-6 pb-6">
{categories.map((category) => {
const categoryItems = menuItems.filter((item) => item.category === category.key)
if (categoryItems.length === 0) return null
return (
<div key={category.key} className="mb-6">
<div className="mb-3 flex flex-row items-center">
<span className="mr-3 flex h-8 w-8 items-center justify-center rounded-lg bg-gray-100">
{category.icon}
</span>
<MyText className="text-base font-bold text-gray-700">{category.title}</MyText>
</div>
{categoryItems.map((item) => (
<MenuItemComponent key={`menu-${item.route}`} item={item} go={go} />
))}
</div>
)
})}
</div>
</div>
)
}