Vlad Chikalkin 7bcae12d54
Some checks failed
Build & Deploy Web & Bot / Build and Push to Docker Hub (push) Has been cancelled
Build & Deploy Web & Bot / Deploy to VPS (push) Has been cancelled
Fix/bugs after first release (#26)
* web/packages: upgrade next

* fix(api/orders): update master validation logic to handle optional masters

* fix(api/notify, api/orders): enhance notification messages and update order state handling for masters

* fix react typings

* refactor(order-buttons, action-panel): streamline button handlers and add return functionality

* fix(contacts, orders): replace empty state messages with DataNotFound component for better user feedback

* feat(bot): add share bot command and update environment configuration for BOT_URL

* fix: pnpm-lock.yaml

* feat(bot): implement add contact wizard scene and enhance contact handling logic

* feat(profile): add BookContactButton component to enhance booking functionality

* fix(order-buttons): update cancel and confirm button logic based on order state

* feat(service-select): share services list for all
enhance service card display with duration formatting and improve layout
2025-07-03 16:36:10 +03:00

63 lines
2.0 KiB
TypeScript

/* eslint-disable canonical/id-match */
'use client';
import FloatingActionPanel from '../shared/action-panel';
import { type OrderComponentProps } from './types';
import { useIsMaster } from '@/hooks/api/customers';
import { useOrderMutation, useOrderQuery } from '@/hooks/api/orders';
import { usePushWithData } from '@/hooks/url';
import { Enum_Order_State } from '@repo/graphql/types';
export function OrderButtons({ documentId }: Readonly<OrderComponentProps>) {
const push = usePushWithData();
const isMaster = useIsMaster();
const { data: { order } = {} } = useOrderQuery({ documentId });
const { isPending, mutate: updateSlot } = useOrderMutation({ documentId });
if (!order) return null;
const isCreated = order?.state === Enum_Order_State.Created;
const isApproved = order?.state === Enum_Order_State.Approved;
const isCompleted = order?.state === Enum_Order_State.Completed;
const isCancelling = order?.state === Enum_Order_State.Cancelling;
const isCancelled = order?.state === Enum_Order_State.Cancelled;
function handleApprove() {
if (isMaster) {
updateSlot({ data: { state: Enum_Order_State.Approved } });
}
}
function handleCancel() {
if (isMaster) {
updateSlot({ data: { state: Enum_Order_State.Cancelled } });
} else {
updateSlot({ data: { state: Enum_Order_State.Cancelling } });
}
}
function handleOnComplete() {
if (isMaster) {
updateSlot({ data: { state: Enum_Order_State.Completed } });
}
}
function handleOnRepeat() {
push('/orders/add', order);
}
return (
<FloatingActionPanel
isLoading={isPending}
onCancel={isCreated || (isMaster && isCancelling) || isApproved ? handleCancel : undefined}
onComplete={isMaster && isApproved ? handleOnComplete : undefined}
onConfirm={isMaster && isCreated ? handleApprove : undefined}
onRepeat={isCancelled || isCompleted ? handleOnRepeat : undefined}
onReturn={isMaster && isCancelled ? handleApprove : undefined}
/>
);
}