Files
evidencija-rezija/app/ui/PrintPreview.tsx
Nikola Derežič b205a61cf9 feat: implement US-3 - enhance print layout with professional table design
- Add comprehensive i18n support for all print preview content
- Fix next-intl context error by moving translations to server component
- Implement professional 3-column table layout with proper styling
- Add multilingual table headers (EN: #, Bill Information, 2D Barcode | HR: #, Informacije o Računu, 2D Barkod)
- Center-align index column header and optimize barcode sizing
- Hide print button and header from actual print output
- Fix hydration errors with proper date handling
- Enhanced barcode display with proper padding and sizing

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-14 21:16:33 +02:00

98 lines
3.7 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use client';
import { PrintBarcodeData } from '../lib/actions/printActions';
export interface PrintPreviewProps {
data: PrintBarcodeData[];
year: number;
month: number;
translations: {
title: string;
barcodesFound: string;
barcodeSingular: string;
printButton: string;
printFooter: string;
tableHeaderIndex: string;
tableHeaderBillInfo: string;
tableHeaderBarcode: string;
};
}
export const PrintPreview: React.FC<PrintPreviewProps> = ({ data, year, month, translations }) => {
return (
<div className="min-h-screen bg-white">
{/* Header section - hidden in print */}
<div className="p-6 border-b border-gray-200 print:hidden">
<h1 className="text-3xl font-bold text-gray-900 mb-2">
{translations.title}
</h1>
<p className="text-lg text-gray-600 mb-4">
{year}-{month.toString().padStart(2, '0')} {data.length} {data.length === 1 ? translations.barcodeSingular : translations.barcodesFound}
</p>
<button
onClick={() => window.print()}
className="btn btn-primary"
>
🖨 {translations.printButton}
</button>
</div>
{/* Print content */}
<div className="p-6">
<table className="w-full border-collapse border-2 border-gray-800">
<thead>
<tr className="bg-gray-100">
<th className="border-2 border-gray-800 px-3 py-2 text-center font-bold text-sm w-16">
{translations.tableHeaderIndex}
</th>
<th className="border-2 border-gray-800 px-3 py-2 text-left font-bold text-sm">
{translations.tableHeaderBillInfo}
</th>
<th className="border-2 border-gray-800 px-3 py-2 text-center font-bold text-sm w-64">
{translations.tableHeaderBarcode}
</th>
</tr>
</thead>
<tbody>
{data.map((item, index) => (
<tr key={`${item.locationName}-${item.billName}`} className="hover:bg-gray-50">
<td className="border-2 border-gray-800 px-3 py-4 text-center font-mono text-sm font-medium">
{(index + 1).toString().padStart(2, '0')}
</td>
<td className="border-2 border-gray-800 px-3 py-4">
<div className="space-y-1">
<div className="font-bold text-sm text-gray-900">
📅 {item.yearMonth}
</div>
<div className="font-medium text-sm text-gray-800">
🏠 {item.locationName}
</div>
<div className="text-sm text-gray-700">
📋 {item.billName}
</div>
</div>
</td>
<td className="border-2 border-gray-800 px-3 py-1.5 text-center">
<div className="flex justify-center items-center">
<img
src={item.barcodeImage.startsWith('data:') ? item.barcodeImage : `data:image/png;base64,${item.barcodeImage}`}
alt={`Barcode for ${item.billName}`}
className="max-h-28 w-auto border border-gray-300 rounded"
style={{ maxWidth: '270px' }}
/>
</div>
</td>
</tr>
))}
</tbody>
</table>
{/* Print footer - only visible when printing */}
<div className="mt-6 text-center text-xs text-gray-500 hidden print:block">
<p>{translations.printFooter.replace('{date}', new Date().toLocaleDateString())}</p>
</div>
</div>
</div>
);
};