From a1af00af695793dcc7ec9c7a8c11d62a15eb8a5d Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Sat, 11 Oct 2025 14:09:18 +0300 Subject: [PATCH] feat: allow order with inactive contacts --- .../orders/order-form/contacts-grid.tsx | 19 ++++++------ apps/web/components/shared/contact-row.tsx | 31 ++++++++++++++----- packages/graphql/api/orders.ts | 9 +++--- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/apps/web/components/orders/order-form/contacts-grid.tsx b/apps/web/components/orders/order-form/contacts-grid.tsx index 2d7345c..d511fb6 100644 --- a/apps/web/components/orders/order-form/contacts-grid.tsx +++ b/apps/web/components/orders/order-form/contacts-grid.tsx @@ -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), + ), }; } diff --git a/apps/web/components/shared/contact-row.tsx b/apps/web/components/shared/contact-row.tsx index b4c33f7..65b6026 100644 --- a/apps/web/components/shared/contact-row.tsx +++ b/apps/web/components/shared/contact-row.tsx @@ -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 ( + + {children} + + ); + } + + return <>{children}; +} + export const ContactRow = memo(function ({ className, description, ...contact }: ContactRowProps) { return ( - +
{contact.active ?
: Неактивен}
- + ); }); diff --git a/packages/graphql/api/orders.ts b/packages/graphql/api/orders.ts index 4278f36..7b2bf95 100644 --- a/packages/graphql/api/orders.ts +++ b/packages/graphql/api/orders.ts @@ -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;