fix(details): corrige erro de id null (RETURNING id) e implementa navegação baseada em rotas (/patient/:patientName)
continuous-integration/webhook Deploy concluído (VPS4)
continuous-integration/webhook Deploy concluído (VPS4)
This commit is contained in:
@@ -34,6 +34,12 @@ export default function App() {
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
|
||||
<Route path="/patient/:patientName" element={
|
||||
<ProtectedRoute>
|
||||
<DashboardPage />
|
||||
</ProtectedRoute>
|
||||
} />
|
||||
|
||||
{/* Rotas de administrador */}
|
||||
<Route path="/clients" element={
|
||||
<AdminRoute>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { useNavigate, useSearchParams, useParams } from 'react-router-dom';
|
||||
import api from '../api/client';
|
||||
import { useSocket } from '../contexts/SocketContext';
|
||||
import { useToast } from '../contexts/ToastContext';
|
||||
@@ -33,6 +33,7 @@ export default function DashboardPage() {
|
||||
const { on, off } = useSocket();
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
const { patientName: urlPatientName } = useParams();
|
||||
|
||||
// View state: 'patients' | 'patient-images'
|
||||
const [view, setView] = useState('patients');
|
||||
@@ -95,11 +96,15 @@ export default function DashboardPage() {
|
||||
}, 300);
|
||||
}, [searchParams]);
|
||||
|
||||
// ── URL query patient (abre a pasta de RX do paciente se informado) ──
|
||||
// ── URL path patient (abre a pasta de RX do paciente se informado no path) ──
|
||||
useEffect(() => {
|
||||
const patientName = searchParams.get('patient');
|
||||
if (!patientName) return;
|
||||
if (!urlPatientName) {
|
||||
setView('patients');
|
||||
setSelectedPatient(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const patientName = decodeURIComponent(urlPatientName);
|
||||
const loadQueryPatient = async () => {
|
||||
try {
|
||||
const { data } = await api.get(`/images/patients?search=${encodeURIComponent(patientName)}&limit=10`);
|
||||
@@ -123,8 +128,7 @@ export default function DashboardPage() {
|
||||
};
|
||||
|
||||
loadQueryPatient();
|
||||
navigate('/', { replace: true });
|
||||
}, [searchParams]);
|
||||
}, [urlPatientName]);
|
||||
|
||||
// ── Socket.IO: nova imagem em tempo real ──────────────────────────
|
||||
useEffect(() => {
|
||||
@@ -228,15 +232,11 @@ export default function DashboardPage() {
|
||||
};
|
||||
|
||||
const openPatient = (patient) => {
|
||||
setSelectedPatient(patient);
|
||||
setView('patient-images');
|
||||
loadPatientImages(patient.patient_name);
|
||||
navigate('/patient/' + encodeURIComponent(patient.patient_name));
|
||||
};
|
||||
|
||||
const goBack = () => {
|
||||
setView('patients');
|
||||
setSelectedPatient(null);
|
||||
loadPatients();
|
||||
navigate('/');
|
||||
};
|
||||
|
||||
// ── Toggle image enabled ──────────────────────────────────────────
|
||||
|
||||
@@ -183,7 +183,7 @@ export default function ImageDetailsPage() {
|
||||
rotation: 0, flipH: false, flipV: false, remark: ''
|
||||
});
|
||||
showToast('Imagem restaurada para o original!', 'success');
|
||||
navigate('/?patient=' + encodeURIComponent(patientName));
|
||||
navigate('/patient/' + encodeURIComponent(patientName));
|
||||
} catch {
|
||||
showToast('Erro ao restaurar a imagem.', 'error');
|
||||
} finally {
|
||||
@@ -337,7 +337,7 @@ export default function ImageDetailsPage() {
|
||||
{/* Top Header para navegação / Voltar */}
|
||||
<header className="header" style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 12, width: '100%' }}>
|
||||
<button className="btn btn-secondary" onClick={() => navigate('/?patient=' + encodeURIComponent(patientName))} style={{ padding: '8px 12px' }} title="Voltar ao Painel">
|
||||
<button className="btn btn-secondary" onClick={() => navigate('/patient/' + encodeURIComponent(patientName))} style={{ padding: '8px 12px' }} title="Voltar ao Painel">
|
||||
{isMobile ? '←' : '← Voltar'}
|
||||
</button>
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
|
||||
@@ -403,7 +403,7 @@ router.post('/:id/transform', async (req, res) => {
|
||||
`INSERT INTO images (
|
||||
image_guid, patient_name, clinic_name, client_name, original_filename, filename,
|
||||
enabled, rotation, flip_horizontal, flip_vertical, original_image_id, created_at, remark, doctor
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)`,
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING id`,
|
||||
[
|
||||
`${realOriginal.image_guid}_${timestamp}`,
|
||||
realOriginal.patient_name,
|
||||
|
||||
Reference in New Issue
Block a user