File size: 2,711 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import * as React from 'react';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Card from '@mui/material/Card';
import CardActions from '@mui/material/CardActions';
import CardHeader from '@mui/material/CardHeader';
import Chip from '@mui/material/Chip';
import Divider from '@mui/material/Divider';
import type { SxProps } from '@mui/material/styles';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
import { ArrowRightIcon } from '@phosphor-icons/react/dist/ssr/ArrowRight';
import dayjs from 'dayjs';
const statusMap = {
pending: { label: 'Pending', color: 'warning' },
delivered: { label: 'Delivered', color: 'success' },
refunded: { label: 'Refunded', color: 'error' },
} as const;
export interface Order {
id: string;
customer: { name: string };
amount: number;
status: 'pending' | 'delivered' | 'refunded';
createdAt: Date;
}
export interface LatestOrdersProps {
orders?: Order[];
sx?: SxProps;
}
export function LatestOrders({ orders = [], sx }: LatestOrdersProps): React.JSX.Element {
return (
<Card sx={sx}>
<CardHeader title="Latest orders" />
<Divider />
<Box sx={{ overflowX: 'auto' }}>
<Table sx={{ minWidth: 800 }}>
<TableHead>
<TableRow>
<TableCell>Order</TableCell>
<TableCell>Customer</TableCell>
<TableCell sortDirection="desc">Date</TableCell>
<TableCell>Status</TableCell>
</TableRow>
</TableHead>
<TableBody>
{orders.map((order) => {
const { label, color } = statusMap[order.status] ?? { label: 'Unknown', color: 'default' };
return (
<TableRow hover key={order.id}>
<TableCell>{order.id}</TableCell>
<TableCell>{order.customer.name}</TableCell>
<TableCell>{dayjs(order.createdAt).format('MMM D, YYYY')}</TableCell>
<TableCell>
<Chip color={color} label={label} size="small" />
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</Box>
<Divider />
<CardActions sx={{ justifyContent: 'flex-end' }}>
<Button
color="inherit"
endIcon={<ArrowRightIcon fontSize="var(--icon-fontSize-md)" />}
size="small"
variant="text"
>
View all
</Button>
</CardActions>
</Card>
);
}
|