- 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.
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
'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>
|
||
);
|
||
}
|