vchikalkin 78e45718a8 refactor(contacts): consolidate customer queries and enhance contact handling
- Replaced use of useCustomersInfiniteQuery with a new useContactsInfiniteQuery hook for improved data fetching.
- Simplified ContactsList and MastersGrid components by removing unnecessary customer documentId filters.
- Deleted outdated contact-related hooks and queries to streamline the codebase.
- Enhanced loading state management across components for better user experience.
2025-09-10 13:44:43 +03:00

41 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { DataNotFound } from '../shared/alert';
import { ContactRow } from '../shared/contact-row';
import { useContactsInfiniteQuery } from '@/hooks/api/customers';
import { Button } from '@repo/ui/components/ui/button';
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
export function ContactsList() {
const {
data: { pages } = {},
fetchNextPage,
hasNextPage,
isLoading,
} = useContactsInfiniteQuery();
const contacts = pages?.flatMap((page) => page.customers);
return (
<div className="flex flex-col space-y-2">
{isLoading && <LoadingSpinner />}
{!isLoading && !contacts?.length ? <DataNotFound title="Контакты не найдены" /> : null}
{contacts?.map(
(contact) =>
contact && (
<ContactRow
description={contact.services.map((service) => service?.name).join(', ')}
key={contact.documentId}
{...contact}
/>
),
)}
{hasNextPage && (
<Button onClick={() => fetchNextPage()} variant="ghost">
Загрузить еще
</Button>
)}
</div>
);
}