From c4eb1b27d9896bfea32fb94a22066ef8625e5a8b Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Thu, 9 Feb 2023 15:48:26 +0100 Subject: [PATCH] fields ui --- apps/web/components/editor/field.tsx | 62 +++++++++++++++++-------- apps/web/components/pdf-viewer.jsx | 62 +++++++++++++++++++++++-- apps/web/package.json | 1 + apps/web/pages/documents/[id]/index.tsx | 29 +----------- package-lock.json | 4 +- 5 files changed, 106 insertions(+), 52 deletions(-) diff --git a/apps/web/components/editor/field.tsx b/apps/web/components/editor/field.tsx index cea2a1528..7d38d8983 100644 --- a/apps/web/components/editor/field.tsx +++ b/apps/web/components/editor/field.tsx @@ -1,38 +1,60 @@ import { ResizableBox, ResizeCallbackData } from "react-resizable"; -import React, { SyntheticEvent, useState } from "react"; +import React, { SyntheticEvent, useEffect, useState } from "react"; import Draggable from "react-draggable"; import { CircleStackIcon } from "@heroicons/react/24/outline"; import Logo from "../logo"; +const stc = require("string-to-color"); type FieldPropsType = { - color: string; - type: string; + field: { + color: string; + type: string; + position: any; + id: string; + recipient: string; + }; + onPositionChangedHandler: any; }; export default function Field(props: FieldPropsType) { + const [field, setField]: any = useState(props.field); + const [position, setPosition]: any = useState( + props.field.position || { x: 0, y: -842 } + ); + const nodeRef = React.createRef(); + console.log(props.field); + + const onControlledDrag = (e: any, position: any) => { + const { x, y } = position; + setPosition({ x, y }); + }; + + const onDragStop = (e: any, position: any) => { + if (!position) return; + const { x, y } = position; + + props.onPositionChangedHandler({ x, y }, props.field.id); + }; + return ( - - { - e.preventDefault(); - e.stopPropagation(); - }} + +
{/* todo icons */} Signature -
- Timur Ercan

- {""} -
+
{props.field.recipient}
- +
); } diff --git a/apps/web/components/pdf-viewer.jsx b/apps/web/components/pdf-viewer.jsx index b63c367ba..fdea6ee69 100644 --- a/apps/web/components/pdf-viewer.jsx +++ b/apps/web/components/pdf-viewer.jsx @@ -2,11 +2,22 @@ import { Fragment, useState } from "react"; import { Document, Page } from "react-pdf/dist/esm/entry.webpack5"; import Field from "./editor/field"; import short from "short-uuid"; +import { Button } from "@documenso/ui"; +const stc = require("string-to-color"); export default function PDFViewer(props) { const [file, setFile] = useState(""); + const [selectedValue, setSelectedValue] = useState(""); const [numPages, setNumPages] = useState(null); const [loading, setLoading] = useState(true); + const [fields, setFields] = useState([]); + + function onPositionChangedHandler(position, id) { + if (!position) return; + const newFields = [...fields]; + fields.find((e) => e.id == id).position = position; + // setFields(newFields); + } function onFileChange(event) { setFile(event.target.files[0]); @@ -25,6 +36,50 @@ export default function PDFViewer(props) { return ( <> diff --git a/apps/web/package.json b/apps/web/package.json index b1007346d..d1d336497 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -43,6 +43,7 @@ "sass": "^1.57.1", "short-uuid": "^4.2.2", "signature_pad": "^4.1.4", + "string-to-color": "^2.2.2", "typescript": "4.8.4" }, "devDependencies": { diff --git a/apps/web/pages/documents/[id]/index.tsx b/apps/web/pages/documents/[id]/index.tsx index e18ed99b2..56e8e2989 100644 --- a/apps/web/pages/documents/[id]/index.tsx +++ b/apps/web/pages/documents/[id]/index.tsx @@ -23,7 +23,6 @@ const PDFViewer = dynamic(() => import("../../../components/pdf-viewer"), { const DocumentsDetailPage: NextPageWithLayout = (props: any) => { const router = useRouter(); - const [fields, setFields]: any[] = useState([]); return (
@@ -95,34 +94,8 @@ const DocumentsDetailPage: NextPageWithLayout = (props: any) => {
-
- - - - -
diff --git a/package-lock.json b/package-lock.json index c3eca1170..2afd5191b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -76,6 +76,7 @@ "sass": "^1.57.1", "short-uuid": "^4.2.2", "signature_pad": "^4.1.4", + "string-to-color": "^2.2.2", "typescript": "4.8.4" }, "devDependencies": { @@ -8538,7 +8539,7 @@ "@types/nodemailer-sendgrid": "^1.0.0", "@types/react-dom": "18.0.9", "@types/react-pdf": "^6.2.0", - "@types/react-resizable": "*", + "@types/react-resizable": "^3.0.3", "autoprefixer": "^10.4.13", "avatar-from-initials": "^1.0.3", "bcryptjs": "^2.4.3", @@ -8566,6 +8567,7 @@ "sass": "^1.57.1", "short-uuid": "^4.2.2", "signature_pad": "^4.1.4", + "string-to-color": "*", "tailwindcss": "^3.2.4", "typescript": "4.8.4" },