import { DroppedItemsObj } from "../DocumentContainer"; import React, { useEffect, useState } from "react"; import { dateFormats, dateTimeFormats, timeFormats } from "../../../../utlity/dateTimeFormats"; import { DroppedItem } from "../../../../utlity/types"; import { IoIosArrowDown } from "react-icons/io"; import { TagsTypes } from "../../../../utlity/types"; import LabelAttr from "./LabelAttr"; import RequiredAttr from "./RequiredAttr"; import CurrTimeStampAttr from "./currTimeStampAttr"; import CommonAttrDropDown from "./CommonAttrDropDown"; import MaskTypePassAttr from "./MaskTypePassAttr"; import TemporalDateAttr from "./TemporalDateAttr"; import SelectTagAttr from "./SelectTagAttr"; import MaxMinLenAttr from "./MaxMinLenAttr"; import RecipientsAttrCon from "./RecipientsAttrCon"; import MovableFieldContainer from "./MovableField"; import DirectionalControls from "./DirectionalControls"; // interface DirectionalControlsProps { // onMove: (direction: 'up' | 'down' | 'left' | 'right') => void; // disabled?: boolean; // stepSize?: number; // className?: string; // } export interface DroppedItemProps { selectedTag: DroppedItem setDroppedItems: React.Dispatch> selTagKey: string, selTagIndx: number, DirectionalControlsProps: { onMove: (direction: 'up' | 'down' | 'left' | 'right', stepSize?: number) => void; disabled?: boolean; stepSize?: number; className?: string; } } export enum TEXT { PARAGRAPH = "paragraph", SINGLE_LINE = "single_line", PASSWORD = "password", } export enum TEMPORAL { DATE = "date", TIME = "time", DATE_TIME = "date_time", } export enum NUMBER { INTEGER = "integer", DECIMAL = "decimal", CURRENCY = "currency" } export enum SELECT { SINGLE_SELECT = "single select", MULTI_SELECT = "multi select" } export enum MASKTYPE { ALL = "all", LAST_FOUR = "last_four", CREDIT_CARD = "credit_Card", NATIONAL_INSURANCE = "national_insurance", SOCIAL_SECURITY = "social_security", SOCIAL_INSURANCE = "social_insurance" } export enum MASKCHARACTER { ASTERISK = "ASTERISK", DOT = "DOT", X = "CROSS", } export const enumMap = { text: TEXT, temporal: TEMPORAL, number: NUMBER, image: String, select: SELECT } export enum DROPDOWNTOGGLE { TYPE, MASK_TYPE, MASK_CHARACTER, DDMMYY_FORMAT } const defaultStyles = { font: "", italic: false, bold: false, underline: false, color: "#000000", textSize: 0 }; const RightSideBar: React.FC = ({ selectedTag, setDroppedItems, selTagKey, selTagIndx, DirectionalControlsProps }) => { const selectedType = selectedTag.type in enumMap && enumMap[selectedTag.type as keyof typeof enumMap]; console.log("selectedTag", selectedTag, selectedType) const [styles, setStyles] = useState(defaultStyles); const [dropDownToggle, setDropDownToggle] = useState(null); const [decimalPlace, setDecimalPlace] = useState(2) const [styleOpen, setStyleOpen] = useState(false); const handlePropertyChange = (changeTo: string, changeWith: string | boolean | number, is24Hrs = null) => { console.log("changeTo", changeTo, "changeWith", changeWith) if (changeTo === '' || changeWith === '') return if (changeWith === "paragraph") { return } if (changeTo === "subType" && (changeWith === TEMPORAL.DATE || changeWith === TEMPORAL.DATE_TIME || changeWith === TEMPORAL.TIME)) { // let change: string = changeWith; // if (change === "DATE TIME") { // change = "DATE_TIME" // } setDroppedItems((prev) => { console.log("Temporal30", prev); return { ...prev, [selTagKey]: Array.isArray(prev[selTagKey]) // Ensure it's an array ? prev[selTagKey].map((item, i) => i === selTagIndx ? { ...item, [changeTo]: changeWith || "", format: "", update: true } : item ) : [], // Fallback in case it's undefined or not an array }; }); } else if (changeTo === "subType" && typeof changeWith === "string" && changeWith.toLowerCase() === "password") { console.log("Second check") console.log("Line 161") setDroppedItems((prev) => ( { ...prev, [selTagKey]: Array.isArray(prev[selTagKey]) ? prev[selTagKey].map((item, i) => i === selTagIndx ? { ...item, [changeTo]: changeWith, maskType: "All", maskCharacter: "ASTERISK", update: true } : item ) : [], } )); } else if (changeTo === "subType" && (changeWith === NUMBER.CURRENCY || changeWith === NUMBER.INTEGER || changeWith === NUMBER.DECIMAL)) { console.log("Third check") let decPlace = changeWith !== NUMBER.DECIMAL ? 0 : decimalPlace; const isCurrency = changeWith === NUMBER.CURRENCY; // const currencyType = null setDroppedItems((prev) => ( { ...prev, [selTagKey]: Array.isArray(prev[selTagKey]) // Ensure it's an array ? prev[selTagKey].map((item, i) => i === selTagIndx ? { ...item, [changeTo]: changeWith, decimalPlace: decPlace, isCurrency, update: true } : item ) : [], }// Provide a fallback in case it's undefined or not an array )); } else if (changeTo === "format" && selectedTag.subType === TEMPORAL.DATE_TIME) { console.log("Fourth Check") let val = timeFormats[0].format; if (!is24Hrs) { val = timeFormats[1].format } console.log("val", val) setDroppedItems((prev) => { const updatedArray = Array.isArray(prev[selTagKey]) ? prev[selTagKey].map((item, i) => { if (i === selTagIndx) { const updatedItem = { ...item, [changeTo]: changeWith + " " + val, update: true }; console.log('Updating item at index', i, 'with:', updatedItem); return updatedItem; } return item; }) : []; return { ...prev, [selTagKey]: updatedArray, }; }); } else { setDroppedItems((prev) => { const updatedItems = Array.isArray(prev[selTagKey]) ? prev[selTagKey].map((item, i) => i === selTagIndx ? { ...item, [changeTo]: changeWith, update: true } : item ) : []; console.log('Updated items:', updatedItems); return { ...prev, [selTagKey]: updatedItems, }; }); } setDropDownToggle(null) } useEffect(() => { if (selectedTag.subType === TEMPORAL.DATE || selectedTag.subType === TEMPORAL.DATE_TIME || selectedTag.subType === TEMPORAL.TIME) { if (selectedTag.subType === TEMPORAL.DATE) { handlePropertyChange("format", dateFormats[0].format) } else if (selectedTag.subType === TEMPORAL.DATE_TIME) { handlePropertyChange("format", dateTimeFormats[0].format) } else if (selectedTag.subType === TEMPORAL.TIME) { handlePropertyChange("format", timeFormats[0].format) } } }, [selectedTag.subType]) useEffect(() => { if (selectedTag.label === "temporal") { handlePropertyChange("subType", TEMPORAL.DATE); handlePropertyChange("format", "DD/MM/YY"); } }, []) const handleDecimalPlace = (e: React.ChangeEvent) => { const val = Number(e.target.value) setDecimalPlace(val) handlePropertyChange("decimalPlace", val) } // useEffect(() => { // if ("styles" in selectedTag) { // console.log("styles" in selectedTag) // const fontSize = selectedTag?.styles?.textSize; // const tagHeight = selectedTag?.dimensions?.height - 18; // console.log(fontSize) // if (selectedTag.subType !== TEXT.PASSWORD && selectedTag.subType !== TEXT.PARAGRAPH && tagHeight > (fontSize + fontSize)) { // handlePropertyChange("subType", TEXT.PARAGRAPH) // } else if (selectedTag.subType !== TEXT.PASSWORD && selectedTag.subType !== TEXT.SINGLE_LINE && tagHeight <= (fontSize + fontSize)) { // console.log("Change subType Called from elseif") // handlePropertyChange("subType", TEXT.SINGLE_LINE) // } // } // }, [selectedTag]) useEffect(() => { if (!selectedTag) return; if (!selectedTag.styles) { handlePropertyChange("styles", defaultStyles); setStyles(defaultStyles); } else { setStyles({ ...defaultStyles, ...selectedTag.styles }); } // Optional subType logic const fontSize = selectedTag?.styles?.textSize || defaultStyles.textSize; const tagHeight = selectedTag?.dimensions?.height - 18; if ( selectedTag.subType !== TEXT.PASSWORD && selectedTag.subType !== TEXT.PARAGRAPH && tagHeight > fontSize * 2 ) { handlePropertyChange("subType", TEXT.PARAGRAPH); } else if ( selectedTag.subType !== TEXT.PASSWORD && selectedTag.subType !== TEXT.SINGLE_LINE && tagHeight <= fontSize * 2 ) { handlePropertyChange("subType", TEXT.SINGLE_LINE); } }, [selectedTag]); const handleStyleChange = (key, value) => { const updatedStyles = { ...(selectedTag.styles ?? defaultStyles), [key]: value }; setStyles(updatedStyles); handlePropertyChange("styles", updatedStyles); }; return ( <> {/* Right Side Bar Start */}

Properties


{ } {selectedTag.label && } {(selectedTag.type !== TagsTypes.SIGNATURE && selectedTag.type !== TagsTypes.INITIALS) && <> } {selectedTag.type.toLowerCase() === TagsTypes.TEMPORAL && } { selectedType && Object.keys(selectedType).length > 0 && } {/* Mask Type */} { selectedTag?.subType === TEXT.PASSWORD && } {/* TEMPORAL DATE FORMAT - START */} { (selectedTag?.subType === TEMPORAL.DATE || selectedTag?.subType === TEMPORAL.TIME || selectedTag?.subType === TEMPORAL.DATE_TIME) && } {/* TEMPORAL DATE FORMAT - END */} {/* NUMBER - DECIMAL PLACES */} { selectedTag?.subType === NUMBER.DECIMAL &&
handleDecimalPlace(e)} value={decimalPlace} className="bg-slate-100 w-full outline-none p-2 rounded" />
} { (selectedTag?.subType === SELECT.SINGLE_SELECT || selectedTag?.subType === SELECT.MULTI_SELECT) && } { (selectedTag.type.toLowerCase() === TagsTypes.TEXT || selectedTag.type.toLowerCase() === TagsTypes.COMPANY) && } {(selectedTag.type.toLowerCase() !== TagsTypes.SIGNATURE && selectedTag.type.toLowerCase() !== TagsTypes.INITIALS) &&
setStyleOpen(!styleOpen)} >
{ styleOpen && <> {/* Font */}
handleStyleChange("font", e.target.value)} />
{/* Text Size */}
handleStyleChange("textSize", parseInt(e.target.value, 10) || 0) } />
{/* Color */}
handleStyleChange("color", e.target.value)} />
{/* Toggles for Bold, Italic, Underline */}
}
}
{/* Right Side Bar End */} ) } export default RightSideBar