diff --git a/apps/web/app/(main)/profile/[telegramId]/page.tsx b/apps/web/app/(main)/profile/[telegramId]/page.tsx index 8f440d5..ead4f58 100644 --- a/apps/web/app/(main)/profile/[telegramId]/page.tsx +++ b/apps/web/app/(main)/profile/[telegramId]/page.tsx @@ -3,6 +3,7 @@ import { getSessionUser } from '@/actions/session'; import { Container } from '@/components/layout'; import { PageHeader } from '@/components/navigation'; import { ContactDataCard, PersonCard, ProfileOrdersList } from '@/components/profile'; +import { MasterServicesList } from '@/components/profile/services'; import { BookButton } from '@/components/shared/book-button'; import { isCustomerMaster } from '@repo/utils/customer'; import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query'; @@ -33,6 +34,7 @@ export default async function ProfilePage(props: Readonly) { // Определяем роли и id const isMaster = isCustomerMaster(currentUser); + const isProfileMaster = isCustomerMaster(profile); const masterId = isMaster ? currentUser.documentId : profile.documentId; const clientId = isMaster ? profile.documentId : currentUser.documentId; @@ -42,6 +44,7 @@ export default async function ProfilePage(props: Readonly) { + {isProfileMaster && } {masterId && clientId && ( ) { + const { isLoading, services } = useMasterServices(masterId); - if (isLoading || !customer) return null; + if (isLoading) return ; + + if (!services?.length) return null; return ( -
+
+

Услуги

+ {services?.map( + (service) => + service?.active && ( +
+ +
+ ), + )} +
+ ); +} + +// Компонент для отображения услуг текущего пользователя (с ссылками) +export function ServicesList() { + const { isLoading, services } = useMasterServices(); + + if (isLoading) return null; + + if (!services?.length) return null; + + return ( +
{services?.map( (service) => service && ( @@ -35,3 +56,27 @@ export function ServicesList() {
); } + +// Общий хук для получения услуг мастера +function useMasterServices(masterId?: string) { + const { data: { customer } = {}, isLoading } = useCustomerQuery(); + + // Используем переданный masterId или текущего пользователя + const targetMasterId = masterId || customer?.documentId; + + const { data: { services } = {} } = useServicesQuery({ + filters: { + master: { + documentId: { + eq: targetMasterId, + }, + }, + }, + }); + + return { + isLoading: isLoading || !targetMasterId, + masterId: targetMasterId, + services, + }; +}