- Updated the `addContact` function to allow all users to add contacts, removing the previous restriction that only masters could do so. - Deleted the `become-master` feature and related utility functions, streamlining the codebase. - Adjusted command settings to reflect the removal of the master role functionality. - Refactored components and hooks to eliminate dependencies on the master role, enhancing user experience and simplifying logic.
78 lines
2.4 KiB
TypeScript
78 lines
2.4 KiB
TypeScript
'use client';
|
||
|
||
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';
|
||
|
||
type MasterServicesListProps = {
|
||
masterId: string;
|
||
};
|
||
|
||
// Компонент для отображения услуг мастера (без ссылок, только просмотр)
|
||
export function ReadonlyServicesList({ masterId }: Readonly<MasterServicesListProps>) {
|
||
const { isLoading, services } = useServices(masterId);
|
||
|
||
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(masterId?: string) {
|
||
const { data: { customer } = {}, isLoading: isLoadingCustomer } = useCustomerQuery();
|
||
|
||
// Используем переданный masterId или текущего пользователя
|
||
const targetMasterId = masterId || customer?.documentId;
|
||
|
||
const { data: { services } = {}, isLoading: isLoadingServices } = useServicesQuery({
|
||
filters: {
|
||
master: {
|
||
documentId: {
|
||
eq: targetMasterId,
|
||
},
|
||
},
|
||
},
|
||
});
|
||
|
||
return {
|
||
isLoading: isLoadingCustomer || isLoadingServices,
|
||
services,
|
||
};
|
||
}
|