From 37f0f8713d71a35d83169888b17a725f042b2908 Mon Sep 17 00:00:00 2001 From: keven Date: Thu, 9 Oct 2025 15:50:20 -0300 Subject: [PATCH] =?UTF-8?q?[MVPTN-88]=20feat(CRUD)=20implementa=C3=A7?= =?UTF-8?q?=C3=B5es=20diversas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/TImovel/TImovelForm.tsx | 88 +++++----- .../components/TImovel/TImovelIndex.tsx | 10 +- .../TImovelUnidadeRuralForm.tsx | 74 ++++---- ...lPage.tsx => TImovelUnidadeRuralIndex.tsx} | 20 ++- .../TImovelUnidadeRuralTable.tsx | 2 +- .../TImovelUnidadeUrbanoForm.tsx | 28 ++- .../TImovelUnidadeUrbanoPage.tsx | 15 +- .../data/TImovel/TImovelIndexData.ts | 5 +- .../TImovelUnidadeRuralDeleteData.ts | 11 +- .../TImovelUnidadeRuralIndexData.ts | 162 +----------------- .../TImovelUnidadeRuralSaveData.ts | 20 ++- .../TImovelUnidadeUrbanoDeleteData.ts | 1 - .../TImovelUnidadeUrbanoIndexData.ts | 3 - .../hooks/TImovel/useTImovelFormHook.ts | 1 + .../hooks/TImovel/useTImovelIndexHook.ts | 7 +- .../useTImovelUnidadeRuralFormHook.ts | 1 + .../useTImovelUnidadeRuralIndexHook.ts | 7 +- .../useTImovelUnidadeUrbanoFormHook.ts | 21 ++- .../TImovel/TImovelIndexInterface.ts | 6 +- .../TImovelUnidadePageInterface.ts | 2 +- .../TImovelUnidadeUrbanoInterface.ts | 4 +- .../TImovelUnidadeRuralSchema.ts | 5 +- .../TImovelUnidadeUrbanoSchema.ts | 4 +- .../TImovelUnidadeRuralIndexService.ts | 11 +- .../TImovelUnidadeRuralSaveService.ts | 1 - .../TImovelUnidadeUrbanoIndexService.ts | 12 +- src/shared/actions/form/ResetFormIfData.ts | 5 +- src/shared/actions/form/normalizeFormData.ts | 19 ++ src/shared/components/response/response.tsx | 12 -- 29 files changed, 245 insertions(+), 312 deletions(-) rename src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/{TImovelUnidadeRuralPage.tsx => TImovelUnidadeRuralIndex.tsx} (86%) create mode 100644 src/shared/actions/form/normalizeFormData.ts diff --git a/src/packages/administrativo/components/TImovel/TImovelForm.tsx b/src/packages/administrativo/components/TImovel/TImovelForm.tsx index 68dec33..5b4d89b 100644 --- a/src/packages/administrativo/components/TImovel/TImovelForm.tsx +++ b/src/packages/administrativo/components/TImovel/TImovelForm.tsx @@ -37,7 +37,7 @@ 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 TImovelUnidadeRuralIndex from '../TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndex'; import { parseNumberInput } from '@/shared/actions/form/parseNumberInput'; export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoading, tipoClasse }: TImovelFormInterface) { @@ -83,21 +83,21 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
- - {/* Tabs */} - - - - - Dados do Imóvel - - - - Unidades - - - {/* Dados do Imóvel */} - + {/* Tabs */} + + + + + Dados do Imóvel + + + + Unidades + + + {/* Dados do Imóvel */} + +
{/* UF */}
@@ -299,7 +299,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa Número - + field.onChange(parseNumberInput(e))} /> @@ -352,34 +352,34 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa />
-
- {/* Unidades */} - - {/* Conteúdo das unidades */} - {tipoClasse === 1 ? : null} - {/* Conteúdo das unidades */} - {tipoClasse === 3 ? : null} - -
- {/* Rodapé do Dialog */} - - - - - - - {/* Campo oculto */} - - + {/* Rodapé do Dialog */} + + + + + + + + +
+ {/* Unidades */} + + {/* Conteúdo das unidades */} + {tipoClasse === 1 ? : null} + {/* Conteúdo das unidades */} + {tipoClasse === 3 ? : null} + +
+ {/* 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 index be55ec5..c217ea6 100644 --- a/src/packages/administrativo/components/TImovel/TImovelIndex.tsx +++ b/src/packages/administrativo/components/TImovel/TImovelIndex.tsx @@ -19,6 +19,10 @@ import TImovelForm from './TImovelForm'; export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: TImovelIndexInterface) { + const TImovelIndexInterface: TImovelIndexInterface = { + tipoClasse: tipoClasse + } + // Controle de estado do botão const [buttonIsLoading, setButtonIsLoading] = useState(false); @@ -75,7 +79,7 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: setButtonIsLoading(false); // Atualiza a lista de dados - indexTImovel(); + indexTImovel(TImovelIndexInterface); }, [saveTImovel, indexTImovel, handleCloseForm], ); @@ -105,7 +109,7 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: await deleteTImovel(itemToDelete); // Atualiza a lista - await indexTImovel(); + await indexTImovel(TImovelIndexInterface); // Limpa o item selecionado setItemToDelete(null); @@ -118,7 +122,7 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: * Busca inicial dos dados */ useEffect(() => { - indexTImovel(); + indexTImovel(TImovelIndexInterface); }, []); /** diff --git a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralForm.tsx b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralForm.tsx index 3c3b7f2..1758ef1 100644 --- a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralForm.tsx +++ b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralForm.tsx @@ -33,7 +33,8 @@ import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, Command import { ImovelTipoEnum } from '@/shared/enums/ImovelTipoEnum'; import { cn } from '@/lib/utils'; import { ImovelConstrucaoEnum } from '@/shared/enums/ImovelConstrucaoEnum'; -import { Checkbox } from '@/components/ui/checkbox'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { SituacoesEnum } from '@/shared/enums/SituacoesEnum'; export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TImovelUnidadeRuralFormInterface) { @@ -61,6 +62,10 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave, }, [data, form]); + function onErro(errors: any) { + console.log(errors); + } + return (
- +
{/* Tipo Imóvel */}
@@ -306,56 +311,59 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave, />
{/* Geo Referenciamento */} -
+
( - -
- - - - - Geo Referenciamento - -
+ + Geo Referenciamento + + + )} />
{/* Reserva Florestal */} -
+
( - -
- - - - - Reserva Florestal - -
+ + Reserva Florestal + + + )} />
- {/* Campo oculto */} - -
{/* Rodapé do Dialog */} diff --git a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralPage.tsx b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndex.tsx similarity index 86% rename from src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralPage.tsx rename to src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndex.tsx index 3508453..63fc9a8 100644 --- a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralPage.tsx +++ b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndex.tsx @@ -3,7 +3,7 @@ import { useEffect, useState, useCallback } from 'react'; import Loading from '@/shared/components/loading/loading'; -import TImovelUnidadeTable from './TImovelUnidadeRuralTable'; +import TImovelUnidadeRuralTable from './TImovelUnidadeRuralTable'; import TImovelUnidadeRuralForm from './TImovelUnidadeRuralForm'; import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog'; @@ -14,8 +14,14 @@ import { useTImovelUnidadeRuralIndexHook } from '@/packages/administrativo/hooks import { useTImovelUnidadeRuralSaveHook } from '@/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralSaveHook'; import { useTImovelUnidadeRuralDeleteHook } from '@/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralDeleteHook'; import { TImovelUnidadeRuralInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural'; +import TImovelUnidadePageInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface'; + +export default function TImovelUnidadeRuralIndex({ imovel_id }: TImovelUnidadePageInterface) { + + const TImovelUnidadePage: TImovelUnidadePageInterface = { + imovel_id: imovel_id + } -export default function TImovelUnidadePage() { // Controle de estado do botão const [buttonIsLoading, setButtonIsLoading] = useState(false); @@ -45,6 +51,8 @@ export default function TImovelUnidadePage() { * Abre o formulário no modo de edição ou criação */ const handleOpenForm = useCallback((data: TImovelUnidadeRuralInterface | null) => { + // Se não houver dados (criação), cria um objeto inicial com imovel_id + const initialData: TImovelUnidadeRuralInterface = data ?? { imovel_id } as TImovelUnidadeRuralInterface; setSelectedData(data); setIsFormOpen(true); }, []); @@ -72,7 +80,7 @@ export default function TImovelUnidadePage() { setButtonIsLoading(false); // Atualiza a lista de dados - indexTImovelUnidadeRural(); + indexTImovelUnidadeRural(TImovelUnidadePage); }, [saveTImovelUnidadeRural, indexTImovelUnidadeRural, handleCloseForm], ); @@ -102,7 +110,7 @@ export default function TImovelUnidadePage() { await deleteTImovelUnidadeRural(itemToDelete); // Atualiza a lista - await indexTImovelUnidadeRural(); + await indexTImovelUnidadeRural(TImovelUnidadePage); // Limpa o item selecionado setItemToDelete(null); @@ -115,7 +123,7 @@ export default function TImovelUnidadePage() { * Busca inicial dos dados */ useEffect(() => { - indexTImovelUnidadeRural(); + indexTImovelUnidadeRural(TImovelUnidadePage); }, []); /** @@ -137,7 +145,7 @@ export default function TImovelUnidadePage() { }} /> {/* Tabela de andamentos */} - diff --git a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralTable.tsx b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralTable.tsx index 90c6c79..f8e72c8 100644 --- a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralTable.tsx +++ b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralTable.tsx @@ -7,7 +7,7 @@ import TImovelUnidadeRuralTableInterface from '@/packages/administrativo/interfa /** * Componente principal da tabela */ -export default function TImovelUnidadeTable({ data, onEdit, onDelete }: TImovelUnidadeRuralTableInterface) { +export default function TImovelUnidadeRuralTable({ data, onEdit, onDelete }: TImovelUnidadeRuralTableInterface) { const columns = TImovelUnidadeColumns(onEdit, onDelete); return (
diff --git a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoForm.tsx b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoForm.tsx index 37d4ce5..260200d 100644 --- a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoForm.tsx +++ b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoForm.tsx @@ -272,7 +272,7 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave key={item.value} value={item.label.toLowerCase()} onSelect={() => { - field.onChange(item.value); // salva o número (id) + field.onChange(item.value); setOpen(false); }} > @@ -366,7 +366,7 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave />
{/* Iptu */} -
+
( - UnidadeUrbano + Unidade Urbano @@ -432,7 +432,7 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave />
{/* Loteamento */} -
+
+ {/* Numero */} +
+ ( + + Numero + + + + + + )} + /> +
{/* CNM */}
+ {/* Complemento */}
- {/* Campo oculto */} - - diff --git a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoPage.tsx b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoPage.tsx index 18da32e..60edd8c 100644 --- a/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoPage.tsx +++ b/src/packages/administrativo/components/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoPage.tsx @@ -16,7 +16,7 @@ import TImovelUnidadeUrbanoTable from './TImovelUnidadeUrbanoTable'; import TImovelUnidadeUrbanoForm from './TImovelUnidadeUrbanoForm'; import TImovelUnidadePageInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface'; -export default function TImovelUnidadeUrbanoPage({imovel_id}: TImovelUnidadePageInterface) { +export default function TImovelUnidadeUrbanoPage({ imovel_id }: TImovelUnidadePageInterface) { const TImovelUnidadePage: TImovelUnidadePageInterface = { imovel_id: imovel_id @@ -31,7 +31,7 @@ export default function TImovelUnidadeUrbanoPage({imovel_id}: TImovelUnidadePage const { deleteTImovelUnidadeUrbano } = useTImovelUnidadeUrbanoDeleteHook(); // Estados - const [selectedAndamento, setSelectedAndamento] = useState(null); + const [selectedData, setSelectedData] = useState(null); const [isFormOpen, setIsFormOpen] = useState(false); // Estado para saber qual item será deletado @@ -51,7 +51,9 @@ export default function TImovelUnidadeUrbanoPage({imovel_id}: TImovelUnidadePage * Abre o formulário no modo de edição ou criação */ const handleOpenForm = useCallback((data: TImovelUnidadeUrbanoInterface | null) => { - setSelectedAndamento(data); + // Se não houver dados (criação), cria um objeto inicial com imovel_id + const initialData: TImovelUnidadeUrbanoInterface = data ?? { imovel_id } as TImovelUnidadeUrbanoInterface; + setSelectedData(initialData); setIsFormOpen(true); }, []); @@ -59,7 +61,7 @@ export default function TImovelUnidadeUrbanoPage({imovel_id}: TImovelUnidadePage * Fecha o formulário e limpa o andamento selecionado */ const handleCloseForm = useCallback(() => { - setSelectedAndamento(null); + setSelectedData(null); setIsFormOpen(false); }, []); @@ -146,7 +148,8 @@ export default function TImovelUnidadeUrbanoPage({imovel_id}: TImovelUnidadePage + onDelete={handleConfirmDelete} + /> {/* Modal de confirmação */} { +async function executeTImovelIndexData(data: TImovelIndexInterface): Promise { const api = new API(); return api.send({ method: Methods.GET, - endpoint: `administrativo/t_imovel/classe/1` + endpoint: `administrativo/t_imovel/classe/${data.tipoClasse}` }); } diff --git a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralDeleteData.ts b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralDeleteData.ts index f7ffa20..c0ea3b3 100644 --- a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralDeleteData.ts +++ b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralDeleteData.ts @@ -1,13 +1,14 @@ import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler"; import { TImovelUnidadeRuralInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural"; +import { Methods } from "@/shared/services/api/enums/ApiMethodEnum"; +import API from "@/shared/services/api/Api"; async function executeTImovelUnidadeRuralDeleteData(data: TImovelUnidadeRuralInterface) { - - return Promise.resolve({ - status: 200, - message: 'Dados Removidos' + const api = new API(); + return api.send({ + method: Methods.DELETE, + endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id}` }); - } export const TImovelUnidadeRuralDeleteData = withClientErrorHandler(executeTImovelUnidadeRuralDeleteData); \ No newline at end of file diff --git a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexData.ts b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexData.ts index 8ddfd2c..8a0889e 100644 --- a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexData.ts +++ b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexData.ts @@ -1,160 +1,14 @@ +import TImovelUnidadePageInterface from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface"; import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler"; +import API from "@/shared/services/api/Api"; +import { Methods } from "@/shared/services/api/enums/ApiMethodEnum"; -async function executeTImovelUnidadeRuralIndexData() { +async function executeTImovelUnidadeRuralIndexData(data: TImovelUnidadePageInterface) { - return Promise.resolve({ - status: 200, - message: 'Dados Salvos', - data: [ - { - "imovel_unidade_id": 3921.00, - "imovel_id": 5459.00, - "numero_unidade": "asdfasd", - "quadra": null, - "area": null, - "superquadra": null, - "conjunto": null, - "bloco": null, - "area_descritiva": null, - "caracteristica": null, - "reserva_florestal": null, - "geo_referenciamento": null, - "logradouro": null, - "tb_tipologradouro_id": null, - "selecionado": "S", - "complemento": null, - "tipo_imovel": 67.00, - "tipo_construcao": 0.00, - "texto": null, - "numero_edificacao": null, - "iptu": "", - "ccir": null, - "nirf": null, - "lote": null, - "torre": null, - "nomeloteamento": null, - "nomecondominio": null, - "numero": null, - "cnm_numero": null, - "imovel_publico_uniao": null, - "spu_rip": null, - "cat": null, - "inscricao_municipal": null, - "cib": null, - "area_construida": null - }, - { - "imovel_unidade_id": 3918.00, - "imovel_id": 5456.00, - "numero_unidade": null, - "quadra": "45", - "area": null, - "superquadra": null, - "conjunto": null, - "bloco": null, - "area_descritiva": null, - "caracteristica": null, - "reserva_florestal": null, - "geo_referenciamento": null, - "logradouro": null, - "tb_tipologradouro_id": null, - "selecionado": "S", - "complemento": null, - "tipo_imovel": 67.00, - "tipo_construcao": 0.00, - "texto": null, - "numero_edificacao": null, - "iptu": null, - "ccir": null, - "nirf": null, - "lote": null, - "torre": null, - "nomeloteamento": null, - "nomecondominio": null, - "numero": null, - "cnm_numero": null, - "imovel_publico_uniao": null, - "spu_rip": null, - "cat": null, - "inscricao_municipal": null, - "cib": null, - "area_construida": null - }, - { - "imovel_unidade_id": 3917.00, - "imovel_id": 5454.00, - "numero_unidade": null, - "quadra": "45", - "area": 160.00, - "superquadra": null, - "conjunto": null, - "bloco": null, - "area_descritiva": null, - "caracteristica": null, - "reserva_florestal": null, - "geo_referenciamento": null, - "logradouro": "RUA P 3", - "tb_tipologradouro_id": 1.00, - "selecionado": "", - "complemento": null, - "tipo_imovel": 67.00, - "tipo_construcao": 0.00, - "texto": null, - "numero_edificacao": null, - "iptu": "1200", - "ccir": null, - "nirf": null, - "lote": "12", - "torre": null, - "nomeloteamento": null, - "nomecondominio": null, - "numero": 125.00, - "cnm_numero": null, - "imovel_publico_uniao": null, - "spu_rip": null, - "cat": null, - "inscricao_municipal": null, - "cib": null, - "area_construida": null - }, - { - "imovel_unidade_id": 3916.00, - "imovel_id": 5453.00, - "numero_unidade": null, - "quadra": "06", - "area": 461.51, - "superquadra": null, - "conjunto": null, - "bloco": null, - "area_descritiva": null, - "caracteristica": null, - "reserva_florestal": null, - "geo_referenciamento": null, - "logradouro": "Mariana Vilela", - "tb_tipologradouro_id": 3.00, - "selecionado": "S", - "complemento": null, - "tipo_imovel": 71.00, - "tipo_construcao": 2.00, - "texto": "{...}", - "numero_edificacao": null, - "iptu": "001.211.0006.0012.0001", - "ccir": null, - "nirf": null, - "lote": "12", - "torre": null, - "nomeloteamento": null, - "nomecondominio": null, - "numero": null, - "cnm_numero": null, - "imovel_publico_uniao": null, - "spu_rip": null, - "cat": null, - "inscricao_municipal": null, - "cib": null, - "area_construida": null - } - ] + const api = new API(); + return await api.send({ + method: Methods.GET, + endpoint: `administrativo/t_imovel_unidade/imovel/${data.imovel_id}` }); } diff --git a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSaveData.ts b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSaveData.ts index d63d21b..739e375 100644 --- a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSaveData.ts +++ b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSaveData.ts @@ -1,13 +1,23 @@ import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler"; import { TImovelUnidadeRuralInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural"; +import API from "@/shared/services/api/Api"; +import { Methods } from "@/shared/services/api/enums/ApiMethodEnum"; -async function executeTImovelUnidadeRuralDeleteData(data: TImovelUnidadeRuralInterface) { +async function executeTImovelUnidadeRuralSaveData(data: TImovelUnidadeRuralInterface) { - return Promise.resolve({ - status: 200, - message: 'Dados Removidos' + // Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST) + const isUpdate = Boolean(data.imovel_unidade_id); + + // Instancia o cliente da API para enviar a requisição + const api = new API(); + + // Executa a requisição para a API com o método apropriado e envia os dados no corpo + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar + endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id || ''}`, // endpoint dinâmico + body: data, // payload enviado para a API }); } -export const TImovelUnidadeRuralSaveData = withClientErrorHandler(executeTImovelUnidadeRuralDeleteData); \ No newline at end of file +export const TImovelUnidadeRuralSaveData = withClientErrorHandler(executeTImovelUnidadeRuralSaveData); \ No newline at end of file diff --git a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoDeleteData.ts b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoDeleteData.ts index 38390e4..3f4c3b6 100644 --- a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoDeleteData.ts +++ b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoDeleteData.ts @@ -6,7 +6,6 @@ import { Methods } from "@/shared/services/api/enums/ApiMethodEnum"; async function executeTImovelUnidadeUrbanoDeleteData(data: TImovelUnidadeUrbanoInterface) { const api = new API(); - return api.send({ method: Methods.DELETE, endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id}` diff --git a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoIndexData.ts b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoIndexData.ts index d8c0be5..3d05ad6 100644 --- a/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoIndexData.ts +++ b/src/packages/administrativo/data/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoIndexData.ts @@ -4,14 +4,11 @@ import API from "@/shared/services/api/Api"; import { Methods } from "@/shared/services/api/enums/ApiMethodEnum"; async function executeTImovelUnidadeUrbanoIndexData(data: TImovelUnidadePageInterface) { - const api = new API(); - return api.send({ method: Methods.GET, endpoint: `administrativo/t_imovel_unidade/imovel/${data.imovel_id}` }); - } export const TImovelUnidadeUrbanoIndexData = withClientErrorHandler(executeTImovelUnidadeUrbanoIndexData); \ No newline at end of file diff --git a/src/packages/administrativo/hooks/TImovel/useTImovelFormHook.ts b/src/packages/administrativo/hooks/TImovel/useTImovelFormHook.ts index 9ab53e1..adbc6cb 100644 --- a/src/packages/administrativo/hooks/TImovel/useTImovelFormHook.ts +++ b/src/packages/administrativo/hooks/TImovel/useTImovelFormHook.ts @@ -6,6 +6,7 @@ export function useTImovelFormHook(defaults?: Partial) { return useForm({ resolver: zodResolver(TImovelSchema), defaultValues: { + imovel_id: 0, ...defaults, }, }); diff --git a/src/packages/administrativo/hooks/TImovel/useTImovelIndexHook.ts b/src/packages/administrativo/hooks/TImovel/useTImovelIndexHook.ts index 09f3dcb..3387f57 100644 --- a/src/packages/administrativo/hooks/TImovel/useTImovelIndexHook.ts +++ b/src/packages/administrativo/hooks/TImovel/useTImovelIndexHook.ts @@ -4,18 +4,17 @@ import { useResponse } from '@/shared/components/response/ResponseContext'; import { useState } from 'react'; import TImovelInterface from '../../interfaces/TImovel/TImovelInterface'; import { TImovelIndexData } from '../../data/TImovel/TImovelIndexData'; +import { TImovelIndexInterface } from '../../interfaces/TImovel/TImovelIndexInterface'; export const useTImovelIndexHook = () => { const { setResponse } = useResponse(); const [tImovel, setTImovel] = useState([]); - const indexTImovel = async () => { - const response = await TImovelIndexData(); - + const indexTImovel = async (data: TImovelIndexInterface) => { + const response = await TImovelIndexData(data); // Armazena os dados consultados setTImovel(response.data); - // Define os dados do componente de resposta (toast, modal, etc) setResponse(response); }; diff --git a/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralFormHook.ts b/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralFormHook.ts index 1c6f664..ac18f23 100644 --- a/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralFormHook.ts +++ b/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralFormHook.ts @@ -6,6 +6,7 @@ export function useTImovelUnidadeRuralFormHook(defaults?: Partial({ resolver: zodResolver(TImovelUnidadeRuralSchema), defaultValues: { + imovel_unidade_id: 0, ...defaults, }, }); diff --git a/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralIndexHook.ts b/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralIndexHook.ts index 2fd32ae..45302e1 100644 --- a/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralIndexHook.ts +++ b/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralIndexHook.ts @@ -1,17 +1,18 @@ 'use client'; import { useResponse } from '@/shared/components/response/ResponseContext'; -import { TImovelUnidadeRuralIndexData } from '@/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexData'; import { TImovelUnidadeRuralInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural'; import { useState } from 'react'; +import { TImovelUnidadeRuralIndexService } from '@/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexService'; +import TImovelUnidadeInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeInterface'; export const useTImovelUnidadeRuralIndexHook = () => { const { setResponse } = useResponse(); const [tImovelUnidadeRural, setTImovelUnidadeRural] = useState([]); - const indexTImovelUnidadeRural = async () => { - const response = await TImovelUnidadeRuralIndexData(); + const indexTImovelUnidadeRural = async (data: TImovelUnidadeInterface) => { + const response = await TImovelUnidadeRuralIndexService(data); // Armazena os dados consultados setTImovelUnidadeRural(response.data); diff --git a/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeUrbano/useTImovelUnidadeUrbanoFormHook.ts b/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeUrbano/useTImovelUnidadeUrbanoFormHook.ts index 769ae95..771d834 100644 --- a/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeUrbano/useTImovelUnidadeUrbanoFormHook.ts +++ b/src/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeUrbano/useTImovelUnidadeUrbanoFormHook.ts @@ -6,7 +6,26 @@ export function useTImovelUnidadeUrbanoFormHook(defaults?: Partial({ resolver: zodResolver(TImovelUnidadeUrbanoSchema), defaultValues: { - ...defaults, + imovel_unidade_id: 0, + imovel_id: 0, + quadra: '', + lote: '', + area: 0, + inscricao_municipal: '', + logradouro: '', + tipo_imovel: 0, + tipo_construcao: 0, + iptu: '', + numero_unidade: '', + torre: '', + nomecondominio: '', + nomeloteamento: '', + cib: '', + cnm_numero: '', + numero_edificacao: '', + complemento: '', + tb_tipologradouro_id: 0, + ...defaults, // sobrescreve com dados reais se houver }, }); } \ No newline at end of file diff --git a/src/packages/administrativo/interfaces/TImovel/TImovelIndexInterface.ts b/src/packages/administrativo/interfaces/TImovel/TImovelIndexInterface.ts index 7dad419..5329745 100644 --- a/src/packages/administrativo/interfaces/TImovel/TImovelIndexInterface.ts +++ b/src/packages/administrativo/interfaces/TImovel/TImovelIndexInterface.ts @@ -1,5 +1,5 @@ export interface TImovelIndexInterface { - pageTitle: string, - pageDescription: string, - tipoClasse: number + pageTitle?: string, + pageDescription?: string, + tipoClasse?: number } \ No newline at end of file diff --git a/src/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface.ts b/src/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface.ts index e7ed9bc..da9256a 100644 --- a/src/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface.ts +++ b/src/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface.ts @@ -1,3 +1,3 @@ export default interface TImovelUnidadePageInterface { - imovel_id? : number; + imovel_id?: number; } \ No newline at end of file diff --git a/src/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface.ts b/src/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface.ts index 39b5e50..ab13fee 100644 --- a/src/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface.ts +++ b/src/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface.ts @@ -5,7 +5,7 @@ export interface TImovelUnidadeUrbanoInterface extends TImovelUnidadeInterface { lote?: string; inscricao_municipal?: string; tb_tipologradouro_id?: number; - logradouro: string; + logradouro?: string; tipo_imovel?: number; tipo_construcao?: number; iptu?: string; @@ -13,7 +13,7 @@ export interface TImovelUnidadeUrbanoInterface extends TImovelUnidadeInterface { torre?: string; nomecondominio?: string; nomeloteamento?: string; - numero?: number; + numero?: string; complemento?: string; numero_edificacao?: string; cnm_numero?: string; diff --git a/src/packages/administrativo/schemas/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSchema.ts b/src/packages/administrativo/schemas/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSchema.ts index 2700c15..49904fc 100644 --- a/src/packages/administrativo/schemas/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSchema.ts +++ b/src/packages/administrativo/schemas/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSchema.ts @@ -1,11 +1,12 @@ import { z } from "zod"; import { TImovelUnidadeSchema } from "../TImovelUnidadeSchema"; +import { SituacoesEnum } from "@/shared/enums/SituacoesEnum"; export const TImovelUnidadeRuralSchema = TImovelUnidadeSchema.extend({ galpao: z.string().optional(), nao_se_aplica: z.boolean().optional(), - reserva_florestal: z.boolean().optional(), - geo_referenciamento: z.boolean().optional(), + reserva_florestal: z.enum(SituacoesEnum), + geo_referenciamento: z.enum(SituacoesEnum), nome_identificacao: z.string().optional(), ccir: z.string().optional(), denominacao: z.string().optional(), diff --git a/src/packages/administrativo/schemas/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoSchema.ts b/src/packages/administrativo/schemas/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoSchema.ts index 50719b1..84cb90d 100644 --- a/src/packages/administrativo/schemas/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoSchema.ts +++ b/src/packages/administrativo/schemas/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoSchema.ts @@ -6,13 +6,13 @@ export const TImovelUnidadeUrbanoSchema = TImovelUnidadeSchema.extend({ lote: z.string().optional(), inscricao_municipal: z.string().optional(), tb_tipologradouro_id: z.number().optional(), - logradouro: z.string().min(1, "O logradouro é obrigatório"), + logradouro: z.string().optional(), iptu: z.string().optional(), numero_unidade: z.string().optional(), torre: z.string().optional(), nomecondominio: z.string().optional(), nomeloteamento: z.string().optional(), - numero: z.number().optional(), + numero: z.string().optional(), complemento: z.string().optional(), numero_edificacao: z.string().optional(), cnm_numero: z.string().optional(), diff --git a/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexService.ts b/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexService.ts index 2826766..f5b320c 100644 --- a/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexService.ts +++ b/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexService.ts @@ -1,10 +1,13 @@ import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler'; import { TImovelUnidadeRuralIndexData } from '@/packages/administrativo/data/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralIndexData'; +import TImovelUnidadeInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeInterface'; -export default async function executeTImovelUnidadeRuralIndexService() { - const response = await TImovelUnidadeRuralIndexData(); - - return response; +export default async function executeTImovelUnidadeRuralIndexService(data: TImovelUnidadeInterface) { + let response = null + if (data.imovel_id) { + response = await TImovelUnidadeRuralIndexData(data); + return response; + } } export const TImovelUnidadeRuralIndexService = withClientErrorHandler(executeTImovelUnidadeRuralIndexService); diff --git a/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSaveService.ts b/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSaveService.ts index ae8c08b..b8e3413 100644 --- a/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSaveService.ts +++ b/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralSaveService.ts @@ -4,7 +4,6 @@ import { TImovelUnidadeRuralInterface } from '@/packages/administrativo/interfac async function executeTImovelUnidadeRuralSaveService(data: TImovelUnidadeRuralInterface) { const response = await TImovelUnidadeRuralSaveData(data); - return response; } diff --git a/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoIndexService.ts b/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoIndexService.ts index 9668663..8af64fe 100644 --- a/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoIndexService.ts +++ b/src/packages/administrativo/services/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoIndexService.ts @@ -3,11 +3,13 @@ import { TImovelUnidadeUrbanoIndexData } from '@/packages/administrativo/data/TI import TImovelUnidadePageInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface'; export default async function executeTImovelUnidadeUrbanoIndexService(data: TImovelUnidadePageInterface) { - const response = await TImovelUnidadeUrbanoIndexData(data); - - if (response.status === 200) { - return response; + if (!data.imovel_id) { + return { + status: 1000, + message: 'Não existe ID de imóvel para consultas.', + }; } + return await TImovelUnidadeUrbanoIndexData(data); } -export const TImovelUnidadeUrbanoIndexService = withClientErrorHandler(executeTImovelUnidadeUrbanoIndexService); \ No newline at end of file +export const TImovelUnidadeUrbanoIndexService = withClientErrorHandler(executeTImovelUnidadeUrbanoIndexService); \ No newline at end of file diff --git a/src/shared/actions/form/ResetFormIfData.ts b/src/shared/actions/form/ResetFormIfData.ts index 09fa8df..09c54a6 100644 --- a/src/shared/actions/form/ResetFormIfData.ts +++ b/src/shared/actions/form/ResetFormIfData.ts @@ -1,4 +1,5 @@ import { UseFormReturn, FieldValues } from "react-hook-form"; +import normalizeFormData from "./normalizeFormData"; /** * Reseta o formulário com os dados recebidos (se existirem) @@ -10,6 +11,6 @@ export function ResetFormIfData( data: T | null ) { if (data) { - form.reset(data); + form.reset(normalizeFormData(data)); } -} +} \ No newline at end of file diff --git a/src/shared/actions/form/normalizeFormData.ts b/src/shared/actions/form/normalizeFormData.ts new file mode 100644 index 0000000..d2a3dfe --- /dev/null +++ b/src/shared/actions/form/normalizeFormData.ts @@ -0,0 +1,19 @@ +/** + * Normaliza os dados do formulário, substituindo null por valores padrão + * Strings: '' + * Numbers: 0 + * Boolean: false + */ +export default function normalizeFormData>(data: T): T { + const normalized: Record = {}; + for (const key in data) { + if (data[key] === null || data[key] === undefined) { + // Detecta tipo baseado em chave ou regra padrão + normalized[key] = + typeof data[key] === 'number' ? 0 : ''; + } else { + normalized[key] = data[key]; + } + } + return normalized as T; +} \ No newline at end of file diff --git a/src/shared/components/response/response.tsx b/src/shared/components/response/response.tsx index dc38b6c..e644e97 100644 --- a/src/shared/components/response/response.tsx +++ b/src/shared/components/response/response.tsx @@ -7,39 +7,27 @@ import { toast } from 'sonner'; export default function Response() { const { response, clearResponse } = useResponse(); - useEffect(() => { switch (Number(response?.status)) { - case 201: toast.success(response.message); break; - case 422: toast.error(response.error, { description: response.detail, }); break; - case 400: toast.error(response.error, { description: response.message, }); break; - case 600: toast.error(response.error, { description: response.message, }); break; - - default: - if (response.status !== 0 && response.status !== 200 && response.status !== 201) { - toast.warning(JSON.stringify(response)); - } - break; } }, [response, clearResponse]); - return
; }