From 16c057d5a3d250fddc0070f4b402ebe7e77e7692 Mon Sep 17 00:00:00 2001 From: Justin Chow Date: Sun, 15 Dec 2024 00:52:38 +0700 Subject: [PATCH] fix: revert tambah ajuan page --- src/app/dashboard/tambah/page.tsx | 225 ++++++++++-------------------- 1 file changed, 77 insertions(+), 148 deletions(-) diff --git a/src/app/dashboard/tambah/page.tsx b/src/app/dashboard/tambah/page.tsx index 9c1d142..04948a8 100644 --- a/src/app/dashboard/tambah/page.tsx +++ b/src/app/dashboard/tambah/page.tsx @@ -16,7 +16,6 @@ import BreadCrumbs from "@/components/BreadCrumbs"; import TextArea from "@/components/form/TextArea"; import "@react-pdf-viewer/core/lib/styles/index.css"; import { Worker, Viewer, SpecialZoomLevel } from "@react-pdf-viewer/core"; -import { pageNavigationPlugin } from "@react-pdf-viewer/page-navigation"; import { useEffect, useRef, useState } from "react"; import useFileStore from "@/app/stores/useFileStore"; @@ -26,7 +25,6 @@ type SignUpRequest = { cover_letter: string; x: string; y: string; - page: number; document: FileList | null; }; @@ -45,22 +43,13 @@ export default function TambahAjuan() { y: number; w: number; height: number; - page: number; } | null>(null); const [startPoint, setStartPoint] = useState<{ x: number; y: number } | null>( null, ); - const [currentPage, setCurrentPage] = useState(1); - const [totalPages, setTotalPages] = useState(1); const [isMdScreen, setIsMdScreen] = useState(false); const animationFrameId = useRef(null); - const [fileUrl, setFileUrl] = useState(""); - const { isFileDeleted, setIsFileDeleted } = useFileStore(); - - const pageNavigationPluginInstance = pageNavigationPlugin(); - const { GoToNextPage, GoToPreviousPage } = pageNavigationPluginInstance; - useEffect(() => { const handleResize = () => { setIsMdScreen(window.innerWidth >= 768); @@ -99,7 +88,6 @@ export default function TambahAjuan() { y: startPoint.y, w, height, - page: currentPage, }); }); } @@ -121,72 +109,66 @@ export default function TambahAjuan() { const x = e.clientX - rect.left; const y = e.clientY - rect.top; - setSelection({ x, y, w: width, height: height, page: currentPage }); + setSelection({ x, y, w: width, height: height }); }; // biome-ignore lint/suspicious/noExplicitAny: - const renderPage = (props: any) => { - // const pageIndex = props.pageIndex + 1; - const { pageIndex } = props; - const pageNumber = pageIndex + 1; - - return ( -
handleMouseDown(e, e.currentTarget) : undefined - } - onMouseMove={ - isMdScreen ? (e) => handleMouseMove(e, e.currentTarget) : undefined - } - onMouseUp={isMdScreen ? handleMouseUp : undefined} - onClick={ - !isMdScreen ? (e) => handlePageClick(e, e.currentTarget) : undefined - } - > - {props.canvasLayer.children} - {isMdScreen && selection && selection.page === pageNumber && ( -
- )} - {!isMdScreen && selection && selection.page === pageNumber && ( -
- )} -
- ); - }; + const renderPage = (props: any) => ( +
handleMouseDown(e, e.currentTarget) : undefined + } + onMouseMove={ + isMdScreen ? (e) => handleMouseMove(e, e.currentTarget) : undefined + } + onMouseUp={isMdScreen ? handleMouseUp : undefined} + onClick={ + !isMdScreen ? (e) => handlePageClick(e, e.currentTarget) : undefined + } + > + {props.canvasLayer.children} + {isMdScreen && selection && ( +
+ )} + {!isMdScreen && selection && ( +
+ )} +
+ ); const { mutate: SignUpMutation, isPending } = useMutation< AxiosResponse, @@ -233,7 +215,6 @@ export default function TambahAjuan() { formData.append("x", scaledX.toFixed(0)); formData.append("y", scaledY.toFixed(0)); formData.append("w", scaledW.toFixed(0)); - formData.append("page", selection.page.toString()); if (data.document && data.document[0]) { formData.append("document", data.document[0]); @@ -242,29 +223,21 @@ export default function TambahAjuan() { SignUpMutation(formData); }; + const { isFileDeleted, setIsFileDeleted } = useFileStore(); + + const [fileUrl, setFileUrl] = useState(""); + // biome-ignore lint/suspicious/noExplicitAny: const handleFileUpload = (files: any) => { if (files.length > 0) { - const file = files[0]; - const previewUrl = URL.createObjectURL(file); - - setFileUrl(previewUrl); + setFileUrl(files[0].preview); setIsFileDeleted(false); - setSelection(null); - setCurrentPage(1); - setTotalPages(0); } else { setFileUrl(""); setIsFileDeleted(true); } }; - // biome-ignore lint/suspicious/noExplicitAny: - const handlePageChange = (e: any) => { - setCurrentPage(e.currentPage + 1); - setTotalPages(e.doc.numPages); - }; - useEffect(() => { if (isFileDeleted) { setFileUrl(""); @@ -313,7 +286,7 @@ export default function TambahAjuan() { on the Preview -
{fileUrl ? ( Selected Coordinates: X: {selection?.x.toFixed(2)}, Y:{" "} {selection?.y.toFixed(2)},{" "} - {isMdScreen && <>Width: {selection?.w.toFixed(2)}}, Page: - {selection && <>{selection.page}} + {isMdScreen && <>Width: {selection?.w.toFixed(2)}}
@@ -404,61 +375,19 @@ export default function TambahAjuan() {
{/* File Preview */} -
-
- {fileUrl ? ( - - { - setTotalPages(e.doc.numPages || 0); - }} - /> - - ) : ( -

File not uploaded

- )} -
- {fileUrl && ( -
- - {(props) => ( - - )} - - -
-

- Page {currentPage} of {totalPages} -

-
- - - {(props) => ( - - )} - -
+
+ {fileUrl ? ( + + + + ) : ( +

File not uploaded

)}