diff --git a/src/packages/administrativo/components/TImovel/TImovelColumns.tsx b/src/packages/administrativo/components/TImovel/TImovelColumns.tsx deleted file mode 100644 index 63f6d38..0000000 --- a/src/packages/administrativo/components/TImovel/TImovelColumns.tsx +++ /dev/null @@ -1,126 +0,0 @@ -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[] { - 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 ( -
- - {GetCapitalize(imovel.cidade)}/{imovel.uf} - - {GetCapitalize(imovel.gtbb_descricao)} -
- ); - }, - 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 ( - - - - - - - onEdit(imovel, true)}> - - Editar - - - onDelete(imovel, true)} - > - - Remover - - - - - ); - }, - enableSorting: false, - enableHiding: false, - }, - ]; -} diff --git a/src/packages/administrativo/components/TImovel/TImovelForm.tsx b/src/packages/administrativo/components/TImovel/TImovelForm.tsx deleted file mode 100644 index 68dec33..0000000 --- a/src/packages/administrativo/components/TImovel/TImovelForm.tsx +++ /dev/null @@ -1,385 +0,0 @@ -'use client'; - -import React, { useEffect } from 'react'; - -import { Button } from '@/components/ui/button'; -import { - Dialog, - DialogClose, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, -} from '@/components/ui/dialog'; -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Input } from '@/components/ui/input'; - -import LoadingButton from '@/shared/components/loadingButton/LoadingButton'; -import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; -import { CheckIcon, ChevronsUpDownIcon, HouseIcon, IdCardIcon } from 'lucide-react'; -import { Select, SelectContent, SelectItem, SelectTrigger } from '@/components/ui/select'; -import { ImovelTipoRegistro } from '@/shared/enums/ImovelTipoRegistro'; -import { ImovelTipoClasseEnum } from '@/shared/enums/ImovelTipoClasseEnum'; -import { ResetFormIfData } from '@/shared/actions/form/ResetFormIfData'; -import { useGTBBairroReadHook } from '../../../../app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroReadHook'; -import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; -import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command'; -import { cn } from '@/lib/utils'; -import GetCapitalize from '@/shared/actions/text/GetCapitalize'; -import { TImovelFormInterface } from '../../interfaces/TImovel/TImovelFormInterface'; -import { useTImovelFormHook } from '../../hooks/TImovel/useTImovelFormHook'; -import TImovelUnidadeUrbanoPage from '../TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoPage'; -import TImovelUnidadeRuralPage from '../TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralPage'; -import { parseNumberInput } from '@/shared/actions/form/parseNumberInput'; - -export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoading, tipoClasse }: TImovelFormInterface) { - - const { gTBBairro, fetchGTBBairro } = useGTBBairroReadHook(); - - // Inicializa o react-hook-form com schema zod - const form = useTImovelFormHook(); - - // Atualiza o formulário quando recebe dados para edição - useEffect(() => { - - // Se existir dados, reseta o formulário com os mesmos - ResetFormIfData(form, data); - - // Função sincrona para carregamento de dados - async function loadData() { - - // Busca os bairros - await fetchGTBBairro(); - - } - - // Executa a função - loadData(); - - }, [data, form]); - - return ( - { - if (!open) onClose(null, false); - }} - > - - - - Imóvel Urbano - - - Cadastro de imóvel urbano - - -
- - {/* Tabs */} - - - - - Dados do Imóvel - - - - Unidades - - - {/* Dados do Imóvel */} - -
- {/* UF */} -
- ( - - UF - - - - - - )} - /> -
- {/* CEP */} -
- ( - - CEP - - - - - - )} - /> -
- {/* Cidade */} -
- ( - - Cidade - - - - - - )} - /> -
- {/* Bairro */} -
- { - const [open, setOpen] = React.useState(false); - return ( - - Bairro - - - - - - - - - - - Nenhum resultado encontrado. - - {gTBBairro?.map((item) => ( - { - field.onChange(Number(item.tb_bairro_id)); - setOpen(false); - }} - > - - {GetCapitalize(item.descricao)} - - ))} - - - - - - - - ); - }} - /> -
- {/* Cartório */} -
- ( - - Cartório - - - - - - )} - /> -
- {/* CNS */} -
- ( - - CNS - - field.onChange(parseNumberInput(e))} /> - - - - )} - /> -
- {/* Livro */} -
- ( - - Livro - - - - - - )} - /> -
- {/* Tipo Registro */} -
- ( - - Tipo Registro - - - - - - )} - /> -
- {/* Número */} -
- ( - - Número - - - - - - )} - /> -
- {/* Número Letra */} -
- ( - - Número Letra - - - - - - )} - /> -
- {/* Tipo Registro */} -
- ( - - Tipo Classe - - - - - - )} - /> -
-
-
- {/* Unidades */} - - {/* Conteúdo das unidades */} - {tipoClasse === 1 ? : null} - {/* Conteúdo das unidades */} - {tipoClasse === 3 ? : null} - -
- {/* Rodapé do Dialog */} - - - - - - - {/* Campo oculto */} - -
- -
-
- ); -} \ No newline at end of file diff --git a/src/packages/administrativo/components/TImovel/TImovelIndex.tsx b/src/packages/administrativo/components/TImovel/TImovelIndex.tsx deleted file mode 100644 index be55ec5..0000000 --- a/src/packages/administrativo/components/TImovel/TImovelIndex.tsx +++ /dev/null @@ -1,170 +0,0 @@ -'use client'; - -import { useEffect, useState, useCallback } from 'react'; - -import Loading from '@/shared/components/loading/loading'; - -import { useTImovelIndexHook } from '@/packages/administrativo/hooks/TImovel/useTImovelIndexHook'; -import { useTImovelSaveHook } from '@/packages/administrativo/hooks/TImovel/useTImovelSaveHook'; -import { useTImovelDeleteHook } from '@/packages/administrativo/hooks/TImovel/useTImovelDeleteHook'; - -import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog'; -import { useConfirmDialog } from '@/shared/components/confirmDialog/useConfirmDialog'; - -import TImovelInterface from '@/packages/administrativo/interfaces/TImovel/TImovelInterface'; -import Header from '@/shared/components/structure/Header'; -import { TImovelIndexInterface } from '../../interfaces/TImovel/TImovelIndexInterface'; -import TImovelTable from './TImovelTable'; -import TImovelForm from './TImovelForm'; - -export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: TImovelIndexInterface) { - - // Controle de estado do botão - const [buttonIsLoading, setButtonIsLoading] = useState(false); - - // Hooks para leitura e salvamento - const { tImovel, indexTImovel } = useTImovelIndexHook(); - const { saveTImovel } = useTImovelSaveHook(); - const { deleteTImovel } = useTImovelDeleteHook(); - - // Estados - const [selectedAndamento, setSelectedAndamento] = useState(null); - const [isFormOpen, setIsFormOpen] = useState(false); - - // Estado para saber qual item será deletado - const [itemToDelete, setItemToDelete] = useState(null); - - /** - * Hook do modal de confirmação - */ - const { - isOpen: isConfirmOpen, - openDialog: openConfirmDialog, - handleConfirm, - handleCancel, - } = useConfirmDialog(); - - /** - * Abre o formulário no modo de edição ou criação - */ - const handleOpenForm = useCallback((data: TImovelInterface | null) => { - setSelectedAndamento(data); - setIsFormOpen(true); - }, []); - - /** - * Fecha o formulário e limpa o andamento selecionado - */ - const handleCloseForm = useCallback(() => { - setSelectedAndamento(null); - setIsFormOpen(false); - }, []); - - /** - * Salva os dados do formulário - */ - const handleSave = useCallback( - async (formData: TImovelInterface) => { - // Coloca o botão em estado de loading - setButtonIsLoading(true); - - // Aguarda salvar o registro - await saveTImovel(formData); - - // Remove o botão em estado de loading - setButtonIsLoading(false); - - // Atualiza a lista de dados - indexTImovel(); - }, - [saveTImovel, indexTImovel, handleCloseForm], - ); - - /** - * Quando o usuário clica em "remover" na tabela - */ - const handleConfirmDelete = useCallback( - (item: TImovelInterface) => { - // Define o item atual para remoção - setItemToDelete(item); - - // Abre o modal de confirmação - openConfirmDialog(); - }, - [openConfirmDialog], - ); - - /** - * Executa a exclusão de fato quando o usuário confirma - */ - const handleDelete = useCallback(async () => { - // Protege contra null - if (!itemToDelete) return; - - // Executa o Hook de remoção - await deleteTImovel(itemToDelete); - - // Atualiza a lista - await indexTImovel(); - - // Limpa o item selecionado - setItemToDelete(null); - - // Fecha o modal - handleCancel(); - }, [itemToDelete, indexTImovel, handleCancel]); - - /** - * Busca inicial dos dados - */ - useEffect(() => { - indexTImovel(); - }, []); - - /** - * Tela de loading enquanto carrega os dados - */ - if (tImovel?.length == 0) { - return ; - } - - return ( -
- {/* Cabeçalho */} -
{ - handleOpenForm(null); - }} - /> - {/* Tabela de andamentos */} - - {/* Modal de confirmação */} - - {/* Formulário de criação/edição */} - -
- ); -} diff --git a/src/packages/administrativo/components/TImovel/TImovelTable.tsx b/src/packages/administrativo/components/TImovel/TImovelTable.tsx deleted file mode 100644 index 54c767b..0000000 --- a/src/packages/administrativo/components/TImovel/TImovelTable.tsx +++ /dev/null @@ -1,22 +0,0 @@ -'use client'; - -import { DataTable } from '@/shared/components/dataTable/DataTable'; -import TImovelColumns from './TImovelColumns'; -import TImovelTableInterface from '../../interfaces/TImovel/TImovelTabelInterface'; - -/** - * Componente principal da tabela - */ -export default function TImovelTable({ data, onEdit, onDelete }: TImovelTableInterface) { - const columns = TImovelColumns(onEdit, onDelete); - return ( -
- -
- ); -} \ No newline at end of file diff --git a/src/packages/administrativo/interfaces/TImovel/TImovelFormInterface.ts b/src/packages/administrativo/interfaces/TImovel/TImovelFormInterface.ts deleted file mode 100644 index 5431d3e..0000000 --- a/src/packages/administrativo/interfaces/TImovel/TImovelFormInterface.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { TImovelFormValues } from "../../schemas/TImovel/TImovelSchema"; - -export interface TImovelFormInterface { - isOpen: boolean; - data: TImovelFormValues | null; - onClose: (item: null, isFormStatus: boolean) => void; - onSave: (data: TImovelFormValues) => void; - buttonIsLoading: boolean; - tipoClasse: number; -} \ No newline at end of file diff --git a/src/packages/administrativo/interfaces/TImovel/TImovelIndexInterface.ts b/src/packages/administrativo/interfaces/TImovel/TImovelIndexInterface.ts deleted file mode 100644 index 7dad419..0000000 --- a/src/packages/administrativo/interfaces/TImovel/TImovelIndexInterface.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface TImovelIndexInterface { - pageTitle: string, - pageDescription: string, - tipoClasse: number -} \ No newline at end of file diff --git a/src/packages/administrativo/interfaces/TImovel/TImovelInterface.ts b/src/packages/administrativo/interfaces/TImovel/TImovelInterface.ts deleted file mode 100644 index 56bad16..0000000 --- a/src/packages/administrativo/interfaces/TImovel/TImovelInterface.ts +++ /dev/null @@ -1,16 +0,0 @@ -export default interface TImovelInterface { - imovel_id?: number, - tipo_classe?: string, - tipo_registro?: string, - data_registro?: string, - numero?: number, - numero_letra?: string, - cidade?: string, - cep?: string, - uf?: string, - tb_bairro_id?: number, - cartorio?: string, - livro?: string, - cns?: number, - gtbb_descricao?: string, -} \ No newline at end of file diff --git a/src/packages/administrativo/interfaces/TImovel/TImovelTabelInterface.ts b/src/packages/administrativo/interfaces/TImovel/TImovelTabelInterface.ts deleted file mode 100644 index a9185c6..0000000 --- a/src/packages/administrativo/interfaces/TImovel/TImovelTabelInterface.ts +++ /dev/null @@ -1,7 +0,0 @@ -import TImovelInterface from "./TImovelInterface"; - -export default interface TImovelTableInterface { - data?: TImovelInterface[]; - onEdit: (item: TImovelInterface, isEditingFormStatus: boolean) => void; - onDelete: (item: TImovelInterface, isEditingFormStatus: boolean) => void; -} \ No newline at end of file diff --git a/src/packages/administrativo/schemas/TImovel/TImovelSchema.ts b/src/packages/administrativo/schemas/TImovel/TImovelSchema.ts deleted file mode 100644 index f7653b2..0000000 --- a/src/packages/administrativo/schemas/TImovel/TImovelSchema.ts +++ /dev/null @@ -1,19 +0,0 @@ -import z from "zod"; - -export const TImovelSchema = z.object({ - imovel_id: z.number().optional(), - tipo_classe: z.string().optional(), - tipo_registro: z.string().optional(), - data_registro: z.string().optional(), - numero: z.number().optional(), - numero_letra: z.string().optional(), - cidade: z.string().optional(), - cep: z.string().optional(), - uf: z.string().optional(), - tb_bairro_id: z.number().optional(), - cartorio: z.string().optional(), - livro: z.string().optional(), - cns: z.number().optional(), -}); - -export type TImovelFormValues = z.infer; \ No newline at end of file