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';
|
'use client';
|
||||||
|
|
||||||
import FloatingActionPanel from '@/components/shared/action-panel';
|
import FloatingActionPanel from '@/components/shared/action-panel';
|
||||||
import { useCustomerQuery } from '@/hooks/api/customers';
|
import { useCustomerQuery } from '@/hooks/api/customers';
|
||||||
import { usePushWithData } from '@/hooks/url';
|
import { usePushWithData } from '@/hooks/url';
|
||||||
import { Button } from '@repo/ui/components/ui/button';
|
import { Enum_Customer_Role } from '@repo/graphql/types';
|
||||||
import {
|
|
||||||
Drawer,
|
|
||||||
DrawerClose,
|
|
||||||
DrawerContent,
|
|
||||||
DrawerDescription,
|
|
||||||
DrawerFooter,
|
|
||||||
DrawerHeader,
|
|
||||||
DrawerTitle,
|
|
||||||
DrawerTrigger,
|
|
||||||
} from '@repo/ui/components/ui/drawer';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
type QuickAppointmentProps = {
|
type QuickAppointmentProps = {
|
||||||
readonly telegramId: number;
|
readonly telegramId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ProfileButtons({ telegramId }: Readonly<QuickAppointmentProps>) {
|
export function ProfileButtons({ telegramId }: Readonly<QuickAppointmentProps>) {
|
||||||
const [isPanelOpen, setIsPanelOpen] = useState(false);
|
|
||||||
const push = usePushWithData();
|
const push = usePushWithData();
|
||||||
|
|
||||||
const { data: { customer: profile } = {} } = useCustomerQuery({ telegramId });
|
const { data: { customer: profile } = {}, isLoading: isLoadingProfile } = useCustomerQuery({
|
||||||
const { data: { customer: currentUser } = {} } = useCustomerQuery();
|
telegramId,
|
||||||
|
|
||||||
const handleBookAsClient = () => {
|
|
||||||
push('/orders/add', {
|
|
||||||
client: currentUser,
|
|
||||||
slot: { master: profile },
|
|
||||||
});
|
});
|
||||||
};
|
const { data: { customer: currentUser } = {}, isLoading: isLoadingCurrentUser } =
|
||||||
|
useCustomerQuery();
|
||||||
|
|
||||||
const handleBookAsMaster = () => {
|
const isLoading = isLoadingProfile || isLoadingCurrentUser;
|
||||||
push('/orders/add', {
|
|
||||||
client: profile,
|
const handleBook = () => {
|
||||||
slot: { master: currentUser },
|
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;
|
if (!telegramId) return null;
|
||||||
|
|
||||||
return (
|
return <FloatingActionPanel isLoading={isLoading} onQuickBook={handleBook} />;
|
||||||
<>
|
|
||||||
<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>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user