126 lines
4.7 KiB
TypeScript
126 lines
4.7 KiB
TypeScript
import { ColumnDef } from "@tanstack/react-table";
|
|
import TImovelInterface from "../../interfaces/TImovel/TImovelInterface";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
EllipsisIcon,
|
|
PencilIcon,
|
|
Trash2Icon,
|
|
} from "lucide-react";
|
|
import { FormatDateTime } from "@/shared/actions/dateTime/FormatDateTime";
|
|
import { FormatCEP } from "@/shared/actions/CEP/FormatCEP";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuGroup,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { ImovelTipoRegistro } from "@/shared/enums/ImovelTipoRegistro";
|
|
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
|
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
|
|
|
export default function TImovelColumns(
|
|
onEdit: (item: TImovelInterface, isEditingFormStatus: boolean) => void,
|
|
onDelete: (item: TImovelInterface, isEditingFormStatus: boolean) => void
|
|
): ColumnDef<TImovelInterface>[] {
|
|
return [
|
|
// ID
|
|
{
|
|
accessorKey: "imovel_id",
|
|
header: ({ column }) => SortableHeader("#", column),
|
|
cell: ({ row }) => Number(row.getValue("imovel_id")),
|
|
enableSorting: false,
|
|
},
|
|
|
|
// Tipo Registro
|
|
{
|
|
accessorKey: "tipo_registro",
|
|
header: ({ column }) => SortableHeader("Tipo Registro", column),
|
|
cell: ({ row }) => {
|
|
const value = row.getValue("tipo_registro") as keyof typeof ImovelTipoRegistro;
|
|
return ImovelTipoRegistro[value] ?? value;
|
|
},
|
|
},
|
|
|
|
// Número
|
|
{
|
|
accessorKey: "numero",
|
|
header: ({ column }) => SortableHeader("Número", column),
|
|
cell: ({ row }) => row.getValue("numero"),
|
|
},
|
|
|
|
// UF / Cidade / Bairro
|
|
{
|
|
id: "uf_cidade_bairro",
|
|
accessorFn: (row) => row,
|
|
header: ({ column }) => SortableHeader("Cidade / UF / Bairro", column),
|
|
cell: ({ row }) => {
|
|
const imovel = row.original;
|
|
return (
|
|
<div className="flex flex-col">
|
|
<span className="font-semibold text-gray-900 capitalize">
|
|
{GetCapitalize(imovel.cidade)}/{imovel.uf}
|
|
</span>
|
|
<span className="text-sm text-gray-500">{GetCapitalize(imovel.gtbb_descricao)}</span>
|
|
</div>
|
|
);
|
|
},
|
|
sortingFn: (a, b) =>
|
|
(a.original.cartorio?.toLowerCase() || "").localeCompare(
|
|
b.original.cartorio?.toLowerCase() || ""
|
|
),
|
|
},
|
|
|
|
// CEP
|
|
{
|
|
accessorKey: "cep",
|
|
header: ({ column }) => SortableHeader("CEP", column),
|
|
cell: ({ row }) => FormatCEP(row.getValue("cep")),
|
|
},
|
|
|
|
// Data de Registro
|
|
{
|
|
accessorKey: "data_registro",
|
|
header: ({ column }) => SortableHeader("Cadastro", column),
|
|
cell: ({ row }) => FormatDateTime(row.getValue("data_registro")),
|
|
sortingFn: "datetime",
|
|
},
|
|
|
|
// Ações
|
|
{
|
|
id: "actions",
|
|
header: "Ações",
|
|
cell: ({ row }) => {
|
|
const imovel = row.original;
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" size="icon">
|
|
<EllipsisIcon />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent side="left" align="start">
|
|
<DropdownMenuGroup>
|
|
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
|
<PencilIcon className="mr-2 h-4 w-4" />
|
|
Editar
|
|
</DropdownMenuItem>
|
|
<DropdownMenuSeparator />
|
|
<DropdownMenuItem
|
|
className="text-red-600"
|
|
onSelect={() => onDelete(imovel, true)}
|
|
>
|
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
Remover
|
|
</DropdownMenuItem>
|
|
</DropdownMenuGroup>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
},
|
|
enableSorting: false,
|
|
enableHiding: false,
|
|
},
|
|
];
|
|
}
|