import React, { useState, useEffect } from "react"; import BorderResize from "../component/borderResize"; import PlaceholderBorder from "./placeholderBorder"; import { Rnd } from "react-rnd"; import { defaultWidthHeight, isMobile } from "../../utils/Utils"; import PlaceholderType from "./placeholderType"; import moment from "moment"; import "../LegaDrive/LegaDrive.css"; function Placeholder(props) { const [isDraggingEnabled, setDraggingEnabled] = useState(true); const [isShowDateFormat, setIsShowDateFormat] = useState(false); const [selectDate, setSelectDate] = useState(); const [dateFormat, setDateFormat] = useState([]); const dateFormatArr = ["L", "l", "LL", "ll", "LLL", "lll", "llll"]; const changeDateFormat = () => { const updateDate = []; dateFormatArr.map((data) => { const date = new Date(selectDate); const milliseconds = date.getTime(); const newDate = moment(milliseconds).format(data); updateDate.push(newDate); }); setDateFormat(updateDate); }; useEffect(() => { if (selectDate) { changeDateFormat(); } }, [selectDate]); //handle to close drop down menu onclick screen useEffect(() => { const closeMenuOnOutsideClick = (e) => { if (isShowDateFormat && !e.target.closest("#menu-container")) { setIsShowDateFormat(!isShowDateFormat); } }; document.addEventListener("click", closeMenuOnOutsideClick); return () => { // Cleanup the event listener when the component unmounts document.removeEventListener("click", closeMenuOnOutsideClick); }; }, [isShowDateFormat]); //onclick placeholder function to open signature pad const handlePlaceholderClick = () => { if ( props.pos.type === "text" || props.pos.type === "checkbox" || props.pos.type === "name" || props.pos.type === "company" || props.pos.type === "job title" || props.pos.type === "date" || props.pos.type === "email" ) { setDraggingEnabled(false); } if ((props.isNeedSign || props.isSignYourself) && !props.isDragging) { if (props.pos.type) { if ( props.pos.type === "signature" || props.pos.type === "stamp" || props.pos.type === "image" ) { props.setIsSignPad(true); props.setSignKey(props.pos.key); props.setIsStamp(props.pos.isStamp); } else if (props.pos.type === "initials") { props.setIsSignPad(true); props.setSignKey(props.pos.key); props.setIsStamp(props.pos.isStamp); props.setIsInitial(true); } } else { props.setIsSignPad(true); props.setSignKey(props.pos.key); props.setIsStamp(props.pos?.isStamp ? props.pos.isStamp : false); } } else if ( props.isPlaceholder && props.pos.type === "dropdown" && !props.isDragging ) { props?.setShowDropdown(true); props?.setSignKey(props.pos.key); props.setUniqueId(props.data.Id); } else if (!props.pos.type) { if ( !props.pos.type && props.isNeedSign && props.data.signerObjId === props.signerObjId ) { props.setIsSignPad(true); props.setSignKey(props.pos.key); props.setIsStamp(props.pos.isStamp); } else if ( (props.isNeedSign && props.pos.type === "signature") || props.pos.type === "stamp" ) { props.setIsSignPad(true); props.setSignKey(props.pos.key); props.setIsStamp(props.pos.isStamp); } else if (props.isNeedSign && props.pos.type === "dropdown") { props.setSignKey(props.pos.key); } } }; const PlaceholderIcon = () => { return ( props.isShowBorder && ( <> {props.isPlaceholder && ( <> {props.pos.type === "checkbox" && ( { e.stopPropagation(); props.setIsCheckboxRequired(true); props.setSignKey(props.pos.key); props.setUniqueId(props.data.Id); }} onTouchEnd={(e) => { e.stopPropagation(); props.setIsCheckboxRequired(true); props.setSignKey(props.pos.key); props.setUniqueId(props.data.Id); }} class="fa-solid fa-gear settingIcon" style={{ color: "#188ae2", right: "23px", top: "-35px" }} > )} { e.stopPropagation(); props.handleLinkUser(props.data.Id); props.setUniqueId(props.data.Id); }} onTouchEnd={(e) => { e.stopPropagation(); props.handleLinkUser(props.data.Id); props.setUniqueId(props.data.Id); }} style={{ color: "#188ae2", right: props.pos.type === "checkbox" ? "6px" : "32px", top: props.pos.type === "checkbox" ? "-35px" : "-18px" }} > > )} {props.pos.type === "date" && selectDate && (
)} { if (props.data) { props.setSignerObjId(props.data.signerObjId); } e.stopPropagation(); props.setIsPageCopy(true); props.setSignKey(props.pos.key); }} onTouchEnd={(e) => { if (props.data) { props.setSignerObjId(props.data.signerObjId); } e.stopPropagation(); props.setIsPageCopy(true); props.setSignKey(props.pos.key); }} style={{ color: "#188ae2", right: props.pos.type === "checkbox" && props.isPlaceholder ? "-11px" : "12px", top: props.pos.type === "checkbox" && props.isPlaceholder ? "-35px" : "-18px" }} > { e.stopPropagation(); if (props.data) { props.handleDeleteSign(props.pos.key, props.data.Id); } else { props.handleDeleteSign(props.pos.key); props.setIsStamp(false); } }} onTouchEnd={(e) => { e.stopPropagation(); if (props.data) { props.handleDeleteSign(props.pos.key, props.data.Id); } else { props.handleDeleteSign(props.pos.key); props.setIsStamp(false); } }} style={{ color: "#188ae2", right: props.pos.type === "checkbox" && props.isPlaceholder ? "-30px" : "-8px", top: props.pos.type === "checkbox" && props.isPlaceholder ? "-35px" : "-18px" }} > > ) ); }; return (