vchikalkin 106fdc0da5 refactor(profile): simplify profile page structure and enhance loading states
- Removed unnecessary data fetching and hydration logic from the main profile page.
- Updated the rendering of components to improve clarity and performance.
- Enhanced loading states in various profile components for better user experience.
- Refactored service list handling to utilize telegramId instead of masterId for consistency.
2025-09-18 14:02:10 +03:00

75 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { type ProfileProps } from '../types';
import { DataNotFound } from '@/components/shared/alert';
import { ServiceCard } from '@/components/shared/service-card';
import { useCustomerQuery } from '@/hooks/api/customers';
import { useServicesQuery } from '@/hooks/api/services';
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
import Link from 'next/link';
// Компонент для отображения услуг мастера (без ссылок, только просмотр)
export function ReadonlyServicesList({ telegramId }: Readonly<ProfileProps>) {
const { isLoading, services } = useServices(telegramId);
return (
<div className="space-y-2 px-4">
<h1 className="font-bold">Услуги</h1>
{isLoading && <LoadingSpinner />}
{!isLoading && !services?.length ? <DataNotFound title="Услуги не найдены" /> : null}
{services?.map(
(service) =>
service?.active && (
<div key={service.documentId}>
<ServiceCard {...service} />
</div>
),
)}
</div>
);
}
// Компонент для отображения услуг текущего пользователя (с ссылками)
export function ServicesList() {
const { isLoading, services } = useServices();
return (
<div className="space-y-2 px-4">
{isLoading && <LoadingSpinner />}
{!isLoading && !services?.length ? <DataNotFound title="Услуги не найдены" /> : null}
{services?.map(
(service) =>
service && (
<div key={service.documentId}>
<Link href={`/profile/services/${service.documentId}`}>
<ServiceCard key={service.documentId} {...service} />
</Link>
</div>
),
)}
</div>
);
}
function useServices(telegramId?: Readonly<ProfileProps>['telegramId']) {
const { data: { customer } = {}, isLoading: isLoadingCustomer } = useCustomerQuery();
// Используем переданный masterId или текущего пользователя
const targetTelegramId = telegramId || customer?.telegramId;
const { data: { services } = {}, isLoading: isLoadingServices } = useServicesQuery({
filters: {
master: {
telegramId: {
eq: targetTelegramId,
},
},
},
});
return {
isLoading: isLoadingCustomer || isLoadingServices,
services,
};
}