Skip to content

Commit

Permalink
removing download button + other minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
DonKoko committed Jun 4, 2024
1 parent 36676cb commit ee98751
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
35 changes: 2 additions & 33 deletions app/components/booking/generate-booking-pdf.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useRef, useState } from "react";
import { useState } from "react";
import type { Asset, Booking } from "@prisma/client";
import { Button } from "~/components/shared/button";

import { tw } from "~/utils/tw";
import { Dialog, DialogPortal } from "../layout/dialog";
import { Spinner } from "../shared/spinner";
Expand All @@ -17,7 +18,6 @@ export const GenerateBookingPdf = ({
timeStamp: number;
}) => {
const [iframeLoaded, setIframeLoaded] = useState(false);
const iframeRef = useRef<HTMLIFrameElement>(null); // Add ref for the iframe
const totalAssets = booking.assets.length;
const url = `/bookings/${booking.id.toString()}/generate-pdf/booking-checklist-${new Date()
.toISOString()
Expand All @@ -30,27 +30,6 @@ export const GenerateBookingPdf = ({
window.location.href = url;
};

const handleDownload = (e: React.MouseEvent<HTMLButtonElement>) => {
try {
e.preventDefault();
const iframe = iframeRef.current;
if (iframe && iframe?.contentDocument) {
const pdfData = iframe?.contentDocument?.body?.innerHTML; // Adjust if necessary to access PDF data
const blob = new Blob([pdfData], { type: "application/pdf" });
const downloadUrl = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = downloadUrl;
a.download = `booking-checklist-${new Date()
.toISOString()
.slice(0, 10)}.pdf`;
a.click();
URL.revokeObjectURL(downloadUrl);
}
} catch (err) {
//do nothing for now.
}
};

const [isDialogOpen, setIsDialogOpen] = useState(false);

const handleOpenDialog = () => {
Expand Down Expand Up @@ -103,7 +82,6 @@ export const GenerateBookingPdf = ({
width="100%"
height="100%"
onLoad={handleIframeLoad}
ref={iframeRef}
src={url}
title="Booking PDF"
allowFullScreen={true}
Expand All @@ -115,15 +93,6 @@ export const GenerateBookingPdf = ({
<Button variant="secondary" onClick={handleCloseDialog}>
Cancel
</Button>
<Button
variant="secondary"
role="link"
disabled={!iframeLoaded}
icon="download"
onClick={handleDownload}
>
Download
</Button>
</div>
</div>
</Dialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const styles = {
marginTop: "10px",
marginBottom: "20px",
border: "1px solid #bfbfbf",
borderRadius: "4px",
},
infoRow: {
display: "flex",
Expand Down

0 comments on commit ee98751

Please sign in to comment.