'use client'; import * as React from 'react'; import Avatar from '@mui/material/Avatar'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; import CardHeader from '@mui/material/CardHeader'; import Chip from '@mui/material/Chip'; import Divider from '@mui/material/Divider'; import Link from '@mui/material/Link'; import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus'; import { ShoppingCartSimple as ShoppingCartSimpleIcon } from '@phosphor-icons/react/dist/ssr/ShoppingCartSimple'; import { dayjs } from '@/lib/dayjs'; import type { ColumnDef } from '@/components/core/data-table'; import { DataTable } from '@/components/core/data-table'; export interface Payment { currency: string; amount: number; invoiceId: string; status: 'pending' | 'completed' | 'canceled' | 'refunded'; createdAt: Date; } const columns = [ { formatter: (row): React.JSX.Element => ( {new Intl.NumberFormat('en-US', { style: 'currency', currency: row.currency }).format(row.amount)} ), name: 'Amount', width: '200px', }, { formatter: (row): React.JSX.Element => { const mapping = { pending: { label: 'Pending', color: 'warning' }, completed: { label: 'Completed', color: 'success' }, canceled: { label: 'Canceled', color: 'error' }, refunded: { label: 'Refunded', color: 'error' }, } as const; const { label, color } = mapping[row.status] ?? { label: 'Unknown', color: 'secondary' }; return ; }, name: 'Status', width: '200px', }, { formatter: (row): React.JSX.Element => { return {row.invoiceId}; }, name: 'Invoice ID', width: '150px', }, { formatter: (row): React.JSX.Element => ( {dayjs(row.createdAt).format('MMM D, YYYY hh:mm A')} ), name: 'Date', align: 'right', }, ] satisfies ColumnDef[]; export interface PaymentsProps { ordersValue: number; payments: Payment[]; refundsValue: number; totalOrders: number; } export function Payments({ ordersValue, payments = [], refundsValue, totalOrders }: PaymentsProps): React.JSX.Element { return ( }> Create Payment } avatar={ } title="Payments" /> } spacing={3} sx={{ justifyContent: 'space-between', p: 2 }} >
Total orders {new Intl.NumberFormat('en-US').format(totalOrders)}
Orders value {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(ordersValue)}
Refunds {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(refundsValue)}
columns={columns} rows={payments} />
); }