diff --git a/src/Components/Common/FilePreviewDialog.tsx b/src/Components/Common/FilePreviewDialog.tsx new file mode 100644 index 00000000000..d0c27fcb4a6 --- /dev/null +++ b/src/Components/Common/FilePreviewDialog.tsx @@ -0,0 +1,219 @@ +import React from "react"; +import { Dialog, Transition } from "@headlessui/react"; +import { classNames } from "../../Utils/utils"; +import CircularProgress from "./components/CircularProgress"; +import { useTranslation } from "react-i18next"; +import { StateInterface } from "../Patient/FileUpload"; + +export const zoom_values = [ + "h-1/6 w-1/6 my-40", + "h-2/6 w-2/6 my-32", + "h-3/6 w-3/6 my-24", + "h-4/6 w-4/6 my-20", + "h-5/6 w-5/6 my-16", + "h-full w-full my-12", +]; + +type FilePreviewProps = { + title?: React.ReactNode; + description?: React.ReactNode; + show: boolean; + onClose: () => void; + file_state: StateInterface; + setFileState: React.Dispatch>; + downloadURL?: string; + fileUrl: string; + className?: string; + titleAction?: React.ReactNode; + fixedWidth?: boolean; +}; + +const FilePreviewDialog = (props: FilePreviewProps) => { + const { + title, + description, + show, + onClose, + file_state, + setFileState, + downloadURL, + fileUrl, + className, + fixedWidth = true, + } = props; + const { t } = useTranslation(); + + const handleZoomIn = () => { + const checkFull = file_state.zoom === zoom_values.length; + setFileState({ + ...file_state, + zoom: !checkFull ? file_state.zoom + 1 : file_state.zoom, + }); + }; + + const handleZoomOut = () => { + const checkFull = file_state.zoom === 1; + setFileState({ + ...file_state, + zoom: !checkFull ? file_state.zoom - 1 : file_state.zoom, + }); + }; + + const handleRotate = (rotation: number) => { + setFileState((prev) => ({ + ...prev, + rotation: prev.rotation + rotation, + })); + }; + + return ( +
+ + + +
+ + +
+
+ + + +
+

{title}

+

+ {description} +

+
+ {props.titleAction} +
+ {fileUrl && fileUrl.length > 0 ? ( +
+
+
+ {file_state.isImage && ( + <> + {[ + [ + t("Zoom In"), + "magnifying-glass-plus", + handleZoomIn, + file_state.zoom === zoom_values.length, + ], + [ + t("Zoom Out"), + "magnifying-glass-minus", + handleZoomOut, + file_state.zoom === 1, + ], + [ + t("Rotate Left"), + "rotate-left", + () => handleRotate(-90), + false, + ], + [ + t("Rotate Right"), + "rotate-right", + () => handleRotate(90), + false, + ], + ].map((button, index) => ( + + ))} + + )} +
+
+ {downloadURL && downloadURL.length > 0 && ( + + + Download + + )} + +
+
+
+ {file_state.isImage ? ( + file + ) : ( +