* chore(docker): add healthcheck to service in docker-compose.yml and update deploy workflow to include docker compose down * refactor(orders): add useOrdersInfiniteQuery for improved pagination and add load more button in orders list components * refactor(graphql): remove NotifyService and related notification logic from orders and API, clean up unused dependencies * refactor(api): streamline customer, order, service, and slot actions by wrapping server functions with client action utility to rethrow error messages to client
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
'use client';
|
||
|
||
import { OrderCard } from '../shared/order-card';
|
||
import { type ProfileProps } from './types';
|
||
import { useCustomerQuery, useIsMaster } from '@/hooks/api/customers';
|
||
import { useOrdersInfiniteQuery } from '@/hooks/api/orders';
|
||
import { Button } from '@repo/ui/components/ui/button';
|
||
|
||
export function ProfileOrdersList({ telegramId }: Readonly<ProfileProps>) {
|
||
const { data: { customer } = {} } = useCustomerQuery();
|
||
const isMaster = useIsMaster();
|
||
|
||
const { data: { customer: profile } = {} } = useCustomerQuery({ telegramId });
|
||
|
||
const {
|
||
data: { pages } = {},
|
||
fetchNextPage,
|
||
hasNextPage,
|
||
isLoading,
|
||
} = useOrdersInfiniteQuery(
|
||
{
|
||
filters: {
|
||
client: {
|
||
documentId: {
|
||
eq: isMaster ? profile?.documentId : customer?.documentId,
|
||
},
|
||
},
|
||
slot: {
|
||
master: {
|
||
documentId: {
|
||
eq: isMaster ? customer?.documentId : profile?.documentId,
|
||
},
|
||
},
|
||
},
|
||
},
|
||
},
|
||
{ enabled: Boolean(profile?.documentId) && Boolean(customer?.documentId) },
|
||
);
|
||
|
||
const orders = pages?.flatMap((page) => page.orders) ?? [];
|
||
|
||
if (!orders?.length || isLoading) return null;
|
||
|
||
return (
|
||
<div className="flex flex-col space-y-2 px-4">
|
||
<h1 className="font-bold">Недавние записи</h1>
|
||
{orders?.map(
|
||
(order) =>
|
||
order && (
|
||
<OrderCard
|
||
avatarSource={isMaster ? 'master' : 'client'}
|
||
key={order.documentId}
|
||
showDate
|
||
{...order}
|
||
/>
|
||
),
|
||
)}
|
||
{hasNextPage && (
|
||
<Button onClick={() => fetchNextPage()} variant="ghost">
|
||
Загрузить еще
|
||
</Button>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|