calculo: fix pensaoalimenticia
Signed-off-by: Rodrigo B. de Sousa Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
c37a0461bf
commit
866a3fe539
3 files changed
+24
-9
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams, useNavigate } from 'react-router-dom'; // Adicionar useNavigate
|
||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
import api from '../../services/api';
|
import api from '../../services/api';
|
||||||
|
|
||||||
@@ -27,17 +27,18 @@ interface CalculoPensao {
|
|||||||
|
|
||||||
export function DetalhePensaoAlimenticia() {
|
export function DetalhePensaoAlimenticia() {
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
|
const navigate = useNavigate(); // Adicionar hook de navegação
|
||||||
const [calculo, setCalculo] = useState<CalculoPensao | null>(null);
|
const [calculo, setCalculo] = useState<CalculoPensao | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadCalculo = async () => {
|
const loadCalculo = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await api.get(`/pensao-alimenticia/${id}`);
|
const response = await api.get(`/api/pensao-alimenticia/${id}`);
|
||||||
setCalculo(response.data);
|
setCalculo(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erro ao carregar cálculo:', error);
|
console.error('Erro ao carregar cálculo:', error);
|
||||||
toast.error('Falha ao carregar dados do cálculo');
|
setCalculo(null); // Não exibir erro, apenas não mostrar cálculo
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -51,7 +52,17 @@ export function DetalhePensaoAlimenticia() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!calculo) {
|
if (!calculo) {
|
||||||
return <div>Cálculo não encontrado</div>;
|
return (
|
||||||
|
<div className="bg-white shadow-md rounded-lg p-6 flex flex-col items-center">
|
||||||
|
<div className="text-lg mb-4 text-gray-700">Nenhum cálculo de pensão alimentícia encontrado.</div>
|
||||||
|
<button
|
||||||
|
className="px-4 py-2 bg-blue-600 text-white rounded-md shadow hover:bg-blue-700"
|
||||||
|
onClick={() => navigate('/pensao-alimenticia/novo')}
|
||||||
|
>
|
||||||
|
Criar novo cálculo
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -90,6 +101,15 @@ export function DetalhePensaoAlimenticia() {
|
|||||||
<p className="text-gray-700">{calculo.observacoes}</p>
|
<p className="text-gray-700">{calculo.observacoes}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className="mt-8 flex justify-end">
|
||||||
|
<button
|
||||||
|
className="px-4 py-2 bg-blue-600 text-white rounded-md shadow hover:bg-blue-700"
|
||||||
|
onClick={() => navigate('/pensao-alimenticia/novo')}
|
||||||
|
>
|
||||||
|
Criar novo cálculo
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -83,11 +83,9 @@ router.get('/:id', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
const calculo = await calculoService.buscarCalculo(id);
|
const calculo = await calculoService.buscarCalculo(id);
|
||||||
|
|
||||||
if (!calculo) {
|
if (!calculo) {
|
||||||
return res.status(404).json({ error: 'Cálculo não encontrado' });
|
return res.status(404).json({ error: 'Cálculo não encontrado' });
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(calculo);
|
res.json(calculo);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erro ao buscar cálculo:', error);
|
console.error('Erro ao buscar cálculo:', error);
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ router.post('/', async (req, res) => {
|
|||||||
router.get('/:id', async (req, res) => {
|
router.get('/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
const calculo = await prisma.calculoPensaoAlimenticia.findUnique({
|
const calculo = await prisma.calculoPensaoAlimenticia.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
include: {
|
include: {
|
||||||
@@ -70,11 +69,9 @@ router.get('/:id', async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!calculo) {
|
if (!calculo) {
|
||||||
return res.status(404).json({ error: 'Cálculo não encontrado' });
|
return res.status(404).json({ error: 'Cálculo não encontrado' });
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(calculo);
|
res.json(calculo);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erro ao buscar cálculo:', error);
|
console.error('Erro ao buscar cálculo:', error);
|
||||||
|
|||||||
Reference in new issue
Block a user