From 1fcc5e442da3a3c978b68cba9face8b4e161a070 Mon Sep 17 00:00:00 2001 From: keven Date: Thu, 2 Oct 2025 15:30:15 -0300 Subject: [PATCH] [MVPTN-87] feat(CRUD): Ajustes diversos no crud de imovel e unidade --- src/actions/form/ResetFormIfData.ts | 15 + src/actions/form/parseNumberInput.ts | 6 + .../_components/g_tb_bairro/GTBBairroForm.tsx | 13 +- .../_components/t_imovel/TImovelForm.tsx | 488 +++++++------ .../_components/t_imovel/TImovelFormProps.ts | 7 + .../_components/t_imovel/TImovelTable.tsx | 2 +- .../TImovelUnidadeColumns.tsx | 25 +- .../t_imovel_unidade/TImovelUnidadeForm.tsx | 687 ++++++++++++------ .../TImovelUnidadeFormProps.ts | 9 + .../t_imovel_unidade/TImovelUnidadeTable.tsx | 4 +- .../_components/t_pessoa/TPessoaForm.tsx | 5 - .../_data/TImovel/TImovelSaveData.ts | 5 + .../_hooks/t_imovel/useTImovelIndexHook.ts | 4 +- .../useTImovelUnidadeIndexHook.ts | 3 +- .../useTImovelUnidadeSaveHook.ts | 1 + .../_interfaces/TImovelUnidadeInterface.ts | 2 +- .../cadastros/_schemas/TImovelSchema.ts | 30 +- .../_schemas/TImovelUnidadeSchema.ts | 7 +- src/app/_components/dataTable/dataTable.tsx | 4 + src/enums/ImovelConstrucaoEnum.ts | 5 + src/enums/ImovelTipoClasseEnum.ts | 4 + src/enums/ImovelTipoEnum.ts | 22 + src/enums/ImovelTipoRegistro.ts | 3 +- 23 files changed, 886 insertions(+), 465 deletions(-) create mode 100644 src/actions/form/ResetFormIfData.ts create mode 100644 src/actions/form/parseNumberInput.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelFormProps.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeFormProps.ts create mode 100644 src/enums/ImovelConstrucaoEnum.ts create mode 100644 src/enums/ImovelTipoClasseEnum.ts create mode 100644 src/enums/ImovelTipoEnum.ts diff --git a/src/actions/form/ResetFormIfData.ts b/src/actions/form/ResetFormIfData.ts new file mode 100644 index 0000000..09fa8df --- /dev/null +++ b/src/actions/form/ResetFormIfData.ts @@ -0,0 +1,15 @@ +import { UseFormReturn, FieldValues } from "react-hook-form"; + +/** + * Reseta o formulário com os dados recebidos (se existirem) + * @param form - Instância do react-hook-form + * @param data - Dados para popular o formulário + */ +export function ResetFormIfData( + form: UseFormReturn, + data: T | null +) { + if (data) { + form.reset(data); + } +} diff --git a/src/actions/form/parseNumberInput.ts b/src/actions/form/parseNumberInput.ts new file mode 100644 index 0000000..154b96f --- /dev/null +++ b/src/actions/form/parseNumberInput.ts @@ -0,0 +1,6 @@ +/** + * Converte o valor do input para número, enviando undefined se estiver vazio + */ +export function parseNumberInput(e: React.ChangeEvent): number | undefined { + return e.target.value ? Number(e.target.value) : undefined; +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx index 2ef3fa9..d88f690 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx @@ -1,7 +1,7 @@ 'use client'; import z from 'zod'; -import { useEffect, useState } from 'react'; +import { useEffect } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; @@ -73,10 +73,13 @@ export default function GTBBairroForm({ > - Bairro - Crie ou edite um bairro + + Bairro + + + Crie ou edite um bairro + -
{/* Descrição */} @@ -93,7 +96,6 @@ export default function GTBBairroForm({ )} /> - {/* Situação */} )} /> - {/* Rodapé do Dialog */} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelForm.tsx index 3917493..e3774ba 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelForm.tsx @@ -1,12 +1,10 @@ 'use client'; -import z from 'zod'; -import { useEffect } from 'react'; -import { useForm, Controller } from 'react-hook-form'; +import React, { useEffect } from 'react'; +import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { Button } from '@/components/ui/button'; -import { Checkbox } from '@/components/ui/checkbox'; import { Dialog, DialogClose, @@ -25,35 +23,50 @@ import { FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; -import { Label } from '@/components/ui/label'; -import { TImovelSchema } from '../../_schemas/TImovelSchema'; +import { TImovelFormValues, TImovelSchema } from '../../_schemas/TImovelSchema'; import LoadingButton from '@/app/_components/loadingButton/LoadingButton'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; -import { HouseIcon, IdCardIcon, UserIcon } from 'lucide-react'; -import { Select } from '@/components/ui/select'; +import { CheckIcon, ChevronsUpDownIcon, HouseIcon, IdCardIcon } from 'lucide-react'; +import { Select, SelectContent, SelectItem, SelectTrigger } from '@/components/ui/select'; import TImovelUnidadePage from '../t_imovel_unidade/TImovelUnidadePage'; +import { ImovelTipoRegistro } from '@/enums/ImovelTipoRegistro'; +import { ImovelTipoClasseEnum } from '@/enums/ImovelTipoClasseEnum'; +import { ResetFormIfData } from '@/actions/form/ResetFormIfData'; +import { TImovelFormProps } from './TImovelFormProps'; +import { useGTBBairroReadHook } from '../../_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 '@/actions/text/GetCapitalize'; -type FormValues = z.infer; +export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TImovelFormProps) { -interface Props { - isOpen: boolean; - data: FormValues | null; - onClose: (item: null, isFormStatus: boolean) => void; - onSave: (data: FormValues) => void; - buttonIsLoading: boolean; -} + const { gTBBairro, fetchGTBBairro } = useGTBBairroReadHook(); -export default function TCensecForm({ isOpen, data, onClose, onSave, buttonIsLoading }: Props) { // Inicializa o react-hook-form com schema zod - const form = useForm({ + const form = useForm({ resolver: zodResolver(TImovelSchema), defaultValues: {}, }); // Atualiza o formulário quando recebe dados para edição useEffect(() => { - if (data) form.reset(data); + + // 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 ( @@ -77,200 +90,270 @@ export default function TCensecForm({ isOpen, data, onClose, onSave, buttonIsLoa {/* Tabs */} - - + + Dados do Imóvel - + Unidades {/* Dados do Imóvel */} -
- {/* Tipo Classe */} - ( - - Tipo Classe - - - - - - )} - /> - - {/* Tipo Registro */} - ( - - Tipo Registro - - - - - - )} - /> - - {/* Número */} - ( - - Número - - - - - - )} - /> - - {/* Número Letra */} - ( - - Número Letra - - - - - - )} - /> - - {/* Cidade */} - ( - - Cidade - - - - - - )} - /> - +
{/* UF */} - ( - - UF - - - - - - )} - /> - - {/* Bairro */} - ( - - Bairro - - - - - - )} - /> - +
+ ( + + UF + + + + + + )} + /> +
{/* CEP */} - ( - - 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 - - - - - - )} - /> - - {/* Livro */} - ( - - Livro - - - - - - )} - /> - +
+ ( + + Cartório + + + + + + )} + /> +
{/* CNS */} - ( - - CNS - - - - - - )} - /> - - {/* GTB Descrição */} - ( - - GTB Descrição - - - - - - )} - /> +
+ ( + + CNS + + + + + + )} + /> +
+ {/* Livro */} +
+ ( + + Livro + + + + + + )} + /> +
+ {/* Tipo Registro */} +
+ ( + + Tipo Registro + + + + + + )} + /> +
+ {/* Número */} +
+ ( + + Número + + + + + + )} + /> +
+ {/* Número Letra */} +
+ ( + + Número Letra + + + + + + )} + /> +
+ {/* Tipo Registro */} +
+ ( + + Tipo Classe + + + + + + )} + /> +
{/* Unidades */} @@ -286,7 +369,6 @@ export default function TCensecForm({ isOpen, data, onClose, onSave, buttonIsLoa Cancelar - ); -} +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelFormProps.ts b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelFormProps.ts new file mode 100644 index 0000000..23a41b1 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelFormProps.ts @@ -0,0 +1,7 @@ +export interface TImovelFormProps { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; + buttonIsLoading: boolean; +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelTable.tsx index 77f04a0..45f6696 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelTable.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel/TImovelTable.tsx @@ -5,7 +5,7 @@ import TImovelColumns from './TImovelColumns'; import TImovelInterface from '../../_interfaces/TImovelInterface'; interface TImovelTableProps { - data: TImovelInterface[]; + data?: TImovelInterface[]; onEdit: (item: TImovelInterface, isEditingFormStatus: boolean) => void; onDelete: (item: TImovelInterface, isEditingFormStatus: boolean) => void; } diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeColumns.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeColumns.tsx index fa594fa..ac1657e 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeColumns.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeColumns.tsx @@ -26,7 +26,30 @@ export default function TImovelUnidadeColumns( accessorKey: "imovel_unidade_id", header: ({ column }) => SortableHeader("#", column), cell: ({ row }) => Number(row.getValue("imovel_unidade_id")), - enableSorting: false, + }, + // Número da Unidade + { + accessorKey: "numero_unidade", + header: ({ column }) => SortableHeader("Número da Unidade", column), + cell: ({ row }) => row.getValue("numero_unidade"), + }, + // Quadra + { + accessorKey: "quadra", + header: ({ column }) => SortableHeader("Quadra", column), + cell: ({ row }) => row.getValue("quadra"), + }, + // Area + { + accessorKey: "area", + header: ({ column }) => SortableHeader("Área", column), + cell: ({ row }) => row.getValue("area"), + }, + // Logradouros + { + accessorKey: "logradouro", + header: ({ column }) => SortableHeader("Logradouro", column), + cell: ({ row }) => row.getValue("logradouro"), }, // Ações { diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeForm.tsx index 3083ed9..1648914 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeForm.tsx @@ -1,12 +1,10 @@ 'use client'; -import z from 'zod'; -import { useEffect } from 'react'; -import { useForm, Controller } from 'react-hook-form'; +import React, { useEffect } from 'react'; +import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { Button } from '@/components/ui/button'; -import { Checkbox } from '@/components/ui/checkbox'; import { Dialog, DialogClose, @@ -25,34 +23,50 @@ import { FormMessage, } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; -import { Label } from '@/components/ui/label'; -import { TImovelSchema } from '../../_schemas/TImovelSchema'; import LoadingButton from '@/app/_components/loadingButton/LoadingButton'; -import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; -import { HouseIcon, IdCardIcon, UserIcon } from 'lucide-react'; -import { Select } from '@/components/ui/select'; +import { TImovelUnidadeFormValues, TImovelUnidadeSchema } from '../../_schemas/TImovelUnidadeSchema'; +import TImovelUnidadeProps from './TImovelUnidadeFormProps'; +import { useGTBTipoLogradouroReadHook } from '../../_hooks/g_tb_tipologradouro/useGTBTipoLogradouroReadHook'; +import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; +import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react'; +import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command'; +import { cn } from '@/lib/utils'; +import GetCapitalize from '@/actions/text/GetCapitalize'; +import { ResetFormIfData } from '@/actions/form/ResetFormIfData'; +import { parseNumberInput } from '@/actions/form/parseNumberInput'; +import { ImovelTipoEnum } from '@/enums/ImovelTipoEnum'; +import { ImovelConstrucaoEnum } from '@/enums/ImovelConstrucaoEnum'; -type FormValues = z.infer; +export default function TImovelUnidadeForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TImovelUnidadeProps) { -interface Props { - isOpen: boolean; - data: FormValues | null; - onClose: (item: null, isFormStatus: boolean) => void; - onSave: (data: FormValues) => void; - buttonIsLoading: boolean; -} + const { gTBTipoLogradouro, fetchGTBTipoLogradouro } = useGTBTipoLogradouroReadHook(); -export default function TImovelUnidadeForm({ isOpen, data, onClose, onSave, buttonIsLoading }: Props) { // Inicializa o react-hook-form com schema zod - const form = useForm({ - resolver: zodResolver(TImovelSchema), - defaultValues: {}, + const form = useForm({ + resolver: zodResolver(TImovelUnidadeSchema), + defaultValues: { + imovel_id: 1, + }, }); // Atualiza o formulário quando recebe dados para edição useEffect(() => { - if (data) form.reset(data); + + // Se existir dados, reseta o formulário com os mesmos + ResetFormIfData(form, data); + + // Carregamento de dados iniciais + async function loadData() { + + // Carrega o tipo de logradouro + await fetchGTBTipoLogradouro(); + + } + + // Executa a função + loadData(); + }, [data, form]); return ( @@ -62,224 +76,450 @@ export default function TImovelUnidadeForm({ isOpen, data, onClose, onSave, butt if (!open) onClose(null, false); }} > - + - Imóvel Urbano + Unidades do Imóvel - Cadastro de imóvel urbano + Cadastro de unidades do imóvel - {/* Tabs */} - - - - - Dados do Imóvel - - - - Unidades - - - - {/* Dados do Imóvel */} - -
- {/* Tipo Classe */} - ( +
+ {/* Quadra */} +
+ ( + + Quadra + + + + + + )} + /> +
+ {/* Lote */} +
+ ( + + Lote + + + + + + )} + /> +
+ {/* Area */} +
+ ( + + Área(m2) + + field.onChange(parseNumberInput(e))} + /> + + + + )} + /> +
+ {/* Inscrição Municipal */} +
+ ( + + Inscrição Municipal + + + + + + )} + /> +
+ {/* Tipo Logradouro */} +
+ { + const [open, setOpen] = React.useState(false); + return ( - Tipo Classe - - - + Tipo logradouro + + + + + + + + + + + Nenhum resultado encontrado. + + {gTBTipoLogradouro?.map((item) => ( + { + field.onChange(Number(item.tb_tipologradouro_id)); + setOpen(false); + }} + > + + {GetCapitalize(item.descricao)} + + ))} + + + + + - )} - /> - - {/* Tipo Registro */} - ( + ); + }} + /> +
+ {/* Logradouro */} +
+ ( + + Logradouro + + + + + + )} + /> +
+ {/* Tipo Imóvel */} +
+ { + const [open, setOpen] = React.useState(false); + // transforma o objeto em um array [{value, label}] + const options = Object.entries(ImovelTipoEnum).map(([id, label]) => ({ + value: Number(id), + label, + })); + return ( - Tipo Registro - - - + Tipo Imóvel + + + + + + + + + + + Nenhum resultado encontrado. + + {options.map((item) => ( + { + field.onChange(item.value); // salva o número (id) + setOpen(false); + }} + > + + {item.label} + + ))} + + + + + - )} - /> - - {/* Número */} - ( + ); + }} + /> +
+ {/* Construção */} +
+ { + const [open, setOpen] = React.useState(false); + const options = Object.entries(ImovelConstrucaoEnum).map(([id, label]) => ({ + value: Number(id), + label, + })); + return ( - Número - - - + Construção + + + + + + + + + + + Nenhum resultado encontrado. + + {options.map((item) => ( + { + field.onChange(item.value); + setOpen(false); + }} + > + + {item.label} + + ))} + + + + + - )} - /> - - {/* Número Letra */} - ( - - Número Letra - - - - - - )} - /> - - {/* Cidade */} - ( - - Cidade - - - - - - )} - /> - - {/* UF */} - ( - - UF - - - - - - )} - /> - - {/* Bairro */} - ( - - Bairro - - - - - - )} - /> - - {/* CEP */} - ( - - CEP - - - - - - )} - /> - - {/* Cartório */} - ( - - Cartório - - - - - - )} - /> - - {/* Livro */} - ( - - Livro - - - - - - )} - /> - - {/* CNS */} - ( - - CNS - - - - - - )} - /> - - {/* GTB Descrição */} - ( - - GTB Descrição - - - - - - )} - /> -
- - - {/* Unidades */} - - {/* Conteúdo das unidades */} - - + ); + }} + /> +
+ {/* Iptu */} +
+ ( + + IPTU + + + + + + )} + /> +
+ {/* Unidade */} +
+ ( + + Unidade + + + + + + )} + /> +
+ {/* Torre */} +
+ ( + + Torre + + + + + + )} + /> +
+ {/* Condominio */} +
+ ( + + Condominio + + + + + + )} + /> +
+ {/* Loteamento */} +
+ ( + + Loteamento + + + + + + )} + /> +
+ {/* CNM */} +
+ ( + + CNM + + + + + + )} + /> +
+ {/* CIB */} +
+ ( + + CIB + + + + + + )} + /> +
+ {/* Numero da Edificação */} +
+ ( + + Número da Edificação + + + + + + )} + /> +
+ {/* Complemento */} +
+ ( + + Complemento + + + + + + )} + /> +
+
{/* Rodapé do Dialog */} @@ -287,7 +527,6 @@ export default function TImovelUnidadeForm({ isOpen, data, onClose, onSave, butt Cancelar - - {/* Campo oculto */} + diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeFormProps.ts b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeFormProps.ts new file mode 100644 index 0000000..032744e --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeFormProps.ts @@ -0,0 +1,9 @@ +import { TImovelUnidadeFormValues } from "../../_schemas/TImovelUnidadeSchema"; + +export default interface TImovelUnidadeProps { + isOpen: boolean; + data: TImovelUnidadeFormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: TImovelUnidadeFormValues) => void; + buttonIsLoading: boolean; +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeTable.tsx index 344dcdf..6c49ecf 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeTable.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_imovel_unidade/TImovelUnidadeTable.tsx @@ -20,8 +20,8 @@ export default function TImovelUnidadeTable({ data, onEdit, onDelete }: TImovelU
); diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_pessoa/TPessoaForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_pessoa/TPessoaForm.tsx index 17c3580..8855a6e 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_pessoa/TPessoaForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_pessoa/TPessoaForm.tsx @@ -716,7 +716,6 @@ export default function TCensecForm({ )} /> - {/* Número */}
- {/* CPF */}
- {/* Órgão Emissor */}
- {/* UF */}
- {/* Data de Expedição */}
{ const { setResponse } = useResponse(); - const [tImovel, setTImovel] = useState< - TImovelInterface[] | null - >(null); + const [tImovel, setTImovel] = useState(); const indexTImovel = async () => { const response = await TImovelIndexData(); diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_imovel_unidade/useTImovelUnidadeIndexHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_imovel_unidade/useTImovelUnidadeIndexHook.ts index 83e6f52..1a38494 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_imovel_unidade/useTImovelUnidadeIndexHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_imovel_unidade/useTImovelUnidadeIndexHook.ts @@ -9,8 +9,7 @@ export const useTImovelUnidadeIndexHook = () => { const { setResponse } = useResponse(); const [tImovelUnidade, setTImovelUnidade] = useState< - TImovelUnidadeInterface[] | null - >(null); + TImovelUnidadeInterface[]>(); const indexTImovelUnidade = async () => { const response = await TImovelUnidadeIndexData(); diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_imovel_unidade/useTImovelUnidadeSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_imovel_unidade/useTImovelUnidadeSaveHook.ts index c129b16..efa5c5d 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_imovel_unidade/useTImovelUnidadeSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_imovel_unidade/useTImovelUnidadeSaveHook.ts @@ -30,4 +30,5 @@ export const useTImovelUnidadeSaveHook = () => { }; return { tImovelUnidade, saveTImovelUnidade }; + }; diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TImovelUnidadeInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TImovelUnidadeInterface.ts index 83a52d1..6aaa723 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TImovelUnidadeInterface.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TImovelUnidadeInterface.ts @@ -11,7 +11,7 @@ export default interface TImovelUnidadeInterface { caracteristica?: string; reserva_florestal?: string; geo_referenciamento?: string; - logradouro?: string; + logradouro: string; tb_tipologradouro_id?: number; selecionado?: string; complemento?: string; diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TImovelSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TImovelSchema.ts index 450a09f..f7653b2 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/TImovelSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TImovelSchema.ts @@ -1,17 +1,19 @@ 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, -}); \ No newline at end of file + 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 diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TImovelUnidadeSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TImovelUnidadeSchema.ts index 99fe817..20f00a9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/TImovelUnidadeSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TImovelUnidadeSchema.ts @@ -13,7 +13,7 @@ export const TImovelUnidadeSchema = z.object({ caracteristica: z.string().optional(), reserva_florestal: z.string().optional(), geo_referenciamento: z.string().optional(), - logradouro: z.string().optional(), + logradouro: z.string().min(1, 'O campo deve ser preenchido').max(90, 'O campo não deve exceder 90 caracteres'), tb_tipologradouro_id: z.number().optional(), selecionado: z.string().optional(), complemento: z.string().optional(), @@ -36,4 +36,7 @@ export const TImovelUnidadeSchema = z.object({ inscricao_municipal: z.string().optional(), cib: z.string().optional(), area_construida: z.number().optional(), -}); \ No newline at end of file +}); + +// Exportar o tipo inferido junto (opcional) +export type TImovelUnidadeFormValues = z.infer; \ No newline at end of file diff --git a/src/app/_components/dataTable/dataTable.tsx b/src/app/_components/dataTable/dataTable.tsx index 39f7549..e665f31 100644 --- a/src/app/_components/dataTable/dataTable.tsx +++ b/src/app/_components/dataTable/dataTable.tsx @@ -216,6 +216,7 @@ export function DataTable({ onClick={() => table.setPageIndex(0)} disabled={!table.getCanPreviousPage()} aria-label="Primeira página" + className='cursor-pointer' > Primeira @@ -225,6 +226,7 @@ export function DataTable({ onClick={() => table.previousPage()} disabled={!table.getCanPreviousPage()} aria-label="Página anterior" + className='cursor-pointer' > Anterior @@ -235,6 +237,7 @@ export function DataTable({ onClick={() => table.nextPage()} disabled={!table.getCanNextPage()} aria-label="Próxima página" + className='cursor-pointer' > Próxima @@ -245,6 +248,7 @@ export function DataTable({ onClick={() => table.setPageIndex(table.getPageCount() - 1)} disabled={!table.getCanNextPage()} aria-label="Última página" + className='cursor-pointer' > Última diff --git a/src/enums/ImovelConstrucaoEnum.ts b/src/enums/ImovelConstrucaoEnum.ts new file mode 100644 index 0000000..a28f354 --- /dev/null +++ b/src/enums/ImovelConstrucaoEnum.ts @@ -0,0 +1,5 @@ +export const ImovelConstrucaoEnum: { [key: number]: string } = { + 0: 'Construção averbada', + 1: 'Em construção', + 2: 'Não se aplica', +}; \ No newline at end of file diff --git a/src/enums/ImovelTipoClasseEnum.ts b/src/enums/ImovelTipoClasseEnum.ts new file mode 100644 index 0000000..0f4a3dc --- /dev/null +++ b/src/enums/ImovelTipoClasseEnum.ts @@ -0,0 +1,4 @@ +export const ImovelTipoClasseEnum: { [key: number]: string } = { + 1: 'Urbano', + 3: 'Rural', +}; \ No newline at end of file diff --git a/src/enums/ImovelTipoEnum.ts b/src/enums/ImovelTipoEnum.ts new file mode 100644 index 0000000..edebfa5 --- /dev/null +++ b/src/enums/ImovelTipoEnum.ts @@ -0,0 +1,22 @@ +export const ImovelTipoEnum: { [key: number]: string } = { + 15: 'Loja', + 31: 'Galpão', + 65: 'Apartamento', + 67: 'Casa', + 69: 'Fazenda / Sítio / Chácara', + 71: 'Terreno / Fração', + 89: 'Outros', + 90: 'Sala', + 91: 'Conjunto de salas', + 92: 'Sobreloja', + 17: 'Sala / Conjunto', + 33: 'Prédio Comercial', + 35: 'Prédio Residencial', + 73: 'Sala ou Loja', + 85: 'Construções', + 87: 'Desmembramento', + 93: 'Vaga de Garagem', + 94: 'Laje', + 95: 'Estacionamento', + 96: 'Barraco' +}; \ No newline at end of file diff --git a/src/enums/ImovelTipoRegistro.ts b/src/enums/ImovelTipoRegistro.ts index 2d91f88..5476b98 100644 --- a/src/enums/ImovelTipoRegistro.ts +++ b/src/enums/ImovelTipoRegistro.ts @@ -1,4 +1,5 @@ export enum ImovelTipoRegistro { M = 'Matrícula', - T = 'Transcrição' + T = 'Transcrição', + I = 'Inscrição', } \ No newline at end of file