diff --git a/frontend/services/backend.ts b/frontend/services/backend.ts index 4ba73ce..f2ba336 100644 --- a/frontend/services/backend.ts +++ b/frontend/services/backend.ts @@ -201,9 +201,11 @@ export const HybridBackend = { return true; }, - getPacientes: async (termo: string = ''): Promise<{ data: Paciente[]; total: number }> => { - const url = termo.trim() ? `${API_URL}/pacientes?q=${encodeURIComponent(termo)}` : `${API_URL}/pacientes`; - const res = await apiFetch(url); + getPacientes: async (termo: string = '', sort: string = 'recentes'): Promise<{ data: Paciente[]; total: number }> => { + const params = new URLSearchParams(); + if (termo.trim()) params.set('q', termo.trim()); + if (sort) params.set('sort', sort); + const res = await apiFetch(`${API_URL}/pacientes?${params}`); return res.json(); }, diff --git a/frontend/views/PatientsView.tsx b/frontend/views/PatientsView.tsx index 6ce9832..0a8ee8f 100644 --- a/frontend/views/PatientsView.tsx +++ b/frontend/views/PatientsView.tsx @@ -399,12 +399,21 @@ const CopyField: React.FC<{ label: string; value?: string | null }> = ({ label, ); }; +type SortOpt = 'recentes' | 'az' | 'za' | 'convenio'; +const SORT_OPTS: { key: SortOpt; label: string }[] = [ + { key: 'recentes', label: 'Recentes' }, + { key: 'az', label: 'A→Z' }, + { key: 'za', label: 'Z→A' }, + { key: 'convenio', label: 'Convênio' }, +]; + export const PatientsView: React.FC = () => { const [busca, setBusca] = useState(''); + const [sort, setSort] = useState('recentes'); const debouncedBusca = useDebounce(busca, 500); - const fetcher = useCallback(() => HybridBackend.getPacientes(debouncedBusca), [debouncedBusca]); - const { data: result, isLoading, error, refresh } = useHybridBackend<{ data: Paciente[]; total: number }>(fetcher, [debouncedBusca]); + const fetcher = useCallback(() => HybridBackend.getPacientes(debouncedBusca, sort), [debouncedBusca, sort]); + const { data: result, isLoading, error, refresh } = useHybridBackend<{ data: Paciente[]; total: number }>(fetcher, [debouncedBusca, sort]); const pacientes = result?.data ?? []; const totalPacientes = result?.total ?? 0; @@ -467,60 +476,58 @@ export const PatientsView: React.FC = () => { -
-
- + {/* Search + sort bar */} +
+
+ setBusca(e.target.value.toUpperCase())} />
+
+ {SORT_OPTS.map(o => ( + + ))} +
-
-

- {busca - ? `RESULTADOS PARA "${busca}" (${pacientes.length})` - : `PACIENTES — exibindo ${pacientes.length} de ${totalPacientes} cadastrados` - } -

-
- -
+
{isLoading &&
CARREGANDO DADOS DO POSTGRESQL...
} {error &&
ERRO AO CARREGAR: {error.message}
} {displayedPacientes && displayedPacientes.map(p => ( -
-
- {/* Nome completo + convênio */} -
-

{p.nome}

+
+
+
+

{p.nome}

{p.convenio && ( - {p.convenio} + {p.convenio} )}
- - {/* Dados copiáveis */} -
+
- {p.email &&
}
- -
- -
-