57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { getCustomer } from '@/actions/api/customers';
|
|
import { getSessionUser } from '@/actions/session';
|
|
import { Container } from '@/components/layout';
|
|
import { PageHeader } from '@/components/navigation';
|
|
import { ContactDataCard, PersonCard, ProfileOrdersList } from '@/components/profile';
|
|
import { BookButton } from '@/components/shared/book-button';
|
|
import { isCustomerMaster } from '@repo/utils/customer';
|
|
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
|
|
|
|
// Тип параметров страницы
|
|
type Props = { params: Promise<{ telegramId: string }> };
|
|
|
|
export default async function ProfilePage(props: Readonly<Props>) {
|
|
const { telegramId } = await props.params;
|
|
const contactTelegramId = Number(telegramId);
|
|
const queryClient = new QueryClient();
|
|
|
|
// Получаем профиль контакта
|
|
const { customer: profile } = await queryClient.fetchQuery({
|
|
queryFn: () => getCustomer({ telegramId: contactTelegramId }),
|
|
queryKey: ['customer', contactTelegramId],
|
|
});
|
|
|
|
// Получаем текущего пользователя
|
|
const sessionUser = await getSessionUser();
|
|
const { customer: currentUser } = await queryClient.fetchQuery({
|
|
queryFn: () => getCustomer({ telegramId: sessionUser.telegramId }),
|
|
queryKey: ['customer', sessionUser.telegramId],
|
|
});
|
|
|
|
// Проверка наличия данных
|
|
if (!profile || !currentUser) return null;
|
|
|
|
// Определяем роли и id
|
|
const isMaster = isCustomerMaster(currentUser);
|
|
const masterId = isMaster ? currentUser.documentId : profile.documentId;
|
|
const clientId = isMaster ? profile.documentId : currentUser.documentId;
|
|
|
|
return (
|
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
|
<PageHeader title="Профиль контакта" />
|
|
<Container className="px-0">
|
|
<PersonCard telegramId={contactTelegramId} />
|
|
<ContactDataCard telegramId={contactTelegramId} />
|
|
<ProfileOrdersList telegramId={contactTelegramId} />
|
|
{masterId && clientId && (
|
|
<BookButton
|
|
clientId={clientId}
|
|
label={isMaster ? 'Записать' : 'Записаться'}
|
|
masterId={masterId}
|
|
/>
|
|
)}
|
|
</Container>
|
|
</HydrationBoundary>
|
|
);
|
|
}
|