zapishis-client/apps/web/components/profile/profile-buttons.tsx
vchikalkin 9244eaec26
2025-10-07 11:25:59 +03:00

95 lines
2.8 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 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';
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 handleBookAsClient = () => {
push('/orders/add', {
client: currentUser,
slot: { master: profile },
});
};
const handleBookAsMaster = () => {
push('/orders/add', {
client: profile,
slot: { master: currentUser },
});
};
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>
</>
);
}