improvement: appointment dialog UX improved.
This commit is contained in:
@@ -14,7 +14,12 @@ export const patientsApi = {
|
||||
},
|
||||
|
||||
create: async (data: CreatePatientInput): Promise<CreatePatientResponse> => {
|
||||
const response = await apiClient.post('/patients', data);
|
||||
const { email, ...rest } = data;
|
||||
const body = {
|
||||
...rest,
|
||||
...(email?.trim() ? { email: email.trim() } : {}),
|
||||
};
|
||||
const response = await apiClient.post('/patients', body);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
|
||||
45
frontend/src/lib/hooks/usePatientSearchQuery.ts
Normal file
45
frontend/src/lib/hooks/usePatientSearchQuery.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { patientsApi } from '@/lib/api/patients';
|
||||
import { useAuth } from '@/lib/hooks/useAuth';
|
||||
import type { Patient } from '@/types/patient';
|
||||
|
||||
/** Debounced patient search — only queries when `search` is non-empty. */
|
||||
export function usePatientSearchQuery(enabled = true) {
|
||||
const { currentOrganization } = useAuth();
|
||||
const [search, setSearch] = useState('');
|
||||
const [patients, setPatients] = useState<Patient[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled || !currentOrganization) {
|
||||
return;
|
||||
}
|
||||
|
||||
const trimmed = search.trim();
|
||||
if (!trimmed) {
|
||||
setPatients([]);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
void (async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await patientsApi.list({ q: trimmed, page: 1, limit: 25 });
|
||||
setPatients(response.data.items ?? []);
|
||||
} catch {
|
||||
setPatients([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
})();
|
||||
}, 300);
|
||||
|
||||
return () => clearTimeout(timeout);
|
||||
}, [search, enabled, currentOrganization]);
|
||||
|
||||
return { search, setSearch, patients, loading };
|
||||
}
|
||||
Reference in New Issue
Block a user