add datetable cnfcnpj
This commit is contained in:
@@ -12,7 +12,12 @@ import { NavLink, useParams } from 'react-router'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { Abbr } from '@repo/ui/components/abbr'
|
||||
import { useDataTable } from '@repo/ui/components/data-table'
|
||||
import {
|
||||
useDataTable,
|
||||
DataTableColumnDatetime,
|
||||
DataTableColumnHeader,
|
||||
DataTableColumnCpfCnpj
|
||||
} from '@repo/ui/components/data-table'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
@@ -26,6 +31,7 @@ import {
|
||||
} from '@repo/ui/components/ui/alert-dialog'
|
||||
import { Avatar, AvatarFallback } from '@repo/ui/components/ui/avatar'
|
||||
import { Button } from '@repo/ui/components/ui/button'
|
||||
import { Checkbox } from '@repo/ui/components/ui/checkbox'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -45,15 +51,30 @@ export type User = {
|
||||
cnpj?: string
|
||||
}
|
||||
|
||||
const formatted = new Intl.DateTimeFormat('pt-BR', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit'
|
||||
})
|
||||
|
||||
export const columns: ColumnDef<User>[] = [
|
||||
{
|
||||
id: 'select',
|
||||
header: ({ table }) => (
|
||||
<Checkbox
|
||||
checked={
|
||||
table.getIsAllPageRowsSelected() ||
|
||||
(table.getIsSomePageRowsSelected() && 'indeterminate')
|
||||
}
|
||||
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
|
||||
className="cursor-pointer"
|
||||
aria-label="Selecionar tudo"
|
||||
/>
|
||||
),
|
||||
cell: ({ row }) => (
|
||||
<Checkbox
|
||||
checked={row.getIsSelected()}
|
||||
disabled={!row.getCanSelect()}
|
||||
onCheckedChange={(value) => row.toggleSelected(!!value)}
|
||||
className="cursor-pointer"
|
||||
aria-label="Selecionar linha"
|
||||
/>
|
||||
)
|
||||
},
|
||||
{
|
||||
header: 'Colaborador',
|
||||
cell: ({ row }) => {
|
||||
@@ -78,38 +99,29 @@ export const columns: ColumnDef<User>[] = [
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: 'cpf',
|
||||
header: 'CPF',
|
||||
cell: ({ row }) => {
|
||||
const { cpf } = row.original
|
||||
|
||||
if (cpf) {
|
||||
return <>{formatCPF(cpf)}</>
|
||||
}
|
||||
|
||||
return <></>
|
||||
}
|
||||
cell: ({ row, column }) => (
|
||||
<DataTableColumnCpfCnpj row={row} column={column} />
|
||||
)
|
||||
},
|
||||
{
|
||||
header: 'Último accesso',
|
||||
cell: ({ row }) => {
|
||||
// Post-migration: rename `lastLogin` to `last_login`
|
||||
if (row.original?.lastLogin) {
|
||||
const lastLogin = new Date(row.original.lastLogin)
|
||||
return formatted.format(lastLogin)
|
||||
}
|
||||
|
||||
return <></>
|
||||
}
|
||||
accessorKey: 'createDate',
|
||||
enableSorting: true,
|
||||
meta: { title: 'Cadastrado em' },
|
||||
header: ({ column }) => <DataTableColumnHeader column={column} />,
|
||||
cell: ({ row, column }) => (
|
||||
<DataTableColumnDatetime row={row} column={column} />
|
||||
)
|
||||
},
|
||||
{
|
||||
header: 'Cadastrado em',
|
||||
meta: {
|
||||
className: 'w-1/12'
|
||||
},
|
||||
cell: ({ row }) => {
|
||||
const created_at = new Date(row.original.createDate)
|
||||
return formatted.format(created_at)
|
||||
}
|
||||
accessorKey: 'lastLogin',
|
||||
enableSorting: true,
|
||||
meta: { title: 'Último acesso' },
|
||||
header: ({ column }) => <DataTableColumnHeader column={column} />,
|
||||
cell: ({ row, column }) => (
|
||||
<DataTableColumnDatetime row={row} column={column} />
|
||||
)
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Route } from './+types/route'
|
||||
import { PlusIcon } from 'lucide-react'
|
||||
import { Suspense } from 'react'
|
||||
import { Await, Link, useSearchParams } from 'react-router'
|
||||
import { MeiliSearchFilterBuilder } from 'meilisearch-helper'
|
||||
|
||||
import { DataTable } from '@repo/ui/components/data-table'
|
||||
import { SearchForm } from '@repo/ui/components/search-form'
|
||||
@@ -27,13 +28,16 @@ export async function loader({ params, context, request }: Route.LoaderArgs) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const { orgid } = params
|
||||
const query = searchParams.get('q') || ''
|
||||
const sort = searchParams.get('sort') || 'createDate:desc'
|
||||
const page = Number(searchParams.get('p')) + 1
|
||||
const hitsPerPage = Number(searchParams.get('perPage')) || 25
|
||||
|
||||
let builder = new MeiliSearchFilterBuilder().where('tenant_id', '=', orgid)
|
||||
|
||||
const users = createSearch({
|
||||
index: 'betaeducacao-prod-users_d2o3r5gmm4it7j',
|
||||
sort: ['createDate:desc', 'create_date:desc'],
|
||||
filter: `tenant_id = ${orgid}`,
|
||||
filter: builder.build(),
|
||||
sort: [sort],
|
||||
query,
|
||||
page,
|
||||
hitsPerPage,
|
||||
@@ -61,7 +65,7 @@ export default function Route({ loaderData: { data } }) {
|
||||
{({ hits, page, hitsPerPage, totalHits }) => {
|
||||
return (
|
||||
<DataTable
|
||||
sort={[{ id: 'created_at', desc: true }]}
|
||||
sort={[{ id: 'createDate', desc: true }]}
|
||||
columns={columns}
|
||||
data={hits as User[]}
|
||||
pageIndex={page - 1}
|
||||
|
||||
Reference in New Issue
Block a user