update tables

This commit is contained in:
2025-11-25 08:16:34 -03:00
parent 89b92948a6
commit d7fe03bd1f
23 changed files with 432 additions and 651 deletions

View File

@@ -0,0 +1,127 @@
'use client'
import type { ColumnDef } from '@tanstack/react-table'
import { HelpCircleIcon } from 'lucide-react'
import { Badge } from '@repo/ui/components/ui/badge'
import { Abbr } from '@repo/ui/components/abbr'
import { Avatar, AvatarFallback } from '@repo/ui/components/ui/avatar'
import { Progress } from '@repo/ui/components/ui/progress'
import {
DataTableColumnDatetime,
DataTableColumnHeaderSort
} from '@repo/ui/components/data-table'
import { cn, initials } from '@repo/ui/lib/utils'
import { labels, statuses, type Enrollment } from './data'
export type { Enrollment }
export const columns: ColumnDef<Enrollment>[] = [
{
accessorKey: 'user',
header: 'Colaborador',
enableHiding: false,
cell: ({ row }) => {
const user = row.getValue('user') as { name: string; email: string }
return (
<div className="flex gap-2.5 items-center">
<Avatar className="size-10 hidden lg:block">
<AvatarFallback>{initials(user.name)}</AvatarFallback>
</Avatar>
<ul>
<li className="font-bold">
<Abbr>{user.name}</Abbr>
</li>
<li className="text-muted-foreground text-sm">
<Abbr>{user.email}</Abbr>
</li>
</ul>
</div>
)
}
},
{
accessorKey: 'course',
header: 'Curso',
enableHiding: false,
cell: ({ row }) => {
const { name } = row.getValue('course') as { name: string }
return <Abbr>{name}</Abbr>
}
},
{
accessorKey: 'status',
header: 'Status',
enableHiding: false,
cell: ({ row }) => {
const s = row.getValue('status') as string
const status = labels[s] ?? s
const { icon: Icon, color } = statuses?.[s] ?? { icon: HelpCircleIcon }
return (
<Badge variant="outline" className={cn(color, ' px-1.5')}>
<Icon className={cn('stroke-2', color)} />
{status}
</Badge>
)
}
},
{
accessorKey: 'progress',
header: 'Progresso',
enableHiding: false,
cell: ({ row }) => {
const progress = row.getValue('progress')
return (
<div className="flex gap-2.5 items-center ">
<Progress value={Number(progress)} className="w-32" />
<span className="text-xs">{String(progress)}%</span>
</div>
)
}
},
{
accessorKey: 'created_at',
meta: { title: 'Cadastrado em' },
enableSorting: true,
enableHiding: true,
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
},
{
accessorKey: 'started_at',
meta: { title: 'Iniciado em' },
enableSorting: true,
enableHiding: true,
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
},
{
accessorKey: 'completed_at',
meta: { title: 'Concluído em' },
enableSorting: true,
enableHiding: true,
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
},
{
accessorKey: 'failed_at',
meta: { title: 'Reprovado em' },
enableSorting: true,
enableHiding: true,
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
},
{
accessorKey: 'canceled_at',
meta: { title: 'Cancelado em' },
enableSorting: true,
enableHiding: true,
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
}
]

View File

@@ -7,6 +7,22 @@ import {
type LucideIcon
} from 'lucide-react'
// This type is used to define the shape of our data.
// You can use a Zod schema here if you want.
type Course = {
id: string
name: string
}
export type Enrollment = {
id: string
name: string
course: Course
status: string
progress: string
created_at: string
}
export const statuses: Record<
string,
{ icon: LucideIcon; color?: string; label: string }

View File

@@ -3,7 +3,7 @@
import {
DataTableColumnDatetime,
DataTableColumnCurrency,
DataTableColumnHeader
DataTableColumnHeaderSort
} from '@repo/ui/components/data-table'
import { type ColumnDef } from '@tanstack/react-table'
import { HelpCircleIcon } from 'lucide-react'
@@ -11,27 +11,17 @@ import { HelpCircleIcon } from 'lucide-react'
import { cn } from '@repo/ui/lib/utils'
import { Badge } from '@repo/ui/components/ui/badge'
import { labels, methods, statuses } from './data'
import { labels, methods, statuses, type Order } from './data'
// This type is used to define the shape of our data.
// You can use a Zod schema here if you want.
export type Order = {
id: string
total: number
status: 'PENDING' | 'PAID' | 'DECLINED' | 'EXPIRED' | 'REFUNDED' | 'CANCELED'
payment_method: 'PIX' | 'CREDIT_CARD' | 'MANUAL' | 'BANK_SLIP'
name: string
}
export type { Order }
export const columns: ColumnDef<Order>[] = [
{
accessorKey: 'payment_method',
header: 'Forma de pag.',
cell: ({ row }) => {
const s = row.getValue('payment_method') as string
const paymentMethod = methods[s] ?? s
return <>{paymentMethod}</>
const paymentMethod = row.getValue('payment_method') as string
return <>{methods[paymentMethod] ?? paymentMethod}</>
}
},
{
@@ -53,35 +43,27 @@ export const columns: ColumnDef<Order>[] = [
{
accessorKey: 'total',
header: 'Valor total',
cell: ({ row, column }) => (
<DataTableColumnCurrency row={row} column={column} />
)
cell: DataTableColumnCurrency
},
{
accessorKey: 'create_date',
enableSorting: true,
meta: { title: 'Comprado em' },
header: ({ column }) => <DataTableColumnHeader column={column} />,
cell: ({ row, column }) => (
<DataTableColumnDatetime row={row} column={column} />
)
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
},
{
accessorKey: 'due_date',
enableSorting: true,
meta: { title: 'Vencimento em' },
header: ({ column }) => <DataTableColumnHeader column={column} />,
cell: ({ row, column }) => (
<DataTableColumnDatetime row={row} column={column} />
)
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
},
{
accessorKey: 'payment_date',
enableSorting: true,
meta: { title: 'Pago em' },
header: ({ column }) => <DataTableColumnHeader column={column} />,
cell: ({ row, column }) => (
<DataTableColumnDatetime row={row} column={column} />
)
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
}
]

View File

@@ -8,6 +8,17 @@ import {
type LucideIcon
} from 'lucide-react'
// This type is used to define the shape of our data.
// You can use a Zod schema here if you want.
export type Order = {
id: string
total: number
status: 'PENDING' | 'PAID' | 'DECLINED' | 'EXPIRED' | 'REFUNDED' | 'CANCELED'
payment_method: 'PIX' | 'CREDIT_CARD' | 'BANK_SLIP' | 'MANUAL'
name: string
email: string
}
export const statuses: Record<
string,
{ icon: LucideIcon; color?: string; label: string }
@@ -22,25 +33,25 @@ export const statuses: Record<
color: 'text-green-400 [&_svg]:text-green-500',
label: 'Pago'
},
REFUNDED: {
icon: RotateCcwIcon,
color: 'text-orange-400 [&_svg]:text-orange-500',
label: 'Estornado'
DECLINED: {
icon: BanIcon,
color: 'text-red-400 [&_svg]:text-red-500',
label: 'Negado'
},
EXPIRED: {
icon: ClockAlertIcon,
color: 'text-orange-400 [&_svg]:text-orange-500',
label: 'Expirado'
},
REFUNDED: {
icon: RotateCcwIcon,
color: 'text-orange-400 [&_svg]:text-orange-500',
label: 'Estornado'
},
CANCELED: {
icon: CircleXIcon,
color: 'text-red-400 [&_svg]:text-red-500',
label: 'Cancelado'
},
DECLINED: {
icon: BanIcon,
color: 'text-red-400 [&_svg]:text-red-500',
label: 'Negado'
}
}
@@ -54,8 +65,8 @@ export const labels: Record<string, string> = {
}
export const methods: Record<string, string> = {
BANK_SLIP: 'Boleto bancário',
MANUAL: 'Depósito bancário',
PIX: 'Pix',
CREDIT_CARD: 'Cartão de crédito',
PIX: 'Pix'
BANK_SLIP: 'Boleto bancário',
MANUAL: 'Depósito bancário'
}

View File

@@ -0,0 +1,8 @@
// This type is used to define the shape of our data.
// You can use a Zod schema here if you want.
export type Org = {
id: string
name: string
email: string
cnpj?: string
}

View File

@@ -0,0 +1,60 @@
'use client'
import { type ColumnDef } from '@tanstack/react-table'
import { Abbr } from '@repo/ui/components/abbr'
import {
DataTableColumnDatetime,
DataTableColumnHeaderSort,
DataTableColumnCpfCnpj
} from '@repo/ui/components/data-table'
import { Avatar, AvatarFallback } from '@repo/ui/components/ui/avatar'
import { initials } from '@repo/ui/lib/utils'
import type { User } from '@repo/ui/routes/users/data'
export type { User }
export const columns: ColumnDef<User>[] = [
{
header: 'Colaborador',
cell: ({ row }) => {
const { name, email } = row.original
return (
<div className="flex gap-2.5 items-center">
<Avatar className="size-10 hidden lg:block">
<AvatarFallback>{initials(name)}</AvatarFallback>
</Avatar>
<ul>
<li className="font-bold">
<Abbr>{name}</Abbr>
</li>
<li className="text-muted-foreground text-sm">
<Abbr>{email}</Abbr>
</li>
</ul>
</div>
)
}
},
{
accessorKey: 'cpf',
header: 'CPF',
cell: DataTableColumnCpfCnpj
},
{
accessorKey: 'createDate',
enableSorting: true,
meta: { title: 'Cadastrado em' },
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
},
{
accessorKey: 'lastLogin',
enableSorting: true,
meta: { title: 'Último acesso' },
header: DataTableColumnHeaderSort,
cell: DataTableColumnDatetime
}
]

View File

@@ -0,0 +1,18 @@
// This type is used to define the shape of our data.
// You can use a Zod schema here if you want.
export type User = {
id: string
name: string
email: string
cpf?: string
cnpj?: string
}
export const headers = {
id: 'ID',
name: 'Nome',
email: 'Email',
cpf: 'CPF',
createDate: 'Cadastrado em',
lastLogin: 'Último acesso'
}