'use client'; import * as React from 'react'; import RouterLink from 'next/link'; import Avatar from '@mui/material/Avatar'; import Box from '@mui/material/Box'; import Chip from '@mui/material/Chip'; import IconButton from '@mui/material/IconButton'; import LinearProgress from '@mui/material/LinearProgress'; import Link from '@mui/material/Link'; import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle'; import { Clock as ClockIcon } from '@phosphor-icons/react/dist/ssr/Clock'; import { Minus as MinusIcon } from '@phosphor-icons/react/dist/ssr/Minus'; import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple'; import { paths } from '@/paths'; import { dayjs } from '@/lib/dayjs'; import { DataTable } from '@/components/core/data-table'; import type { ColumnDef } from '@/components/core/data-table'; import { useCustomersSelection } from './customers-selection-context'; export interface Customer { id: string; name: string; avatar?: string; email: string; phone?: string; quota: number; status: 'pending' | 'active' | 'blocked'; createdAt: Date; } const columns = [ { formatter: (row): React.JSX.Element => ( {' '}
{row.name} {row.email}
), name: 'Name', width: '250px', }, { formatter: (row): React.JSX.Element => ( {new Intl.NumberFormat('en-US', { style: 'percent', maximumFractionDigits: 2 }).format(row.quota / 100)} ), name: 'Quota', width: '250px', }, { field: 'phone', name: 'Phone number', width: '150px' }, { formatter(row) { return dayjs(row.createdAt).format('MMM D, YYYY h:mm A'); }, name: 'Created at', width: '200px', }, { formatter: (row): React.JSX.Element => { const mapping = { active: { label: 'Active', icon: }, blocked: { label: 'Blocked', icon: }, pending: { label: 'Pending', icon: }, } as const; const { label, icon } = mapping[row.status] ?? { label: 'Unknown', icon: null }; return ; }, name: 'Status', width: '150px', }, { formatter: (): React.JSX.Element => ( ), name: 'Actions', hideName: true, width: '100px', align: 'right', }, ] satisfies ColumnDef[]; export interface CustomersTableProps { rows: Customer[]; } export function CustomersTable({ rows }: CustomersTableProps): React.JSX.Element { const { deselectAll, deselectOne, selectAll, selectOne, selected } = useCustomersSelection(); return ( columns={columns} onDeselectAll={deselectAll} onDeselectOne={(_, row) => { deselectOne(row.id); }} onSelectAll={selectAll} onSelectOne={(_, row) => { selectOne(row.id); }} rows={rows} selectable selected={selected} /> {!rows.length ? ( No customers found ) : null} ); }