mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 13:05:44 +00:00
booking flow,summtion, approval, contract, mock payemnt and integration to back office, and also add permissions
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
type BookingActionContext,
|
||||
type BookingActionDef,
|
||||
} from "@/features/bookings/booking-actions.config";
|
||||
import { useAuth } from "@/auth/useAuth";
|
||||
import { useBookingDetail, useBookingMutations } from "@/hooks/bookings/useBookings";
|
||||
|
||||
export function useBookingActionDialog(
|
||||
@@ -14,13 +15,18 @@ export function useBookingActionDialog(
|
||||
) {
|
||||
const [pendingAction, setPendingAction] = useState<BookingActionDef | null>(null);
|
||||
const [inputValue, setInputValue] = useState("");
|
||||
const [selectedFile, setSelectedFile] = useState<File | null>(null);
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
|
||||
const needsApprovalSteps =
|
||||
pendingAction?.id === "approve" || pendingAction?.id === "rejectApproval";
|
||||
|
||||
const needsApprovalContext =
|
||||
context.status === "PENDING_APPROVAL" ||
|
||||
context.status === "APPROVED_PENDING_SIGNATURE";
|
||||
|
||||
const { data: detail, isLoading: detailLoading } = useBookingDetail(
|
||||
needsApprovalSteps ? bookingId : undefined,
|
||||
needsApprovalSteps || needsApprovalContext ? bookingId : undefined,
|
||||
);
|
||||
|
||||
const mergedContext: BookingActionContext = {
|
||||
@@ -29,12 +35,14 @@ export function useBookingActionDialog(
|
||||
reference: detail?.reference ?? context.reference,
|
||||
};
|
||||
|
||||
const { user } = useAuth();
|
||||
const mutations = useBookingMutations(bookingId);
|
||||
const actions = getBookingActions(mergedContext);
|
||||
const actions = getBookingActions(mergedContext, user);
|
||||
|
||||
const openAction = useCallback((action: BookingActionDef) => {
|
||||
setPendingAction(action);
|
||||
setInputValue("");
|
||||
setSelectedFile(null);
|
||||
setDialogOpen(true);
|
||||
}, []);
|
||||
|
||||
@@ -42,6 +50,7 @@ export function useBookingActionDialog(
|
||||
setDialogOpen(false);
|
||||
setPendingAction(null);
|
||||
setInputValue("");
|
||||
setSelectedFile(null);
|
||||
}, []);
|
||||
|
||||
const runAction = useCallback(() => {
|
||||
@@ -82,11 +91,8 @@ export function useBookingActionDialog(
|
||||
break;
|
||||
case "viewContract":
|
||||
break;
|
||||
case "generatePnr":
|
||||
mutations.generatePnr.mutate(undefined, { onSuccess });
|
||||
break;
|
||||
case "verifyPayment":
|
||||
mutations.verifyPayment.mutate(undefined, { onSuccess });
|
||||
case "payBooking":
|
||||
mutations.payBooking.mutate(undefined, { onSuccess });
|
||||
break;
|
||||
case "startTransit":
|
||||
mutations.startTransit.mutate(undefined, { onSuccess });
|
||||
@@ -94,12 +100,16 @@ export function useBookingActionDialog(
|
||||
case "complete":
|
||||
mutations.complete.mutate(undefined, { onSuccess });
|
||||
break;
|
||||
case "cancel":
|
||||
mutations.cancel.mutate(inputValue.trim(), { onSuccess });
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}, [
|
||||
pendingAction,
|
||||
inputValue,
|
||||
selectedFile,
|
||||
mergedContext.approvalSteps,
|
||||
mutations,
|
||||
closeDialog,
|
||||
@@ -109,13 +119,18 @@ export function useBookingActionDialog(
|
||||
mutations.isPending ||
|
||||
(needsApprovalSteps && detailLoading) ||
|
||||
(pendingAction?.id === "approve" &&
|
||||
!getNextPendingApprovalStep(mergedContext.approvalSteps));
|
||||
!getNextPendingApprovalStep(mergedContext.approvalSteps)) ||
|
||||
(pendingAction?.input === "file" && !selectedFile) ||
|
||||
(pendingAction?.input === "reason" && !inputValue.trim()) ||
|
||||
(pendingAction?.input === "note" && !inputValue.trim());
|
||||
|
||||
return {
|
||||
actions,
|
||||
pendingAction,
|
||||
inputValue,
|
||||
setInputValue,
|
||||
selectedFile,
|
||||
setSelectedFile,
|
||||
dialogOpen,
|
||||
setDialogOpen: (open: boolean) => {
|
||||
if (!open) closeDialog();
|
||||
|
||||
Reference in New Issue
Block a user