Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
113 lines
4.4 KiB
TypeScript
113 lines
4.4 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef } from "react";
|
|
import { AnimatePresence, motion } from "framer-motion";
|
|
import { X, Download } from "lucide-react";
|
|
import type { GalleryImage } from "./ImageGallery";
|
|
import { downloadGalleryImage } from "./ImageLightbox";
|
|
import type { PdfDocument } from "./pdfDocument";
|
|
|
|
/** Pages rendered by the reader; longer PDFs link out to the full file. */
|
|
export const PDF_PAGE_CAP = 5;
|
|
|
|
/** Draws one PDF page onto a canvas at the device pixel ratio, sized to its container width. */
|
|
function PdfPageCanvas({ doc, page, title }: { doc: PdfDocument; page: number; title: string }) {
|
|
const ref = useRef<HTMLCanvasElement>(null);
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
doc.getPage(page).then((p) => {
|
|
const canvas = ref.current;
|
|
if (cancelled || !canvas) return;
|
|
const cssWidth = canvas.parentElement?.clientWidth || 600;
|
|
const base = p.getViewport({ scale: 1 });
|
|
const viewport = p.getViewport({ scale: (cssWidth / base.width) * (window.devicePixelRatio || 1) });
|
|
canvas.width = viewport.width;
|
|
canvas.height = viewport.height;
|
|
return p.render({ canvas, viewport }).promise;
|
|
}).catch(() => {});
|
|
return () => { cancelled = true; };
|
|
}, [doc, page]);
|
|
|
|
return <canvas ref={ref} aria-label={`${title} page ${page}`} className="w-full h-auto block bg-white" />;
|
|
}
|
|
|
|
/** Renders pages 1..min(numPages, maxPages) stacked vertically. */
|
|
export function PdfPages({ doc, title, maxPages }: { doc: PdfDocument; title: string; maxPages: number }) {
|
|
const count = Math.min(doc.numPages, maxPages);
|
|
return (
|
|
<>
|
|
{Array.from({ length: count }, (_, i) => (
|
|
<PdfPageCanvas key={i + 1} doc={doc} page={i + 1} title={title} />
|
|
))}
|
|
</>
|
|
);
|
|
}
|
|
|
|
interface Props {
|
|
/** PDF to read; null closes the reader */
|
|
pdf: { image: GalleryImage; doc: PdfDocument } | null;
|
|
onClose: () => void;
|
|
}
|
|
|
|
/** Fullscreen in-app PDF reader: up to PDF_PAGE_CAP pages, then a link to the full file. */
|
|
export default function PdfReader({ pdf, onClose }: Props) {
|
|
return (
|
|
<AnimatePresence>
|
|
{pdf && (
|
|
<motion.div
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-label={pdf.image.title}
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
exit={{ opacity: 0 }}
|
|
className="fixed inset-0 z-[60] flex flex-col"
|
|
style={{ background: "rgba(0,0,0,0.92)", backdropFilter: "blur(12px)" }}
|
|
>
|
|
{/* Header: title, download, close */}
|
|
<div className="flex items-center gap-3 px-4 py-3" style={{ paddingTop: "max(0.75rem, env(safe-area-inset-top))" }}>
|
|
<p className="flex-1 min-w-0 truncate text-sm font-bold text-white">{pdf.image.title}</p>
|
|
<motion.button
|
|
onClick={() => downloadGalleryImage(pdf.image)}
|
|
whileTap={{ scale: 0.9 }}
|
|
className="flex items-center gap-1.5 px-3 py-2 rounded-xl text-xs font-bold"
|
|
style={{ background: "rgba(255,107,0,0.2)", border: "1px solid rgba(255,107,0,0.4)", color: "#FF6B00" }}
|
|
>
|
|
<Download strokeWidth={2} className="w-3.5 h-3.5" /> View
|
|
</motion.button>
|
|
<motion.button
|
|
onClick={onClose}
|
|
whileTap={{ scale: 0.85 }}
|
|
aria-label="Close"
|
|
className="w-10 h-10 rounded-full flex items-center justify-center"
|
|
style={{ background: "rgba(255,255,255,0.1)", border: "1px solid rgba(255,255,255,0.2)" }}
|
|
>
|
|
<X strokeWidth={2} className="w-5 h-5 stroke-white" />
|
|
</motion.button>
|
|
</div>
|
|
|
|
{/* Pages */}
|
|
<div className="flex-1 overflow-y-auto px-4 pb-8 space-y-3">
|
|
<PdfPages doc={pdf.doc} title={pdf.image.title} maxPages={PDF_PAGE_CAP} />
|
|
{pdf.doc.numPages > PDF_PAGE_CAP && (
|
|
<div className="flex flex-col items-center gap-2 pt-2 text-center">
|
|
<p className="text-xs text-white/70">Showing {PDF_PAGE_CAP} of {pdf.doc.numPages} pages</p>
|
|
<a
|
|
href={pdf.image.src}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="px-4 py-2 rounded-xl text-xs font-bold"
|
|
style={{ background: "#FF6B00", color: "#FFFFFF" }}
|
|
>
|
|
Open full PDF
|
|
</a>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</motion.div>
|
|
)}
|
|
</AnimatePresence>
|
|
);
|
|
}
|