From fdf25567d8cba779a04aa78d501fb73adbb6f171 Mon Sep 17 00:00:00 2001 From: rockingrohit9639 Date: Fri, 4 Oct 2024 17:55:01 +0530 Subject: [PATCH 1/4] feat(booking): add feature to revert a booking to draft --- app/components/booking/actions-dropdown.tsx | 7 +- .../booking/revert-to-draft-dialog.tsx | 78 +++++++++++++++++++ app/routes/_layout+/bookings.$bookingId.tsx | 17 ++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 app/components/booking/revert-to-draft-dialog.tsx 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..a74308d07 --- /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)); From 1ee13519d365eacb04c24241dd01d59b0f55a478 Mon Sep 17 00:00:00 2001 From: rockingrohit9639 Date: Fri, 4 Oct 2024 17:59:05 +0530 Subject: [PATCH 2/4] format file with prettier --- app/components/booking/revert-to-draft-dialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/booking/revert-to-draft-dialog.tsx b/app/components/booking/revert-to-draft-dialog.tsx index a74308d07..2a116659b 100644 --- a/app/components/booking/revert-to-draft-dialog.tsx +++ b/app/components/booking/revert-to-draft-dialog.tsx @@ -43,7 +43,7 @@ export default function RevertToDraftDialog({ booking }: RevertToDraftProps) {

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

From dd990e57eccf8452470b96bf268e3a2f1064b5f3 Mon Sep 17 00:00:00 2001 From: Nikolay Bonev Date: Mon, 7 Oct 2024 18:46:22 +0300 Subject: [PATCH 3/4] fix: bug causing AssetCustomFieldValue to be removed for BOOLEAN fields that are set to false --- app/routes/_layout+/assets.$assetId.overview.tsx | 2 +- app/routes/_layout+/assets.$assetId_.edit.tsx | 2 +- app/utils/custom-fields.ts | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/routes/_layout+/assets.$assetId.overview.tsx b/app/routes/_layout+/assets.$assetId.overview.tsx index 0edf974f2..22ac6ce88 100644 --- a/app/routes/_layout+/assets.$assetId.overview.tsx +++ b/app/routes/_layout+/assets.$assetId.overview.tsx @@ -131,7 +131,6 @@ export async function loader({ context, request, params }: LoaderFunctionArgs) { asset.bookings = [currentBooking]; } - /** We only need customField with same category of asset or without any category */ let customFields = asset.categoryId ? asset.customFields.filter( @@ -227,6 +226,7 @@ export default function AssetOverview() { asset && asset.customFields?.length > 0 ? asset.customFields.filter((f) => f.value) : []; + const location = asset && asset.location; usePosition(); const fetcher = useFetcher(); diff --git a/app/routes/_layout+/assets.$assetId_.edit.tsx b/app/routes/_layout+/assets.$assetId_.edit.tsx index 4270b4307..273f7ae03 100644 --- a/app/routes/_layout+/assets.$assetId_.edit.tsx +++ b/app/routes/_layout+/assets.$assetId_.edit.tsx @@ -207,7 +207,7 @@ export async function action({ context, request, params }: ActionFunctionArgs) { return redirect(`/assets/new`); } - return redirect(`/assets/${id}`); + return json(data({ success: true })); } catch (cause) { const reason = makeShelfError(cause, { userId, id }); return json(error(reason), { status: reason.status }); diff --git a/app/utils/custom-fields.ts b/app/utils/custom-fields.ts index 485109269..8e323365d 100644 --- a/app/utils/custom-fields.ts +++ b/app/utils/custom-fields.ts @@ -150,8 +150,8 @@ export const buildCustomFieldValue = ( ): ShelfAssetCustomFieldValueType["value"] | undefined => { try { const { raw } = value; - - if (!raw) { + /** We handle boolean different because it returns false */ + if (def.type !== "BOOLEAN" && !raw) { return undefined; } @@ -188,6 +188,10 @@ export const getCustomFieldDisplayValue = ( return parseMarkdownToReact(value.raw as string); } + if (Object.hasOwnProperty.call(value, "valueBoolean")) { + return value.valueBoolean ? "Yes" : "No"; + } + if (value.valueDate && value.raw) { return hints ? formatDateBasedOnLocaleOnly(value.valueDate as string, hints.locale) From 750f5838d53340f56146d9f6b84b38fbc67f6e41 Mon Sep 17 00:00:00 2001 From: rockingrohit9639 Date: Tue, 8 Oct 2024 10:33:03 +0530 Subject: [PATCH 4/4] fix: transaction issue on bulk delete assets --- app/modules/asset/service.server.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/modules/asset/service.server.ts b/app/modules/asset/service.server.ts index 9ce21e71e..49868f759 100644 --- a/app/modules/asset/service.server.ts +++ b/app/modules/asset/service.server.ts @@ -2301,10 +2301,8 @@ export async function bulkDeleteAssets({ }); try { - await db.$transaction(async (tx) => { - await tx.asset.deleteMany({ - where: { id: { in: assets.map((asset) => asset.id) } }, - }); + await db.asset.deleteMany({ + where: { id: { in: assets.map((asset) => asset.id) } }, }); /** Deleting images of the assets (if any) */