improvement: appointment dialog UX improved.

This commit is contained in:
2026-07-12 22:07:11 +03:30
parent 53b43f2cdb
commit abf0371a5b
18 changed files with 1006 additions and 759 deletions

View File

@@ -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;
},

View 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 };
}