Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/multi-fe899b3f54
Browse files Browse the repository at this point in the history
  • Loading branch information
DonKoko authored Oct 8, 2024
2 parents 61712fb + 9f3c89d commit fcbea76
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 9 deletions.
7 changes: 6 additions & 1 deletion app/components/booking/actions-dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BookingStatus } from "@prisma/client";
import { useLoaderData, useSubmit } from "@remix-run/react";
import { ChevronRight } from "~/components/icons/library";
import {
Expand All @@ -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";
Expand Down Expand Up @@ -65,8 +67,11 @@ export const ActionsDropdown = ({ fullWidth }: Props) => {
<DropdownMenuPortal>
<DropdownMenuContent
align="end"
className="order w-[220px] rounded-md bg-white p-1.5 text-right "
className="order w-[220px] rounded-md bg-white p-1.5 text-right"
>
<When truthy={booking.status === BookingStatus.RESERVED}>
<RevertToDraftDialog booking={booking} />
</When>
<When
truthy={(isOngoing || isReserved || isOverdue) && canCancelBooking}
>
Expand Down
78 changes: 78 additions & 0 deletions app/components/booking/revert-to-draft-dialog.tsx
Original file line number Diff line number Diff line change
@@ -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<Booking, "name" | "status">;
};

export default function RevertToDraftDialog({ booking }: RevertToDraftProps) {
const [isDialogOpen, setIsDialogOpen] = useState(false);

function handleOpenDialog() {
setIsDialogOpen(true);
}

function handleCloseDialog() {
setIsDialogOpen(false);
}

return (
<>
<Button
variant="link"
className="hidden justify-start rounded-sm px-2 py-1.5 text-left text-sm font-medium text-gray-700 outline-none hover:bg-slate-100 hover:text-gray-700 md:block"
width="full"
onClick={handleOpenDialog}
disabled={booking.status !== BookingStatus.RESERVED}
>
Revert to Draft
</Button>
<DialogPortal>
<Dialog
className="md:max-w-sm"
open={isDialogOpen}
onClose={handleCloseDialog}
title={
<div>
<h3>Reverting to draft state</h3>
</div>
}
>
<div className="px-6 pb-4">
<p className="mb-4">
Are you sure you want to revert{" "}
<span className="font-bold">{booking.name}</span> booking back to
draft?
</p>

<form method="post" className="flex w-full items-center gap-4">
<input type="hidden" name="intent" value="revert-to-draft" />
<Button
variant="secondary"
className="flex-1"
type="button"
onClick={handleCloseDialog}
>
Cancel
</Button>
<Button className="flex-1">Confirm</Button>
</form>
</div>
</Dialog>
</DialogPortal>

{/* Only for mobile */}
<Button
variant="link"
className="block justify-start rounded-sm px-2 py-1.5 text-left text-sm font-medium text-gray-700 outline-none hover:bg-slate-100 hover:text-gray-700 md:hidden"
width="full"
onClick={handleOpenDialog}
disabled={booking.status !== BookingStatus.RESERVED}
>
Revert to Draft
</Button>
</>
);
}
6 changes: 2 additions & 4 deletions app/modules/asset/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand Down
2 changes: 1 addition & 1 deletion app/routes/_layout+/assets.$assetId.overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/routes/_layout+/assets.$assetId_.edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
17 changes: 17 additions & 0 deletions app/routes/_layout+/bookings.$bookingId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export async function action({ context, request, params }: ActionFunctionArgs) {
"archive",
"cancel",
"removeKit",
"revert-to-draft",
]),
nameChangeOnly: z
.string()
Expand All @@ -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 } =
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 6 additions & 2 deletions app/utils/custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fcbea76

Please sign in to comment.