diff --git a/.gitignore b/.gitignore index ad6413d..674c347 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,4 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts -src/config/app.json +/src/config/app.json diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx index 847d1d2..cce2544 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx @@ -64,9 +64,6 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveGTBProfissao(formData); - // Encerra o fomulário - handleCloseForm(); - // Atualiza a lista de dados fetchGTBProfissao(); diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx index 740f76c..55af3da 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx @@ -64,13 +64,10 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveGTBRegimeComunhao(formData); - // Encerra o fomulário - handleCloseForm(); - // Atualiza a lista de dados fetchGTBRegimeComunhao(); - }, [saveGTBRegimeComunhao, fetchGTBRegimeComunhao, handleCloseForm]); + }, [saveGTBRegimeComunhao, fetchGTBRegimeComunhao]); /** * Quando o usuário clica em "remover" na tabela diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index 9d80a98..823afb8 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -63,14 +63,11 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveTTBAndamentoServico(formData); - - // Encerra o fomulário - handleCloseForm(); - + // Atualiza a lista de dados fetchTTBAndamentoServico(); - }, [saveTTBAndamentoServico, fetchTTBAndamentoServico, handleCloseForm]); + }, [saveTTBAndamentoServico, fetchTTBAndamentoServico]); /** * Quando o usuário clica em "remover" na tabela diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx index 6f66b36..8501ce9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -65,13 +65,10 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveTTBReconhecimentoTipo(formData); - // Encerra o fomulário - handleCloseForm(); - // Atualiza a lista de dados fetchTTBReconhecimentosTipos(); - }, [saveTTBReconhecimentoTipo, fetchTTBReconhecimentosTipos, handleCloseForm]); + }, [saveTTBReconhecimentoTipo, fetchTTBReconhecimentosTipos]); /** * Quando o usuário clica em "remover" na tabela diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx index 96f5104..ec7d5d1 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx @@ -63,6 +63,7 @@ export default function GTBProfissaoForm({ isOpen, data, onClose, onSave }: Prop }} > + Profissões diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts index d93edb3..74b9dd5 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts @@ -7,6 +7,8 @@ export const useGTBProfissaoSaveHook = () => { const { setResponse } = useResponse(); const [gTBProfissao, setGTBProfissao] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); const saveGTBProfissao = async (data: GTBProfissaoInterface) => { @@ -16,6 +18,12 @@ export const useGTBProfissaoSaveHook = () => { setResponse(response); + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + } return { gTBProfissao, saveGTBProfissao } diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts index f0d336e..b67690e 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts @@ -7,15 +7,25 @@ export const useGTBRegimeComunhaoSaveHook = () => { const { setResponse } = useResponse(); const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); const saveGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { const response = await GTBRegimeComunhaoSaveService(data); + // Guardar os dados localizados setGTBRegimeComunhao(response.data); + // Manda a resposta para o verificador de resposta setResponse(response); + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + } return { gTBRegimeComunhao, saveGTBRegimeComunhao } diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts index c5c1c37..43586da 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts @@ -11,6 +11,9 @@ export const useTTBAndamentoServicoSaveHook = () => { const [tTBAndamentoServico, setTTBAndamentoServico] = useState(); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + const saveTTBAndamentoServico = async (data: TTBAndamentoServicoInteface) => { const response = await TTBAndamentoServicoSaveData(data); @@ -21,6 +24,9 @@ export const useTTBAndamentoServicoSaveHook = () => { // Define os dados da respota(toast, modal, etc) setResponse(response); + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + // Retorna os valores de forma imediata return response.data; diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts index 48c60dd..88a88df 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts @@ -11,6 +11,9 @@ export const useTTBReconhecimentoTipoSaveHook = () => { const [tTBReconhecimentoTipo, setTTBReconhcimentoTipo] = useState(); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + const saveTTBReconhecimentoTipo = async (reconhecimentoTipo: ITTTBReconhecimentoTipo) => { const response = await TTBReconhecimentoTipoSaveData(reconhecimentoTipo); @@ -19,6 +22,9 @@ export const useTTBReconhecimentoTipoSaveHook = () => { setResponse(response); + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + // Retorna os valores de forma imediata return response.data; diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts index 034c23d..4d9e9b9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts @@ -5,6 +5,8 @@ export default async function GTProfissaoSaveService(data: GTBProfissaoInterface const response = await GTBProfissaoSaveData(data); + console.log('GTBRegimeComunhaoSaveData', response) + return response; } \ No newline at end of file diff --git a/src/app/(protected)/layout.tsx b/src/app/(protected)/layout.tsx index 0ca9fb4..1ab8b42 100644 --- a/src/app/(protected)/layout.tsx +++ b/src/app/(protected)/layout.tsx @@ -74,7 +74,7 @@ export default function RootLayout({
{children} - +
diff --git a/src/app/_response/ResponseContext.tsx b/src/app/_response/ResponseContext.tsx index f356b31..e4bb515 100644 --- a/src/app/_response/ResponseContext.tsx +++ b/src/app/_response/ResponseContext.tsx @@ -17,10 +17,10 @@ interface ResponseContextProps { const ResponseContext = createContext(undefined); export const ResponseProvider: React.FC<{ children: ReactNode }> = ({ children }) => { - const [response, setResponseState] = useState({ message: '', type: null, status : 0}); + const [response, setResponseState] = useState({ message: '', type: null, status: 0 }); const setResponse = (value: ResponseState) => setResponseState(value); - const clearResponse = () => setResponseState({ message: '', type: null, status : 0}); + const clearResponse = () => setResponseState({ message: '', type: null, status: 0 }); return ( diff --git a/src/app/_response/response.tsx b/src/app/_response/response.tsx index 4a6e245..4b62195 100644 --- a/src/app/_response/response.tsx +++ b/src/app/_response/response.tsx @@ -1,20 +1,41 @@ // app/src/app/_response/response.tsx "use client"; -import { useResponse } from "./ResponseContext"; -import { useEffect } from "react"; -import { toast } from "sonner"; +import { + useResponse +} from "./ResponseContext"; +import { + useEffect +} from "react"; +import { + toast +} from "sonner"; export default function Response() { - const { response, clearResponse } = useResponse(); + const { + response, + clearResponse + } = useResponse(); useEffect(() => { switch (Number(response?.status)) { - case 200: - toast(response.message); + case 201: + toast.success(response.message); + break; + + case 422: + toast.danger(response.error, { + description: response.detail + }); + break; + + default: + if (response.status !== 0 && response.status !== 200 && response.status !== 201) { + toast.warning(JSON.stringify(response)); + } break; } }, [response, clearResponse]); return
; -} +} \ No newline at end of file