zapishis-client/apps/web/components/profile/profile-buttons.tsx
vchikalkin b88ac07ba3 refactor: simplify profile button logic and remove unused components
- Consolidated booking logic into a single handleBook function based on customer role.
- Removed unused Drawer and Button components to streamline the ProfileButtons component.
- Added loading state handling for improved user experience.
2025-10-12 09:03:30 +03:00

36 lines
1.1 KiB
TypeScript

/* eslint-disable canonical/id-match */
'use client';
import FloatingActionPanel from '@/components/shared/action-panel';
import { useCustomerQuery } from '@/hooks/api/customers';
import { usePushWithData } from '@/hooks/url';
import { Enum_Customer_Role } from '@repo/graphql/types';
type QuickAppointmentProps = {
readonly telegramId: number;
};
export function ProfileButtons({ telegramId }: Readonly<QuickAppointmentProps>) {
const push = usePushWithData();
const { data: { customer: profile } = {}, isLoading: isLoadingProfile } = useCustomerQuery({
telegramId,
});
const { data: { customer: currentUser } = {}, isLoading: isLoadingCurrentUser } =
useCustomerQuery();
const isLoading = isLoadingProfile || isLoadingCurrentUser;
const handleBook = () => {
if (profile?.role === Enum_Customer_Role.Client) {
push('/orders/add', { client: profile, slot: { master: currentUser } });
} else {
push('/orders/add', { client: currentUser, slot: { master: profile } });
}
};
if (!telegramId) return null;
return <FloatingActionPanel isLoading={isLoading} onQuickBook={handleBook} />;
}