import React, { useEffect, useState } from 'react'; import fields from '../../../helper/fieldsListData'; // import api from '../../../config/api'; import { useParams } from 'react-router-dom'; import typeToIconMap from '../../../helper/iconMap'; import { FaQuestionCircle } from 'react-icons/fa'; import { TagsProperties, TagsTypes } from '../../../utlity/types'; import { v4 as uuidv4 } from "uuid"; import axios from 'axios'; const handlePointerDown = (event: React.DragEvent, label: string, recipientId: number, recipientIndx: number, tagsProperties: TagsProperties) => { const dragElemRect = event.currentTarget.getBoundingClientRect(); let width = dragElemRect.width let height = dragElemRect.height if (label === TagsTypes.RADIO || label === TagsTypes.CHECKBOX) { const innerIconConRect = event.currentTarget.children[0].getBoundingClientRect(); width = innerIconConRect.width + 10 height = innerIconConRect.height + 10 } // Handling Initia Width and height of Some tags - START if (label === TagsTypes.STAMP) { width = 160 height = 160 } else if (label === TagsTypes.SIGNATURE) { width = 200 height = 75 } else if (label === TagsTypes.INITIALS) { width = 85 height = 75 } // Handling Initia Width and height of Some tags - END const offsetX = event.clientX - dragElemRect.left; const offsetY = event.clientY - dragElemRect.top; const obj = { label, offsetX, offsetY, recipientId: recipientId, recipientIndx: recipientIndx, width, height, properties: tagsProperties } if (obj.label.toLowerCase() === "radio" || obj.label.toLowerCase() === "checkbox") obj.group = uuidv4(); window.dragElemData = JSON.stringify(obj); } interface FieldListProps { color: string; recipientId: number; recipientIndx: number; acntId?: string | null; } const FieldList: React.FC = ({ color, recipientId, recipientIndx, acntId = null }) => { const [tagsData, setTagsData] = useState([]); let { accountId } = useParams<{ accountId: string }>(); if (acntId) { accountId = acntId; } if (!accountId) { window.location.href = "/"; return null; } useEffect(() => { axios .get(`${import.meta.env.VITE_BASE_URI}/api/accounts/${accountId}/tags`, { headers: { "ngrok-skip-browser-warning": "69420", } }) .then((res) => { const priorityOrder = ['SIGNATURE', 'INITIALS', 'STAMP']; const data = res.data; // Separate prioritized and other tags const prioritized = data.filter((tag: any) => priorityOrder.includes(tag.type) ); const others = data .filter((tag: any) => !priorityOrder.includes(tag.type)) .sort((a: any, b: any) => a.type.localeCompare(b.type)); // Maintain the custom order of priority const prioritizedSorted = priorityOrder .map((type) => prioritized.find((tag: any) => tag.type === type)) .filter(Boolean); // remove undefined in case not found setTagsData([...prioritizedSorted, ...others]); }) .catch((err) => { console.error(err.message); }); }, []); return (
{tagsData.map((field, index) => { const IconComponent = typeToIconMap[field.type] || ; // Optional: skip unknown types if (!IconComponent) return null; return ( //
handleDragStart(e, field.label, recipientId)} className="p-1 flex justify-start items-center gap-2 rounded-sm cursor-grab hover:bg-slate-200 transition-all duration-300">
handlePointerDown(e, field.type.toLowerCase(), recipientId, recipientIndx, field)} className="p-1 flex justify-start items-center gap-2 rounded-sm cursor-grab hover:bg-slate-200 transition-all duration-300">
{IconComponent}

{field.type.toLowerCase()}

) } )}
); }; export default FieldList;