import { useQuery } from '@tanstack/react-query'; import { OrderService } from '../orders/OrderService'; import { DataGrid, GridColDef } from '@mui/x-data-grid'; import { Chip, Link, Paper, TableContainer, Typography } from '@mui/material'; type Color = | 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning'; const columns: GridColDef[] = [ { field: 'order_id', headerName: 'ID', renderCell: (params) => { return ( {params.value} ); }, }, { field: 'customer', flex: 2, headerName: 'Customer', renderCell: (params) => { return ( <> {params.value.guest ? ( <>{params.value.name} ) : ( {params.value.name} )} ); }, }, { field: 'order_date', flex: 1, headerName: 'Date', type: 'dateTime', valueGetter: (params) => new Date(params.value), }, { field: 'status', flex: 1, headerName: 'Status', renderCell: (params) => { return ( ); }, }, { field: 'total_amt', flex: 1, headerName: 'Total', type: 'number', valueGetter: (params) => new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }).format(params.value), }, ]; function statusColor(value: string): Color { switch (value) { case 'completed': return 'success'; case 'cancelled': return 'error'; default: return 'default'; } } export const RecentOrders = () => { const params = { direction: 'desc', orderBy: 'order_id', perPage: 10, }; const statusToContext = (status: string): string => { switch (status) { case 'created': case 'pending-approval': return 'warning'; case 'completed': return 'success'; case 'cancelled': return 'danger'; default: return 'light'; } }; const { data: orders, isLoading } = useQuery({ queryKey: ['orders'], queryFn: () => OrderService.index(params), }); return ( <> {orders ? ( <> Recent orders row.order_id} hideFooter loading={isLoading} rows={orders} /> ) : null} ); };