contacts: loading spinner

This commit is contained in:
vchikalkin 2025-01-20 17:29:05 +03:00
parent 21b2e983eb
commit d15f42de1a
2 changed files with 7 additions and 5 deletions

View File

@ -30,9 +30,11 @@ const ContactRow = memo(function ({ contact }: ContactRowProps) {
});
export function ContactsList() {
const { contacts } = useCustomerContacts();
const { contacts, isLoading } = useCustomerContacts();
if (!contacts.length) return <LoadingSpinner />;
if (isLoading) return <LoadingSpinner />;
if (!contacts.length) return <div>Контакты не найдены</div>;
return (
<div className="space-y-2">

View File

@ -8,14 +8,14 @@ import { use, useMemo } from 'react';
export function useCustomerContacts() {
const { filter } = use(ContactsFilterContext);
const { data: clientsData } = useQuery({
const { data: clientsData, isLoading: isLoadingClients } = useQuery({
queryFn: getClients,
queryKey: ['contacts', 'clients'],
});
const clients = clientsData?.clients;
const { data: mastersData } = useQuery({
const { data: mastersData, isLoading: isLoadingMasters } = useQuery({
queryFn: getMasters,
queryKey: ['contacts', 'masters'],
});
@ -33,5 +33,5 @@ export function useCustomerContacts() {
}
}, [clients, masters, filter]);
return { contacts };
return { contacts, isLoading: isLoadingClients || isLoadingMasters };
}