( documentData, signerId, journey, isRemovePrefill )
| 4263 | } |
| 4264 | |
| 4265 | export const updateDateWidgetsRes = ( |
| 4266 | documentData, |
| 4267 | signerId, |
| 4268 | journey, |
| 4269 | isRemovePrefill |
| 4270 | ) => { |
| 4271 | const contactUser = documentData?.Signers?.find( |
| 4272 | (data) => data.objectId === signerId |
| 4273 | ); |
| 4274 | const extUser = |
| 4275 | localStorage.getItem("Extand_Class") || JSON.stringify([contactUser]); |
| 4276 | let placeHolders = documentData?.Placeholders; |
| 4277 | if (isRemovePrefill) { |
| 4278 | placeHolders = placeHolders?.filter((x) => x.Role !== "prefill"); |
| 4279 | } |
| 4280 | const userDetails = extUser ? JSON.parse(extUser)[0] : contactUser; |
| 4281 | return placeHolders?.map((item) => { |
| 4282 | if (item?.signerObjId === signerId || item?.Id === signerId) { |
| 4283 | // Sort page number placeholders |
| 4284 | const placeHolder = Array.isArray(item.placeHolder) |
| 4285 | ? [...item.placeHolder] |
| 4286 | : []; |
| 4287 | const sortedPlaceHolder = placeHolder |
| 4288 | .sort((a, b) => a.pageNumber - b.pageNumber) |
| 4289 | .map((ph) => { |
| 4290 | const sortedWidgets = [...ph.pos] |
| 4291 | .sort((a, b) => { |
| 4292 | // Sort widgets by Y position (top to bottom) and X position (left to right) |
| 4293 | // Treat widgets within 5px Y difference as belonging to the same row |
| 4294 | const Y_TOLERANCE = 5; |
| 4295 | const yDiff = a.yPosition - b.yPosition; |
| 4296 | |
| 4297 | if (Math.abs(yDiff) <= Y_TOLERANCE) { |
| 4298 | return a.xPosition - b.xPosition; // Same row → sort by X |
| 4299 | } |
| 4300 | |
| 4301 | return yDiff; // Different rows → sort by Y |
| 4302 | }) |
| 4303 | .map((widget) => { |
| 4304 | // Update widget values if needed |
| 4305 | if ( |
| 4306 | ["name", "email", "job title", "company"].includes( |
| 4307 | widget.type |
| 4308 | ) && |
| 4309 | !widget.options.defaultValue && |
| 4310 | !widget.options.response && |
| 4311 | userDetails |
| 4312 | ) { |
| 4313 | return { |
| 4314 | ...widget, |
| 4315 | options: { |
| 4316 | ...widget.options, |
| 4317 | response: widgetDataValue(widget.type, userDetails) |
| 4318 | } |
| 4319 | }; |
| 4320 | } |
| 4321 | return widget; |
| 4322 | }); |
no test coverage detected