From e10bb10c203c6b7a16683a365a2550732517ec6c Mon Sep 17 00:00:00 2001 From: "pramod.mahajan" Date: Mon, 8 Dec 2025 14:10:00 +0530 Subject: [PATCH 1/4] display properly each document --- src/components/Expenses/PreviewDocument.jsx | 210 ++++++++++---------- src/utils/constants.jsx | 13 ++ 2 files changed, 117 insertions(+), 106 deletions(-) diff --git a/src/components/Expenses/PreviewDocument.jsx b/src/components/Expenses/PreviewDocument.jsx index e819cd44..f35d6ef2 100644 --- a/src/components/Expenses/PreviewDocument.jsx +++ b/src/components/Expenses/PreviewDocument.jsx @@ -1,5 +1,6 @@ import { error } from "pdf-lib"; import { useState, useRef, useEffect } from "react"; +import { iframeDocuments } from "../../utils/constants"; const PreviewDocument = ({ files = [] }) => { const images = Array.isArray(files) ? files : [files]; @@ -19,7 +20,9 @@ const PreviewDocument = ({ files = [] }) => { const currentFile = images[index]; const fileUrl = currentFile?.preSignedUrl; - const isPDF = fileUrl?.toLowerCase().endsWith(".pdf"); + const isDocumentType = iframeDocuments.includes( + currentFile?.contentType.toLowerCase() + ); useEffect(() => { setRotation(0); @@ -28,8 +31,10 @@ const PreviewDocument = ({ files = [] }) => { setLoading(true); }, [index]); - 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 zoomIn = () => + !isDocumentType && setScale((prev) => Math.min(prev + 0.2, MAX_ZOOM)); + const zoomOut = () => + !isDocumentType && setScale((prev) => Math.max(prev - 0.2, MIN_ZOOM)); const resetAll = () => { setRotation(0); @@ -46,7 +51,7 @@ const PreviewDocument = ({ files = [] }) => { }; const handleMouseDown = (e) => { - if (isPDF) return; + if (isDocumentType) return; setDragging(true); startPos.current = { x: e.clientX - position.x, @@ -55,7 +60,7 @@ const PreviewDocument = ({ files = [] }) => { }; const handleMouseMove = (e) => { - if (!dragging || isPDF) return; + if (!dragging || isDocumentType) return; setPosition({ x: e.clientX - startPos.current.x, @@ -65,114 +70,107 @@ const PreviewDocument = ({ files = [] }) => { const handleMouseUp = () => setDragging(false); - const handleDoubleClick = () => !isPDF && resetAll(); + const handleDoubleClick = () => !isDocumentType && resetAll(); return ( - <> - {/* Controls */} -
-
- {!isPDF && ( - <> - setRotation((prev) => prev + 90)} - title="Rotate" - /> - - - - - )} -
-
+<> + {/* Controls */} +
+
+ {!isDocumentType && ( + <> + setRotation((prev) => prev + 90)} + title="Rotate" + /> + + + + + )} +
+
-
+ {loading &&
Loading...
} + + {isDocumentType ? ( +