Skip to content

Commit f1a7a76

Browse files
authored
Merge pull request #122 from alimarchal/copilot/fix-pdf-download-button-responsiveness
[WIP] Fix PDF Download button responsiveness on Branch Network page
2 parents a394b1c + 4500bc9 commit f1a7a76

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

resources/js/components/BranchLocator.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ const BranchLocator: React.FC<Props> = ({ branches = [], regions = [], districts
194194
};
195195

196196
const downloadPDF = () => {
197-
// Create a printable version of the data
198-
const printContent = `
197+
setIsDownloading(true);
198+
try {
199+
// Create a printable version of the data
200+
const printContent = `
199201
<!DOCTYPE html>
200202
<html>
201203
<head>
@@ -285,16 +287,24 @@ const BranchLocator: React.FC<Props> = ({ branches = [], regions = [], districts
285287
</html>
286288
`;
287289

288-
const printWindow = window.open('', '_blank');
289-
if (printWindow) {
290-
printWindow.document.write(printContent);
291-
printWindow.document.close();
292-
293-
// Wait for content to load then trigger print
294-
setTimeout(() => {
295-
printWindow.print();
296-
// printWindow.close();
297-
}, 250);
290+
const printWindow = window.open('', '_blank');
291+
if (printWindow) {
292+
printWindow.document.write(printContent);
293+
printWindow.document.close();
294+
295+
// Wait for content to load then trigger print
296+
setTimeout(() => {
297+
printWindow.print();
298+
// printWindow.close();
299+
setIsDownloading(false);
300+
}, 250);
301+
} else {
302+
setIsDownloading(false);
303+
}
304+
} catch (error) {
305+
console.error('Error generating PDF:', error);
306+
alert('Failed to open print dialog. Please try again.');
307+
setIsDownloading(false);
298308
}
299309
};
300310

@@ -418,27 +428,28 @@ const BranchLocator: React.FC<Props> = ({ branches = [], regions = [], districts
418428
</div>
419429

420430
{/* Results Count and Download Options */}
421-
<div className="mt-4 flex items-center justify-between">
431+
<div className="mt-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
422432
<div className="text-sm text-gray-600">
423433
Showing {displayBranches.length} of {branches.length || 87} branches
424434
{searchTerm && <span className="ml-2 font-medium text-[#4A7C59]">for "{searchTerm}"</span>}
425435
</div>
426436

427437
{/* Download Buttons */}
428-
<div className="flex items-center gap-3">
438+
<div className="flex flex-wrap items-center gap-2 sm:gap-3">
429439
<span className="text-sm text-gray-600">Download:</span>
430440
<button
431441
onClick={downloadExcel}
432442
disabled={isDownloading}
433-
className="flex items-center gap-2 rounded-lg bg-green-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700 focus:ring-2 focus:ring-green-500 focus:ring-offset-2 focus:outline-none disabled:opacity-50"
443+
className="flex items-center gap-2 rounded-lg bg-green-600 px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-green-700 focus:ring-2 focus:ring-green-500 focus:ring-offset-2 focus:outline-none disabled:opacity-50 sm:px-4"
434444
title="Download as Excel"
435445
>
436446
<FileSpreadsheet className="h-4 w-4" />
437447
{isDownloading ? 'Generating...' : 'Excel'}
438448
</button>
439449
<button
440450
onClick={downloadPDF}
441-
className="flex items-center gap-2 rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-red-700 focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:outline-none"
451+
disabled={isDownloading}
452+
className="flex items-center gap-2 rounded-lg bg-red-600 px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-red-700 focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:outline-none disabled:opacity-50 sm:px-4"
442453
title="Download as PDF"
443454
>
444455
<FileText className="h-4 w-4" />

0 commit comments

Comments
 (0)