feat: allow order with inactive contacts
This commit is contained in:
parent
311f6c183d
commit
a1af00af69
@ -26,8 +26,12 @@ type ContactsGridProps = {
|
|||||||
readonly title: string;
|
readonly title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type UseContactsProps = Partial<{
|
||||||
|
showInactive: boolean;
|
||||||
|
}>;
|
||||||
|
|
||||||
export function ClientsGrid() {
|
export function ClientsGrid() {
|
||||||
const { contacts, fetchNextPage, hasNextPage, isLoading } = useContacts();
|
const { contacts, fetchNextPage, hasNextPage, isLoading } = useContacts({ showInactive: true });
|
||||||
|
|
||||||
const clientId = useOrderStore((store) => store.clientId);
|
const clientId = useOrderStore((store) => store.clientId);
|
||||||
const setClientId = useOrderStore((store) => store.setClientId);
|
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 { data: { customer } = {}, isLoading: isLoadingCustomer } = useCustomerQuery();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -156,16 +160,13 @@ function useContacts() {
|
|||||||
|
|
||||||
const isLoading = isLoadingContacts || isLoadingCustomer;
|
const isLoading = isLoadingContacts || isLoadingCustomer;
|
||||||
|
|
||||||
const contacts = sift(
|
const contacts = sift(pages.flatMap((page) => page.customers));
|
||||||
pages.flatMap((page) => page.customers).filter((contact) => Boolean(contact && contact.active)),
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isLoading,
|
isLoading,
|
||||||
...query,
|
...query,
|
||||||
contacts: [
|
contacts: [{ ...customer, name: 'Я', surname: undefined } as CustomerFieldsFragment].concat(
|
||||||
{ ...customer, name: 'Я', surname: undefined } as CustomerFieldsFragment,
|
showInactive ? contacts : contacts.filter((contact) => contact.active),
|
||||||
...contacts,
|
),
|
||||||
],
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { Badge } from '@repo/ui/components/ui/badge';
|
|||||||
import { cn } from '@repo/ui/lib/utils';
|
import { cn } from '@repo/ui/lib/utils';
|
||||||
import { getCustomerFullName } from '@repo/utils/customer';
|
import { getCustomerFullName } from '@repo/utils/customer';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { memo } from 'react';
|
import { memo, type PropsWithChildren } from 'react';
|
||||||
|
|
||||||
type ContactRowProps = GQL.CustomerFieldsFragment & {
|
type ContactRowProps = GQL.CustomerFieldsFragment & {
|
||||||
readonly className?: string;
|
readonly className?: string;
|
||||||
@ -12,13 +12,30 @@ type ContactRowProps = GQL.CustomerFieldsFragment & {
|
|||||||
readonly showServices?: boolean;
|
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) {
|
export const ContactRow = memo(function ({ className, description, ...contact }: ContactRowProps) {
|
||||||
return (
|
return (
|
||||||
<Link
|
<Wrapper contact={contact}>
|
||||||
className="block"
|
|
||||||
href={contact.active ? `/profile/${contact.telegramId}` : ''}
|
|
||||||
key={contact.telegramId}
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex items-center justify-between',
|
'flex items-center justify-between',
|
||||||
@ -37,6 +54,6 @@ export const ContactRow = memo(function ({ className, description, ...contact }:
|
|||||||
</div>
|
</div>
|
||||||
{contact.active ? <div /> : <Badge variant="destructive">Неактивен</Badge>}
|
{contact.active ? <div /> : <Badge variant="destructive">Неактивен</Badge>}
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable sonarjs/no-commented-code */
|
||||||
/* eslint-disable sonarjs/cognitive-complexity */
|
/* eslint-disable sonarjs/cognitive-complexity */
|
||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
import { ERRORS as SHARED_ERRORS } from '../constants/errors';
|
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) throw new Error(ERRORS.NOT_FOUND_CLIENT);
|
||||||
|
|
||||||
// Проверка активности клиента
|
// // Проверка активности клиента
|
||||||
if (!clientEntity?.active) {
|
// if (!clientEntity?.active) {
|
||||||
throw new Error(ERRORS.INACTIVE_CLIENT);
|
// throw new Error(ERRORS.INACTIVE_CLIENT);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Получаем мастера слота
|
// Получаем мастера слота
|
||||||
const slotMaster = slot.master;
|
const slotMaster = slot.master;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user