feat: allow order with inactive contacts

This commit is contained in:
vchikalkin 2025-10-11 14:09:18 +03:00
parent 311f6c183d
commit a1af00af69
3 changed files with 39 additions and 20 deletions

View File

@ -26,8 +26,12 @@ type ContactsGridProps = {
readonly title: string;
};
type UseContactsProps = Partial<{
showInactive: boolean;
}>;
export function ClientsGrid() {
const { contacts, fetchNextPage, hasNextPage, isLoading } = useContacts();
const { contacts, fetchNextPage, hasNextPage, isLoading } = useContacts({ showInactive: true });
const clientId = useOrderStore((store) => store.clientId);
const setClientId = useOrderStore((store) => store.setClientId);
@ -145,7 +149,7 @@ export function MastersGrid() {
);
}
function useContacts() {
function useContacts({ showInactive = false }: UseContactsProps = {}) {
const { data: { customer } = {}, isLoading: isLoadingCustomer } = useCustomerQuery();
const {
@ -156,16 +160,13 @@ function useContacts() {
const isLoading = isLoadingContacts || isLoadingCustomer;
const contacts = sift(
pages.flatMap((page) => page.customers).filter((contact) => Boolean(contact && contact.active)),
);
const contacts = sift(pages.flatMap((page) => page.customers));
return {
isLoading,
...query,
contacts: [
{ ...customer, name: 'Я', surname: undefined } as CustomerFieldsFragment,
...contacts,
],
contacts: [{ ...customer, name: 'Я', surname: undefined } as CustomerFieldsFragment].concat(
showInactive ? contacts : contacts.filter((contact) => contact.active),
),
};
}

View File

@ -4,7 +4,7 @@ import { Badge } from '@repo/ui/components/ui/badge';
import { cn } from '@repo/ui/lib/utils';
import { getCustomerFullName } from '@repo/utils/customer';
import Link from 'next/link';
import { memo } from 'react';
import { memo, type PropsWithChildren } from 'react';
type ContactRowProps = GQL.CustomerFieldsFragment & {
readonly className?: string;
@ -12,13 +12,30 @@ type ContactRowProps = GQL.CustomerFieldsFragment & {
readonly showServices?: boolean;
};
function Wrapper({
children,
contact,
}: PropsWithChildren<{ readonly contact: GQL.CustomerFieldsFragment }>) {
const isActive = contact.active && contact.telegramId;
if (isActive) {
return (
<Link
className="block"
href={contact.active ? `/profile/${contact.telegramId}` : ''}
key={contact.telegramId}
>
{children}
</Link>
);
}
return <>{children}</>;
}
export const ContactRow = memo(function ({ className, description, ...contact }: ContactRowProps) {
return (
<Link
className="block"
href={contact.active ? `/profile/${contact.telegramId}` : ''}
key={contact.telegramId}
>
<Wrapper contact={contact}>
<div
className={cn(
'flex items-center justify-between',
@ -37,6 +54,6 @@ export const ContactRow = memo(function ({ className, description, ...contact }:
</div>
{contact.active ? <div /> : <Badge variant="destructive">Неактивен</Badge>}
</div>
</Link>
</Wrapper>
);
});

View File

@ -1,3 +1,4 @@
/* eslint-disable sonarjs/no-commented-code */
/* eslint-disable sonarjs/cognitive-complexity */
/* eslint-disable @typescript-eslint/naming-convention */
import { ERRORS as SHARED_ERRORS } from '../constants/errors';
@ -283,10 +284,10 @@ export class OrdersService extends BaseService {
if (!clientEntity) throw new Error(ERRORS.NOT_FOUND_CLIENT);
// Проверка активности клиента
if (!clientEntity?.active) {
throw new Error(ERRORS.INACTIVE_CLIENT);
}
// // Проверка активности клиента
// if (!clientEntity?.active) {
// throw new Error(ERRORS.INACTIVE_CLIENT);
// }
// Получаем мастера слота
const slotMaster = slot.master;