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.
This commit is contained in:
parent
b517519e7e
commit
b88ac07ba3
@ -1,94 +1,35 @@
|
||||
/* 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 { Button } from '@repo/ui/components/ui/button';
|
||||
import {
|
||||
Drawer,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerDescription,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerTitle,
|
||||
DrawerTrigger,
|
||||
} from '@repo/ui/components/ui/drawer';
|
||||
import { useState } from 'react';
|
||||
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||
|
||||
type QuickAppointmentProps = {
|
||||
readonly telegramId: number;
|
||||
};
|
||||
|
||||
export function ProfileButtons({ telegramId }: Readonly<QuickAppointmentProps>) {
|
||||
const [isPanelOpen, setIsPanelOpen] = useState(false);
|
||||
const push = usePushWithData();
|
||||
|
||||
const { data: { customer: profile } = {} } = useCustomerQuery({ telegramId });
|
||||
const { data: { customer: currentUser } = {} } = useCustomerQuery();
|
||||
const { data: { customer: profile } = {}, isLoading: isLoadingProfile } = useCustomerQuery({
|
||||
telegramId,
|
||||
});
|
||||
const { data: { customer: currentUser } = {}, isLoading: isLoadingCurrentUser } =
|
||||
useCustomerQuery();
|
||||
|
||||
const handleBookAsClient = () => {
|
||||
push('/orders/add', {
|
||||
client: currentUser,
|
||||
slot: { master: profile },
|
||||
});
|
||||
};
|
||||
const isLoading = isLoadingProfile || isLoadingCurrentUser;
|
||||
|
||||
const handleBookAsMaster = () => {
|
||||
push('/orders/add', {
|
||||
client: profile,
|
||||
slot: { master: currentUser },
|
||||
});
|
||||
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 onQuickBook={() => setIsPanelOpen(true)} />
|
||||
<Drawer onOpenChange={setIsPanelOpen} open={isPanelOpen}>
|
||||
<DrawerTrigger asChild>
|
||||
<div />
|
||||
</DrawerTrigger>
|
||||
<DrawerContent>
|
||||
<div className="mx-auto w-full max-w-sm">
|
||||
<DrawerHeader>
|
||||
<DrawerTitle>Быстрая запись</DrawerTitle>
|
||||
<DrawerDescription>Выберите действие</DrawerDescription>
|
||||
</DrawerHeader>
|
||||
<div className="p-4 pt-0">
|
||||
<div className="flex flex-col gap-3">
|
||||
<DrawerClose asChild>
|
||||
<Button
|
||||
className="w-full text-sm"
|
||||
disabled={!profile || !currentUser}
|
||||
onClick={handleBookAsClient}
|
||||
size="sm"
|
||||
>
|
||||
Записаться к мастеру {profile?.name}
|
||||
</Button>
|
||||
</DrawerClose>
|
||||
<DrawerClose asChild>
|
||||
<Button
|
||||
className="w-full text-sm"
|
||||
disabled={!profile || !currentUser}
|
||||
onClick={handleBookAsMaster}
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
>
|
||||
Записать клиента к себе
|
||||
</Button>
|
||||
</DrawerClose>
|
||||
</div>
|
||||
</div>
|
||||
<DrawerFooter>
|
||||
<DrawerClose asChild>
|
||||
<Button variant="outline">Отмена</Button>
|
||||
</DrawerClose>
|
||||
</DrawerFooter>
|
||||
</div>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
</>
|
||||
);
|
||||
return <FloatingActionPanel isLoading={isLoading} onQuickBook={handleBook} />;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user