305 lines
10 KiB
TypeScript
305 lines
10 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="var(--color-gray-300)" 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="var(--color-emerald-500)" />,
|
|
description: 'View and manage customer orders',
|
|
route: '/dashboard/orders',
|
|
category: 'orders',
|
|
iconColor: 'var(--color-emerald-500)',
|
|
iconBg: 'var(--color-emerald-100)',
|
|
onPress: handleManageOrdersPress,
|
|
},
|
|
{
|
|
title: 'Delivery Sequences',
|
|
icon: <RouteIcon size={24} color="var(--color-violet-500)" />,
|
|
description: 'Plan and optimize delivery routes',
|
|
route: '/dashboard/orders/sequence',
|
|
category: 'orders',
|
|
iconColor: 'var(--color-violet-500)',
|
|
iconBg: 'var(--color-violet-100)',
|
|
onPress: handleDeliverySequencesPress,
|
|
},
|
|
{
|
|
title: 'Delivery Slots',
|
|
icon: <CalendarClock size={24} color="var(--color-cyan-500)" />,
|
|
description: 'Configure delivery times',
|
|
route: '/dashboard/slots',
|
|
category: 'quick',
|
|
iconColor: 'var(--color-cyan-500)',
|
|
iconBg: 'var(--color-cyan-100)',
|
|
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="var(--color-amber-500)" />,
|
|
description: 'Handle customer complaints',
|
|
route: '/dashboard/complaints',
|
|
category: 'quick',
|
|
iconColor: 'var(--color-amber-500)',
|
|
iconBg: 'var(--color-amber-100)',
|
|
badgeCount: essentialsData?.unresolvedComplaints,
|
|
},
|
|
{
|
|
title: 'Products',
|
|
icon: <Package size={24} color="var(--color-indigo-500)" />,
|
|
description: 'Manage product catalog',
|
|
route: '/dashboard/products',
|
|
category: 'products',
|
|
iconColor: 'var(--color-indigo-500)',
|
|
iconBg: 'var(--color-indigo-100)',
|
|
},
|
|
{
|
|
title: 'Prices Overview',
|
|
icon: <DollarSign size={24} color="var(--color-emerald-600)" />,
|
|
description: 'Update product pricing',
|
|
route: '/dashboard/prices',
|
|
category: 'products',
|
|
iconColor: 'var(--color-emerald-600)',
|
|
iconBg: 'var(--color-emerald-50)',
|
|
},
|
|
{
|
|
title: 'Product Tags',
|
|
icon: <Tag size={24} color="var(--color-pink-500)" />,
|
|
description: 'Organize with tags',
|
|
route: '/dashboard/product-tags',
|
|
category: 'products',
|
|
iconColor: 'var(--color-pink-500)',
|
|
iconBg: 'var(--color-pink-100)',
|
|
},
|
|
{
|
|
title: 'Product Groupings',
|
|
icon: <Shapes size={24} color="var(--color-violet-500)" />,
|
|
description: 'Group products together',
|
|
route: '/dashboard/product-groupings',
|
|
category: 'products',
|
|
iconColor: 'var(--color-violet-500)',
|
|
iconBg: 'var(--color-purple-100)',
|
|
},
|
|
{
|
|
title: 'Stores',
|
|
icon: <Store size={24} color="var(--color-teal-500)" />,
|
|
description: 'Manage store locations',
|
|
route: '/dashboard/stores',
|
|
category: 'settings',
|
|
iconColor: 'var(--color-teal-500)',
|
|
iconBg: 'var(--color-teal-100)',
|
|
},
|
|
{
|
|
title: 'Coupons',
|
|
icon: <TicketPercent size={24} color="var(--color-orange-500)" />,
|
|
description: 'Create discount coupons',
|
|
route: '/dashboard/coupons',
|
|
category: 'marketing',
|
|
iconColor: 'var(--color-orange-500)',
|
|
iconBg: 'var(--color-orange-100)',
|
|
},
|
|
{
|
|
title: 'App Constants',
|
|
icon: <Settings size={24} color="var(--color-violet-600)" />,
|
|
description: 'Customize app settings',
|
|
route: '/dashboard/customize-app',
|
|
category: 'settings',
|
|
iconColor: 'var(--color-violet-600)',
|
|
iconBg: 'var(--color-purple-100)',
|
|
},
|
|
{
|
|
title: 'User Management',
|
|
icon: <Users size={24} color="var(--color-sky-500)" />,
|
|
description: 'View and manage all users',
|
|
route: '/dashboard/users',
|
|
category: 'users',
|
|
iconColor: 'var(--color-sky-500)',
|
|
iconBg: 'var(--color-sky-100)',
|
|
},
|
|
{
|
|
title: 'Send Notifications',
|
|
icon: <Megaphone size={24} color="var(--color-violet-500)" />,
|
|
description: 'Send push notifications to users',
|
|
route: '/dashboard/notifications',
|
|
category: 'users',
|
|
iconColor: 'var(--color-violet-500)',
|
|
iconBg: 'var(--color-purple-100)',
|
|
},
|
|
]
|
|
|
|
const quickActions = menuItems.filter((item) => item.category === 'quick')
|
|
|
|
const categories = [
|
|
{ key: 'orders', title: 'Orders', icon: <ReceiptText size={18} color={theme.colors.foregroundMuted} /> },
|
|
{
|
|
key: 'products',
|
|
title: 'Products & Inventory',
|
|
icon: <Package size={18} color={theme.colors.foregroundMuted} />,
|
|
},
|
|
{
|
|
key: 'marketing',
|
|
title: 'Marketing & Promotions',
|
|
icon: <Megaphone size={18} color={theme.colors.foregroundMuted} />,
|
|
},
|
|
{ key: 'users', title: 'User Management', icon: <Users size={18} color={theme.colors.foregroundMuted} /> },
|
|
{
|
|
key: 'settings',
|
|
title: 'Settings & Configuration',
|
|
icon: <Settings size={18} color={theme.colors.foregroundMuted} />,
|
|
},
|
|
]
|
|
|
|
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>
|
|
)
|
|
}
|