import React, { useRef, useState } from "react"; import { useAutoAnimate } from "@formkit/auto-animate/react"; import { color, darkenColor, getFirstLetter, isMobile, nameColor } from "../../constant/Utils"; const cursor = "cursor-[url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEAmpwYAAAASElEQVR4nGNgwAMkJSUbpKSkOvCpIaT5PxSTbogUQjMYMwxeIIXmVFIxA8UGDDyQGg0DnIDi6JKUlCxHMqCeZAOghjSAMD5FAKfeaURdUFxCAAAAAElFTkSuQmCC'),_pointer]"; const RecipientList = (props) => { const [animationParent] = useAutoAnimate(); const [isHover, setIsHover] = useState(); const [isEdit, setIsEdit] = useState(false); //function for onhover signer name change background color const inputRef = useRef(null); const isWidgetExist = (Id) => { return props.signerPos.some((x) => x.Id === Id && x.placeHolder); }; //handle drag start const handleDragStart = (e, id) => { // `e.dataTransfer.setData('text/plain')`is used to set the data to be transferred during a drag operation. // The first argument specifies the type of data being set, and the second argument is the actual data you want to transfer. e.dataTransfer.setData("text/plain", id); }; //handleDragOver prevents the default behavior of the dragover event, which is necessary for the drop event to be triggered. const handleDragOver = (e) => { e.preventDefault(); }; //handle draggable element drop and also used in mobile view on up and down key to change sequence of recipient's list const handleChangeSequence = (e, ind, isUp, isDown, obj) => { e.preventDefault(); let draggedItemId; let index = ind; //if isUp true then set item's id and index in mobile view if (isUp) { draggedItemId = index; index = index - 1; } //if isDown true then set item's id and index in mobile view else if (isDown) { draggedItemId = index; index = index + 1; } //else set id on drag element in desktop viiew else { //`e.dataTransfer.getData('text/plain')` is used to get data that you have saved. draggedItemId = e.dataTransfer.getData("text/plain"); } //convert string to number const intDragId = parseInt(draggedItemId); //get that item to change position const draggedItem = props.signersdata.filter((_, ind) => ind === intDragId); const remainingItems = props.signersdata.filter( (_, ind) => ind !== intDragId ); //splice method is used to replace or add new value in array at specific index remainingItems.splice(index, 0, ...draggedItem); //set current draggable recipient details,objectId,index,contract_className ... after replace recipient list props?.setSignersData(remainingItems); props?.setIsSelectId(index); props?.setUniqueId(remainingItems[index]?.Id); props?.setRoleName(remainingItems[index]?.Role); props?.setBlockColor(obj.blockColor); //change order of placeholder's list using sorting method //`remainingItems` is correct order of signers after change order const changeOrderSignerList = props?.signerPos.sort((a, b) => { //`indexA` and `indexB` is to get element position using index in correct order array const indexA = remainingItems.findIndex((item) => item.Id === a.Id); const indexB = remainingItems.findIndex((item) => item.Id === b.Id); //and then compare `indexA - indexB` value //if positive it means indexB element comes before indexA then need to sorting //if negative it means indexA element is on correct position do not need to sorting return indexA - indexB; }); props?.setSignerPos(changeOrderSignerList); }; return ( <> {props.signersdata?.length > 0 && props.signersdata.map((obj, ind) => { return (