diff --git a/src/packages/administrativo/components/TImovel/TImovelColumns.tsx b/src/packages/administrativo/components/TImovel/TImovelColumns.tsx index 63f6d38..8a54278 100644 --- a/src/packages/administrativo/components/TImovel/TImovelColumns.tsx +++ b/src/packages/administrativo/components/TImovel/TImovelColumns.tsx @@ -67,9 +67,7 @@ export default function TImovelColumns( ); }, sortingFn: (a, b) => - (a.original.cartorio?.toLowerCase() || "").localeCompare( - b.original.cartorio?.toLowerCase() || "" - ), + Number(a.original.numero || 0) - Number(b.original.numero || 0), }, // CEP diff --git a/src/packages/administrativo/components/TImovel/TImovelForm.tsx b/src/packages/administrativo/components/TImovel/TImovelForm.tsx index 5b4d89b..ab3d2c6 100644 --- a/src/packages/administrativo/components/TImovel/TImovelForm.tsx +++ b/src/packages/administrativo/components/TImovel/TImovelForm.tsx @@ -27,7 +27,6 @@ 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'; @@ -45,7 +44,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa const { gTBBairro, fetchGTBBairro } = useGTBBairroReadHook(); // Inicializa o react-hook-form com schema zod - const form = useTImovelFormHook(); + const form = useTImovelFormHook({}); // Atualiza o formulário quando recebe dados para edição useEffect(() => { @@ -66,6 +65,10 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa }, [data, form]); + function onError(error: any) { + console.log(error); + } + return ( - Imóvel Urbano + {tipoClasse === 1 ? 'Imóvel Urbano' : 'Imóvel Rural'} - Cadastro de imóvel urbano + {tipoClasse === 1 ? 'Cadastro de imóvel urbano' : 'Cadastro de imóvel rural'} -
- {/* Tabs */} - - - - - Dados do Imóvel - - - - Unidades - - - {/* Dados do Imóvel */} - - + {/* Tabs */} + + + + + Dados do Imóvel + + + + Unidades + + + {/* Dados do Imóvel */} + + +
{/* UF */}
@@ -222,7 +225,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa Cartório - + field.onChange(parseNumberInput(e))} /> @@ -262,7 +265,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa />
{/* Tipo Registro */} -
+
{/* Número */} -
+
{/* Número Letra */} -
+
- {/* Tipo Registro */} -
- ( - - Tipo Classe - - - - - - )} - /> -
{/* Rodapé do Dialog */} @@ -366,19 +340,17 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa loading={buttonIsLoading} /> - - - {/* Unidades */} - - {/* Conteúdo das unidades */} - {tipoClasse === 1 ? : null} - {/* Conteúdo das unidades */} - {tipoClasse === 3 ? : null} - - - {/* Campo oculto */} - + + + {/* Unidades */} + + {/* Conteúdo das unidades */} + {tipoClasse === 1 ? : null} + {/* Conteúdo das unidades */} + {tipoClasse === 3 ? : null} + +
); diff --git a/src/packages/administrativo/components/TImovel/TImovelIndex.tsx b/src/packages/administrativo/components/TImovel/TImovelIndex.tsx index caa4b0c..14cc04c 100644 --- a/src/packages/administrativo/components/TImovel/TImovelIndex.tsx +++ b/src/packages/administrativo/components/TImovel/TImovelIndex.tsx @@ -33,7 +33,7 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: const { deleteTImovel } = useTImovelDeleteHook(); // Estados - const [selectedAndamento, setSelectedAndamento] = useState(null); + const [selectedData, setSelectedData] = useState(null); const [isFormOpen, setIsFormOpen] = useState(false); // Estado para saber qual item será deletado @@ -53,7 +53,15 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: * Abre o formulário no modo de edição ou criação */ const handleOpenForm = useCallback((data: TImovelInterface | null) => { - setSelectedAndamento(data); + // Se não houver dados (criação), cria um objeto inicial com pessoa_tipo + const initialData: TImovelInterface = data ?? { tipo_classe: tipoClasse } as TImovelInterface; + + // Se existir dado de tipo_classe preenchido, converte para inteiro + if (initialData.tipo_classe !== undefined && initialData.tipo_classe !== null) { + initialData.tipo_classe = Number(initialData.tipo_classe); + } + + setSelectedData(initialData); setIsFormOpen(true); }, []); @@ -61,7 +69,7 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: * Fecha o formulário e limpa o andamento selecionado */ const handleCloseForm = useCallback(() => { - setSelectedAndamento(null); + setSelectedData(null); setIsFormOpen(false); }, []); @@ -92,7 +100,6 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: (item: TImovelInterface) => { // Define o item atual para remoção setItemToDelete(item); - // Abre o modal de confirmação openConfirmDialog(); }, @@ -164,7 +171,7 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: {/* Formulário de criação/edição */} ({ + value: Number(id), + label, + })); + return ( + + + + + + + + + + + Nenhum resultado encontrado. + + {options.map((item) => ( + { + field.onChange(item.value); + setOpen(false); + }} + > + + {item.label} + + ))} + + + + + + ); +} diff --git a/src/packages/administrativo/components/TImovel/TImovelTipoImovelSelect.tsx b/src/packages/administrativo/components/TImovel/TImovelTipoImovelSelect.tsx new file mode 100644 index 0000000..0ab104c --- /dev/null +++ b/src/packages/administrativo/components/TImovel/TImovelTipoImovelSelect.tsx @@ -0,0 +1,60 @@ +import { Button } from "@/components/ui/button"; +import { CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command"; +import { FormControl } from "@/components/ui/form"; +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; +import { cn } from "@/lib/utils"; +import { ImovelTipoEnum } from "@/shared/enums/ImovelTipoEnum"; +import { Command } from "cmdk"; +import { CheckIcon, ChevronsUpDownIcon } from "lucide-react"; +import React from "react"; + +export default function TImovelTipoImovelSelect({ field }: any) { + const [open, setOpen] = React.useState(false); + const options = Object.entries(ImovelTipoEnum).map(([id, label]) => ({ + value: Number(id), + label, + })); + + return ( + + + + + + + + + + + Nenhum resultado encontrado. + + {options.map((item) => ( + { + field.onChange(item.value); + setOpen(false); + }} + > + + {item.label} + + ))} + + + + + + ); +} diff --git a/src/packages/administrativo/components/TImovel/TImovelTipoLogradouroSelect.tsx b/src/packages/administrativo/components/TImovel/TImovelTipoLogradouroSelect.tsx new file mode 100644 index 0000000..4f72661 --- /dev/null +++ b/src/packages/administrativo/components/TImovel/TImovelTipoLogradouroSelect.tsx @@ -0,0 +1,92 @@ +'use client'; + +import React from "react"; +import { Button } from "@/components/ui/button"; +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList, +} from "@/components/ui/command"; +import { FormControl } from "@/components/ui/form"; +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; +import { cn } from "@/lib/utils"; +import { CheckIcon, ChevronsUpDownIcon } from "lucide-react"; +import GetCapitalize from "@/shared/actions/text/GetCapitalize"; +import { useGTBTipoLogradouroReadHook } from "@/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroReadHook"; + +export default function TImovelTipoLogradouroSelect({ field }: any) { + const [open, setOpen] = React.useState(false); + const [isLoading, setIsLoading] = React.useState(false); + const { gTBTipoLogradouro, fetchGTBTipoLogradouro } = useGTBTipoLogradouroReadHook(); + // Busca os dados uma única vez ao montar + React.useEffect(() => { + const loadData = async () => { + if (!gTBTipoLogradouro.length) { + setIsLoading(true); + await fetchGTBTipoLogradouro(); + setIsLoading(false); + } + }; + loadData(); + }, []); + const selected = gTBTipoLogradouro.find( + (item) => String(item.tb_tipologradouro_id) === String(field.value) + ); + return ( + + + + + + + + + + + + {isLoading ? "Carregando..." : "Nenhum resultado encontrado."} + + + {gTBTipoLogradouro?.map((item) => ( + { + field.onChange(Number(item.tb_tipologradouro_id)); + setOpen(false); + }} + > + + {GetCapitalize(item.descricao)} + + ))} + + + + + + ); +} diff --git a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralForm.tsx b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralForm.tsx index 1758ef1..f16eacd 100644 --- a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralForm.tsx +++ b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralForm.tsx @@ -53,7 +53,7 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave, async function loadData() { // Carrega o tipo de logradouro - await fetchGTBTipoLogradouro(); + // await fetchGTBTipoLogradouro(); } diff --git a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoForm.tsx b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoForm.tsx index 260200d..101c11f 100644 --- a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoForm.tsx +++ b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoForm.tsx @@ -23,44 +23,31 @@ import { import { Input } from '@/components/ui/input'; import LoadingButton from '@/shared/components/loadingButton/LoadingButton'; -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 '@/shared/actions/text/GetCapitalize'; import { ResetFormIfData } from '@/shared/actions/form/ResetFormIfData'; import { parseNumberInput } from '@/shared/actions/form/parseNumberInput'; -import { ImovelTipoEnum } from '@/shared/enums/ImovelTipoEnum'; -import { ImovelConstrucaoEnum } from '@/shared/enums/ImovelConstrucaoEnum'; import { useGTBTipoLogradouroReadHook } from '@/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroReadHook'; import { useTImovelUnidadeUrbanoFormHook } from '@/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeUrbano/useTImovelUnidadeUrbanoFormHook'; import { TImovelUnidadeUrbanoFormInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoFormInterface'; +import TImovelTipoImovelSelect from '../../TImovel/TImovelTipoImovelSelect'; +import TImovelTipoConstrucaoSelect from '../../TImovel/TImovelTipoConstrucaoSelect'; +import TImovelTipoLogradouroSelect from '../../TImovel/TImovelTipoLogradouroSelect'; export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TImovelUnidadeUrbanoFormInterface) { const { gTBTipoLogradouro, fetchGTBTipoLogradouro } = useGTBTipoLogradouroReadHook(); // Inicializa o react-hook-form com schema zod - const form = useTImovelUnidadeUrbanoFormHook(); + const form = useTImovelUnidadeUrbanoFormHook({}); - // Atualiza o formulário quando recebe dados para edição + // Aguarda alteração no Data useEffect(() => { - - // Se existir dados, reseta o formulário com os mesmos ResetFormIfData(form, data); + }, [data]); - // Carregamento de dados iniciais - async function loadData() { - - // Carrega o tipo de logradouro - await fetchGTBTipoLogradouro(); - - } - - // Executa a função - loadData(); - - }, [data, form]); + // Execução imediata + useEffect(() => { + if (!gTBTipoLogradouro.length) fetchGTBTipoLogradouro(); + }, []); return ( { - const [open, setOpen] = React.useState(false); - return ( - - Tipo logradouro - - - - - - - - - - - Nenhum resultado encontrado. - - {gTBTipoLogradouro?.map((item) => ( - { - field.onChange(Number(item.tb_tipologradouro_id)); - setOpen(false); - }} - > - - {GetCapitalize(item.descricao)} - - ))} - - - - - - - - ); - }} + render={({ field }) => ( + + Tipo logradouro + + + + )} /> {/* Logradouro */} @@ -236,62 +171,10 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave control={form.control} name="tipo_imovel" render={({ field }) => { - 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 Imóvel - - - - - - - - - - - Nenhum resultado encontrado. - - {options.map((item) => ( - { - field.onChange(item.value); - setOpen(false); - }} - > - - {item.label} - - ))} - - - - - + ); @@ -304,61 +187,10 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave control={form.control} name="tipo_construcao" render={({ field }) => { - const [open, setOpen] = React.useState(false); - const options = Object.entries(ImovelConstrucaoEnum).map(([id, label]) => ({ - value: Number(id), - label, - })); return ( Construção - - - - - - - - - - - Nenhum resultado encontrado. - - {options.map((item) => ( - { - field.onChange(item.value); - setOpen(false); - }} - > - - {item.label} - - ))} - - - - - + ); @@ -495,7 +327,6 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave )} /> - {/* Numero da Edificação */}
- {/* Complemento */}
{pessoa.nome || '-'}
-
- {empty(pessoa.email) ? 'Email não informado' : pessoa.email} -
); @@ -57,7 +54,6 @@ export default function TPessoaJuridicaColumns( sortingFn: (a, b) => (a.original.nome?.toLowerCase() || '').localeCompare(b.original.nome?.toLowerCase() || ''), }, - // CPF { accessorKey: 'cpf_cnpj', diff --git a/src/packages/administrativo/hooks/TImovel/useTImovelFormHook.ts b/src/packages/administrativo/hooks/TImovel/useTImovelFormHook.ts index adbc6cb..fa56ab2 100644 --- a/src/packages/administrativo/hooks/TImovel/useTImovelFormHook.ts +++ b/src/packages/administrativo/hooks/TImovel/useTImovelFormHook.ts @@ -1,6 +1,6 @@ import { useForm } from "react-hook-form"; -import { zodResolver } from "@hookform/resolvers/zod"; import { TImovelFormValues, TImovelSchema } from "../../schemas/TImovel/TImovelSchema"; +import { zodResolver } from "@hookform/resolvers/zod"; export function useTImovelFormHook(defaults?: Partial) { return useForm({ diff --git a/src/packages/administrativo/interfaces/TImovel/TImovelInterface.ts b/src/packages/administrativo/interfaces/TImovel/TImovelInterface.ts index 56bad16..26ccbec 100644 --- a/src/packages/administrativo/interfaces/TImovel/TImovelInterface.ts +++ b/src/packages/administrativo/interfaces/TImovel/TImovelInterface.ts @@ -1,6 +1,6 @@ export default interface TImovelInterface { imovel_id?: number, - tipo_classe?: string, + tipo_classe?: number, tipo_registro?: string, data_registro?: string, numero?: number, @@ -9,7 +9,7 @@ export default interface TImovelInterface { cep?: string, uf?: string, tb_bairro_id?: number, - cartorio?: string, + cartorio?: number, livro?: string, cns?: number, gtbb_descricao?: string, diff --git a/src/packages/administrativo/schemas/TImovel/TImovelSchema.ts b/src/packages/administrativo/schemas/TImovel/TImovelSchema.ts index f7653b2..c793045 100644 --- a/src/packages/administrativo/schemas/TImovel/TImovelSchema.ts +++ b/src/packages/administrativo/schemas/TImovel/TImovelSchema.ts @@ -2,7 +2,7 @@ import z from "zod"; export const TImovelSchema = z.object({ imovel_id: z.number().optional(), - tipo_classe: z.string().optional(), + tipo_classe: z.number().optional(), tipo_registro: z.string().optional(), data_registro: z.string().optional(), numero: z.number().optional(), @@ -11,9 +11,10 @@ export const TImovelSchema = z.object({ cep: z.string().optional(), uf: z.string().optional(), tb_bairro_id: z.number().optional(), - cartorio: z.string().optional(), + cartorio: z.number().optional(), livro: z.string().optional(), cns: z.number().optional(), + gtbb_descricao: z.string().optional(), }); export type TImovelFormValues = z.infer; \ No newline at end of file