2025-08-08 17:59:39 +07:00
|
|
|
'use client'
|
|
|
|
|
|
2025-08-10 21:46:15 +07:00
|
|
|
import React from 'react'
|
2025-08-08 17:59:39 +07:00
|
|
|
import { useDashboardAnalytics } from '../../../../../../services/queries/analytics'
|
2025-08-10 21:46:15 +07:00
|
|
|
import Loading from '../../../../../../components/layout/shared/Loading'
|
2025-08-11 13:48:24 +07:00
|
|
|
import { formatCurrency, formatDate, formatShortCurrency } from '../../../../../../utils/transform'
|
2025-08-10 22:56:04 +07:00
|
|
|
import ProductSales from '../../../../../../views/dashboards/products/ProductSales'
|
|
|
|
|
import PaymentMethodReport from '../../../../../../views/dashboards/payment-methods/PaymentMethodReport'
|
|
|
|
|
import OrdersReport from '../../../../../../views/dashboards/orders/OrdersReport'
|
2025-08-08 17:59:39 +07:00
|
|
|
|
|
|
|
|
const DashboardOverview = () => {
|
2025-08-10 21:46:15 +07:00
|
|
|
// Sample data - replace with your actual data
|
|
|
|
|
const { data: salesData, isLoading } = useDashboardAnalytics()
|
|
|
|
|
|
2025-08-08 17:59:39 +07:00
|
|
|
if (isLoading) return <Loading />
|
|
|
|
|
|
2025-08-10 21:46:15 +07:00
|
|
|
const MetricCard = ({ iconClass, title, value, subtitle, bgColor = 'bg-blue-500' }: any) => (
|
2025-08-10 22:56:04 +07:00
|
|
|
<div className='bg-white rounded-lg shadow-md hover:shadow-xl transition-shadow duration-300 p-6'>
|
2025-08-10 21:46:15 +07:00
|
|
|
<div className='flex items-center justify-between'>
|
|
|
|
|
<div className='flex-1'>
|
|
|
|
|
<h3 className='text-sm font-medium text-gray-600 mb-2'>{title}</h3>
|
|
|
|
|
<p className='text-2xl font-bold text-gray-900 mb-1'>{value}</p>
|
|
|
|
|
{subtitle && <p className='text-sm text-gray-500'>{subtitle}</p>}
|
|
|
|
|
</div>
|
2025-08-12 21:29:24 +07:00
|
|
|
<div className={`px-4 py-3 rounded-full ${bgColor} bg-opacity-10`}>
|
2025-08-10 21:46:15 +07:00
|
|
|
<i className={`${iconClass} text-[32px] ${bgColor.replace('bg-', 'text-')}`}></i>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const ProgressBar = ({ percentage, color = 'bg-blue-500' }: any) => (
|
|
|
|
|
<div className='w-full bg-gray-200 rounded-full h-2'>
|
|
|
|
|
<div
|
|
|
|
|
className={`${color} h-2 rounded-full transition-all duration-300`}
|
|
|
|
|
style={{ width: `${percentage}%` }}
|
|
|
|
|
></div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-08 17:59:39 +07:00
|
|
|
return (
|
2025-08-10 21:46:15 +07:00
|
|
|
<>
|
|
|
|
|
{salesData && (
|
|
|
|
|
<div>
|
|
|
|
|
{/* Header */}
|
|
|
|
|
{/* <div className="mb-8">
|
|
|
|
|
<h1 className="text-3xl font-bold text-gray-900 mb-2">Sales Dashboard</h1>
|
|
|
|
|
<p className="text-gray-600">
|
|
|
|
|
{formatDate(salesData.date_from)} - {formatDate(salesData.date_to)}
|
|
|
|
|
</p>
|
|
|
|
|
</div> */}
|
|
|
|
|
|
|
|
|
|
{/* Overview Metrics */}
|
|
|
|
|
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8'>
|
|
|
|
|
<MetricCard
|
|
|
|
|
iconClass='tabler-cash'
|
|
|
|
|
title='Total Sales'
|
2025-08-11 13:48:24 +07:00
|
|
|
value={formatShortCurrency(salesData.overview.total_sales)}
|
2025-08-10 21:46:15 +07:00
|
|
|
bgColor='bg-green-500'
|
|
|
|
|
/>
|
|
|
|
|
<MetricCard
|
|
|
|
|
iconClass='tabler-shopping-cart'
|
|
|
|
|
title='Total Orders'
|
|
|
|
|
value={salesData.overview.total_orders.toLocaleString()}
|
|
|
|
|
subtitle={`${salesData.overview.voided_orders} voided, ${salesData.overview.refunded_orders} refunded`}
|
|
|
|
|
bgColor='bg-blue-500'
|
|
|
|
|
/>
|
|
|
|
|
<MetricCard
|
|
|
|
|
iconClass='tabler-trending-up'
|
|
|
|
|
title='Average Order Value'
|
2025-08-11 13:48:24 +07:00
|
|
|
value={formatShortCurrency(salesData.overview.average_order_value)}
|
2025-08-10 21:46:15 +07:00
|
|
|
bgColor='bg-purple-500'
|
|
|
|
|
/>
|
|
|
|
|
<MetricCard
|
|
|
|
|
iconClass='tabler-users'
|
|
|
|
|
title='Total Customers'
|
|
|
|
|
value={salesData.overview.total_customers || 'N/A'}
|
|
|
|
|
bgColor='bg-orange-500'
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className='grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8'>
|
|
|
|
|
{/* Top Products */}
|
2025-08-10 22:56:04 +07:00
|
|
|
<ProductSales title='Top Products' productData={salesData.top_products} />
|
2025-08-10 21:46:15 +07:00
|
|
|
|
|
|
|
|
{/* Payment Methods */}
|
2025-08-10 22:56:04 +07:00
|
|
|
<PaymentMethodReport payments={salesData.payment_methods} />
|
2025-08-10 21:46:15 +07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Recent Sales */}
|
2025-08-10 22:56:04 +07:00
|
|
|
<OrdersReport title='Recent Sales' orderData={salesData.recent_sales} />
|
2025-08-10 21:46:15 +07:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2025-08-08 17:59:39 +07:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DashboardOverview
|