vchikalkin 5dfef524e2 refactor(contact): remove customer master role checks and simplify contact addition
- Updated the `addContact` function to allow all users to add contacts, removing the previous restriction that only masters could do so.
- Deleted the `become-master` feature and related utility functions, streamlining the codebase.
- Adjusted command settings to reflect the removal of the master role functionality.
- Refactored components and hooks to eliminate dependencies on the master role, enhancing user experience and simplifying logic.
2025-09-08 12:51:35 +03:00

55 lines
1.9 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 { OrderCard } from '../shared/order-card';
import { type ProfileProps } from './types';
import { useCustomerQuery } from '@/hooks/api/customers';
import { useOrdersInfiniteQuery } from '@/hooks/api/orders';
import { Button } from '@repo/ui/components/ui/button';
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
export function ProfileOrdersList({ telegramId }: Readonly<ProfileProps>) {
const { data: { customer } = {} } = useCustomerQuery();
const { data: { customer: profile } = {} } = useCustomerQuery({ telegramId });
const {
data: { pages } = {},
fetchNextPage,
hasNextPage,
isLoading,
} = useOrdersInfiniteQuery(
{
filters: {
// Показываем все записи между текущим пользователем и профилем
or: [
{
client: { documentId: { eq: customer?.documentId } },
slot: { master: { documentId: { eq: profile?.documentId } } },
},
{
client: { documentId: { eq: profile?.documentId } },
slot: { master: { documentId: { eq: customer?.documentId } } },
},
],
},
},
{ enabled: Boolean(profile?.documentId) && Boolean(customer?.documentId) },
);
const orders = pages?.flatMap((page) => page.orders) ?? [];
return (
<div className="flex flex-col space-y-2 px-4">
<h1 className="font-bold">Недавние записи</h1>
{isLoading && <LoadingSpinner />}
{!isLoading && !orders.length ? <DataNotFound title="Записи не найдены" /> : null}
{orders?.map((order) => order && <OrderCard key={order.documentId} showDate {...order} />)}
{hasNextPage && (
<Button onClick={() => fetchNextPage()} variant="ghost">
Загрузить еще
</Button>
)}
</div>
);
}