diff --git a/app/components/booking/actions-dropdown.tsx b/app/components/booking/actions-dropdown.tsx index 59e370992..bb1574c2d 100644 --- a/app/components/booking/actions-dropdown.tsx +++ b/app/components/booking/actions-dropdown.tsx @@ -1,3 +1,4 @@ +import { BookingStatus } from "@prisma/client"; import { useLoaderData, useSubmit } from "@remix-run/react"; import { ChevronRight } from "~/components/icons/library"; import { @@ -18,6 +19,7 @@ import { userHasPermission } from "~/utils/permissions/permission.validator.clie import { tw } from "~/utils/tw"; import { DeleteBooking } from "./delete-booking"; import { GenerateBookingPdf } from "./generate-booking-pdf"; +import RevertToDraftDialog from "./revert-to-draft-dialog"; import { Divider } from "../layout/divider"; import { Button } from "../shared/button"; import When from "../when/when"; @@ -65,8 +67,11 @@ export const ActionsDropdown = ({ fullWidth }: Props) => { + + + diff --git a/app/components/booking/revert-to-draft-dialog.tsx b/app/components/booking/revert-to-draft-dialog.tsx new file mode 100644 index 000000000..2a116659b --- /dev/null +++ b/app/components/booking/revert-to-draft-dialog.tsx @@ -0,0 +1,78 @@ +import { useState } from "react"; +import { BookingStatus, type Booking } from "@prisma/client"; +import { Dialog, DialogPortal } from "../layout/dialog"; +import { Button } from "../shared/button"; + +type RevertToDraftProps = { + booking: Pick; +}; + +export default function RevertToDraftDialog({ booking }: RevertToDraftProps) { + const [isDialogOpen, setIsDialogOpen] = useState(false); + + function handleOpenDialog() { + setIsDialogOpen(true); + } + + function handleCloseDialog() { + setIsDialogOpen(false); + } + + return ( + <> + + + +

Reverting to draft state

+ + } + > +
+

+ Are you sure you want to revert{" "} + {booking.name} booking back to + draft? +

+ +
+ + + +
+
+
+
+ + {/* Only for mobile */} + + + ); +} diff --git a/app/routes/_layout+/bookings.$bookingId.tsx b/app/routes/_layout+/bookings.$bookingId.tsx index 1a49ac398..e5aa405e1 100644 --- a/app/routes/_layout+/bookings.$bookingId.tsx +++ b/app/routes/_layout+/bookings.$bookingId.tsx @@ -249,6 +249,7 @@ export async function action({ context, request, params }: ActionFunctionArgs) { "archive", "cancel", "removeKit", + "revert-to-draft", ]), nameChangeOnly: z .string() @@ -270,6 +271,7 @@ export async function action({ context, request, params }: ActionFunctionArgs) { archive: PermissionAction.update, cancel: PermissionAction.update, removeKit: PermissionAction.update, + "revert-to-draft": PermissionAction.update, }; const { organizationId, role, isSelfServiceOrBase } = @@ -535,6 +537,21 @@ export async function action({ context, request, params }: ActionFunctionArgs) { headers, }); } + case "revert-to-draft": { + await upsertBooking( + { id, status: BookingStatus.DRAFT }, + getClientHint(request) + ); + + sendNotification({ + title: "Booking reverted", + message: "Your booking has been reverted back to draft successfully", + icon: { name: "success", variant: "success" }, + senderId: authSession.userId, + }); + + return json(data({ success: true })); + } default: { checkExhaustiveSwitch(intent); return json(data(null));