diff --git a/src/components/Expenses/PreviewDocument.jsx b/src/components/Expenses/PreviewDocument.jsx index 5d5b1b59..e819cd44 100644 --- a/src/components/Expenses/PreviewDocument.jsx +++ b/src/components/Expenses/PreviewDocument.jsx @@ -1,3 +1,4 @@ +import { error } from "pdf-lib"; import { useState, useRef, useEffect } from "react"; const PreviewDocument = ({ files = [] }) => { @@ -15,9 +16,11 @@ const PreviewDocument = ({ files = [] }) => { const MIN_ZOOM = 0.4; const MAX_ZOOM = 3; - const currentImage = images[index]; + const currentFile = images[index]; + const fileUrl = currentFile?.preSignedUrl; + + const isPDF = fileUrl?.toLowerCase().endsWith(".pdf"); - // Reset on image change useEffect(() => { setRotation(0); setScale(1); @@ -25,8 +28,8 @@ const PreviewDocument = ({ files = [] }) => { setLoading(true); }, [index]); - const zoomIn = () => setScale((prev) => Math.min(prev + 0.2, MAX_ZOOM)); - const zoomOut = () => setScale((prev) => Math.max(prev - 0.2, MIN_ZOOM)); + const zoomIn = () => !isPDF && setScale((prev) => Math.min(prev + 0.2, MAX_ZOOM)); + const zoomOut = () => !isPDF && setScale((prev) => Math.max(prev - 0.2, MIN_ZOOM)); const resetAll = () => { setRotation(0); @@ -42,24 +45,8 @@ const PreviewDocument = ({ files = [] }) => { if (index > 0) setIndex((i) => i - 1); }; - const handleWheel = (e) => { - e.preventDefault(); - - if (e.ctrlKey) { - const delta = e.deltaY > 0 ? -0.1 : 0.1; - setScale((prev) => { - let next = prev + delta; - if (next < MIN_ZOOM) next = MIN_ZOOM; - if (next > MAX_ZOOM) next = MAX_ZOOM; - return next; - }); - } else { - if (e.deltaY > 0) nextImage(); - else prevImage(); - } - }; - const handleMouseDown = (e) => { + if (isPDF) return; setDragging(true); startPos.current = { x: e.clientX - position.x, @@ -68,7 +55,7 @@ const PreviewDocument = ({ files = [] }) => { }; const handleMouseMove = (e) => { - if (!dragging) return; + if (!dragging || isPDF) return; setPosition({ x: e.clientX - startPos.current.x, @@ -78,39 +65,41 @@ const PreviewDocument = ({ files = [] }) => { const handleMouseUp = () => setDragging(false); - const handleDoubleClick = () => resetAll(); + const handleDoubleClick = () => !isPDF && resetAll(); return ( <> - {/* Top Controls */} + {/* Controls */}
- {/* Left */}
- setRotation((prev) => prev + 90)} - title="Rotate" - /> - - - + {!isPDF && ( + <> + setRotation((prev) => prev + 90)} + title="Rotate" + /> + + + + + )}
{ className="position-relative d-flex justify-content-center align-items-center bg-light-secondary overflow-hidden" style={{ minHeight: "70vh", + userSelect: "none", borderRadius: "10px", }} > {loading &&
Loading...
} - Preview setLoading(false)} - /> + {/* PDF VIEW */} + {isPDF ? ( +