@clyrex-digital/clyrex-controls-dev 0.8.1-dev.20260810100746 → 0.8.1-dev.20260824062326

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/DataBindingControls-QZ7ES2AS.mjs +205 -0
  2. package/dist/DataBindingControls-XCAIDMDC.mjs +209 -0
  3. package/dist/{InputControlClient-XR37ZIQ2.mjs → InputControlClient-4M2BZXQO.mjs} +5 -3
  4. package/dist/InputControlClient-AORN4DRF.mjs +1921 -0
  5. package/dist/{LinkNodeButton-AOEDCCL7.mjs → LinkNodeButton-BEAX4I4C.mjs} +1 -1
  6. package/dist/LinkNodeButton-IT2CELKO.mjs +225 -0
  7. package/dist/{Pagination-YKNCYVXV.mjs → Pagination-GL6B4MNO.mjs} +5 -3
  8. package/dist/{Pagination-6OFACRMQ.mjs → Pagination-ZQO3EUKB.mjs} +27 -71
  9. package/dist/chunk-2R26M6CK.mjs +30 -0
  10. package/dist/{chunk-KL2YKXXS.mjs → chunk-4P4HO663.mjs} +30 -6
  11. package/dist/chunk-4R7F7LBL.mjs +36 -0
  12. package/dist/chunk-6PW2RLUJ.mjs +52 -0
  13. package/dist/chunk-E4VOFO5Q.mjs +39 -0
  14. package/dist/{chunk-YDPISYMP.mjs → chunk-GCG4OYDJ.mjs} +0 -34
  15. package/dist/{chunk-65QPOTZ4.mjs → chunk-GJOJX2O3.mjs} +1 -1
  16. package/dist/chunk-GKI42H4B.mjs +13 -0
  17. package/dist/{chunk-TVL6KVD5.mjs → chunk-Q46GMD3P.mjs} +31 -37
  18. package/dist/chunk-RHVNJMS4.mjs +251 -0
  19. package/dist/{chunk-WEV5U33G.mjs → chunk-TKDSRAM6.mjs} +36 -20
  20. package/dist/chunk-TQ6BXQ3A.mjs +24 -0
  21. package/dist/{chunk-3GWLDT7C.mjs → chunk-WXZMRMRS.mjs} +36 -20
  22. package/dist/index.d.mts +17 -6
  23. package/dist/index.d.ts +17 -6
  24. package/dist/index.js +600 -316
  25. package/dist/index.mjs +85 -59
  26. package/dist/server.d.mts +17 -6
  27. package/dist/server.d.ts +17 -6
  28. package/dist/server.js +2701 -301
  29. package/dist/server.mjs +70 -55
  30. package/package.json +1 -1
  31. package/dist/LinkNodeButton-KZRNRJRI.mjs +0 -467
package/dist/server.mjs CHANGED
@@ -1,10 +1,16 @@
1
1
  import {
2
- Hyperlink,
3
2
  OdataBuilder
4
- } from "./chunk-TVL6KVD5.mjs";
3
+ } from "./chunk-Q46GMD3P.mjs";
4
+ import {
5
+ AssetUtility_default
6
+ } from "./chunk-TQ6BXQ3A.mjs";
7
+ import {
8
+ Hyperlink
9
+ } from "./chunk-2R26M6CK.mjs";
10
+ import "./chunk-4R7F7LBL.mjs";
5
11
  import {
6
12
  ServiceClient_default
7
- } from "./chunk-3GWLDT7C.mjs";
13
+ } from "./chunk-WXZMRMRS.mjs";
8
14
  import "./chunk-56HSDML5.mjs";
9
15
 
10
16
  // src/components/pageRenderingEngine/PageBodyRenderer.tsx
@@ -95,27 +101,6 @@ var LineBreakNode_default = LineBreakNode;
95
101
  // src/components/pageRenderingEngine/nodes/LinkNode.tsx
96
102
  import React from "react";
97
103
 
98
- // src/components/utilities/AssetUtility.tsx
99
- var AssetUtility = class {
100
- constructor() {
101
- }
102
- static resolveUrl(assetBaseUrl, url) {
103
- if (!url) return void 0;
104
- if (url.startsWith("http")) return url;
105
- if (!assetBaseUrl) return url;
106
- return `${assetBaseUrl}/${url}`;
107
- }
108
- // // static getAssetUrl(apiBaseUrl: string) {
109
- // // let domainName = apiBaseUrl.replace("https://", "");
110
- // // return `https://cdn.g-assets.com/${domainName}`;
111
- // // }
112
- // static getAssetFullPath(apiBaseUrl: string, relativePath: string) {
113
- // const domainName = apiBaseUrl.replace("https://", "");
114
- // return `https://cdn.g-assets.com/${domainName}/${relativePath}`;
115
- // }
116
- };
117
- var AssetUtility_default = AssetUtility;
118
-
119
104
  // src/components/pageRenderingEngine/nodes/ImageNode.tsx
120
105
  import dynamic2 from "next/dynamic";
121
106
 
@@ -305,7 +290,7 @@ var ImageNode_default = ImageNode;
305
290
  // src/components/pageRenderingEngine/nodes/LinkNode.tsx
306
291
  import dynamic3 from "next/dynamic";
307
292
  import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
308
- var LinkNodeButton = dynamic3(() => import("./LinkNodeButton-KZRNRJRI.mjs"), {
293
+ var LinkNodeButton = dynamic3(() => import("./LinkNodeButton-IT2CELKO.mjs"), {
309
294
  ssr: false
310
295
  });
311
296
  function getNestedValue2(obj, path) {
@@ -524,12 +509,6 @@ import { jsx as jsx9 } from "react/jsx-runtime";
524
509
  var BooleanView = (props) => {
525
510
  const { value, customProps } = props;
526
511
  const showOnlyTrueIcon = customProps?.showOnlyTrueIcon;
527
- console.log("BooleanView Debug:", {
528
- value,
529
- type: typeof value,
530
- customProps,
531
- showOnlyTrueIcon
532
- });
533
512
  const booleanValue = (() => {
534
513
  if (typeof value === "boolean") return value;
535
514
  if (typeof value === "string") {
@@ -570,7 +549,6 @@ var MediaAsset = (props) => {
570
549
  if (props.value != void 0 && props.value != null && props.value != "") {
571
550
  try {
572
551
  assets = JSON.parse(props.value);
573
- console.log("Parsed Assets: ", assets);
574
552
  } catch (error) {
575
553
  console.error("Error parsing assets:", error);
576
554
  }
@@ -2132,7 +2110,6 @@ var getFileDetails = (url) => {
2132
2110
  var DocumentNode = (props) => {
2133
2111
  console.log("DocumentNode rendered");
2134
2112
  console.log("props", props);
2135
- console.log("dataitem", props.dataitem);
2136
2113
  console.log("node", props.node);
2137
2114
  let documents = [];
2138
2115
  if (props.dataitem && props.node.documentKey) {
@@ -2286,7 +2263,10 @@ var GoogleMapNode_default = GoogleMapNode;
2286
2263
 
2287
2264
  // src/components/pageRenderingEngine/nodes/DivContainer.tsx
2288
2265
  import { jsx as jsx35, jsxs as jsxs13 } from "react/jsx-runtime";
2289
- var Pagination = dynamic11(() => import("./Pagination-6OFACRMQ.mjs"), { ssr: true });
2266
+ var Pagination = dynamic11(() => import("./Pagination-ZQO3EUKB.mjs"), { ssr: true });
2267
+ var DataBindingControls = dynamic11(() => import("./DataBindingControls-XCAIDMDC.mjs"), {
2268
+ ssr: true
2269
+ });
2290
2270
  var Slider = dynamic11(() => import("./Slider-PEIVH6A5.mjs"), {
2291
2271
  ssr: false
2292
2272
  });
@@ -2701,32 +2681,67 @@ var DivContainer = async (props) => {
2701
2681
  dangerouslySetInnerHTML: { __html: cssResult.css + animationCSS }
2702
2682
  }
2703
2683
  ),
2704
- /* @__PURE__ */ jsx35(
2705
- Wrapper,
2684
+ dataBindingProperties && /* @__PURE__ */ jsx35(
2685
+ DataBindingControls,
2706
2686
  {
2707
- id: guid,
2708
- style: combinedStyles,
2709
- className: classNames || void 0,
2710
- ...wrapperProps,
2711
- children: dataToRender.map(
2712
- (item, idx) => item?.links?.view && renderLink ? renderChildren(
2713
- props.node.children,
2714
- props,
2715
- item,
2716
- idx,
2717
- props.href ? void 0 : item?.links?.view
2718
- )?.map((child, i) => /* @__PURE__ */ jsx35(React22.Fragment, { children: child }, i)) : renderChildren(props.node.children, props, item, idx)
2719
- )
2687
+ mode: "toolbar",
2688
+ path: props.path,
2689
+ query: props.query,
2690
+ facets: response?.facets,
2691
+ sortOptions: response?.sortOptions,
2692
+ showSortOptions: dataBindingProperties.showSortOptions,
2693
+ showSearchBar: dataBindingProperties.showSearchBar
2720
2694
  }
2721
2695
  ),
2722
- dataBindingProperties && props.node.dataBinding.enablePagination && /* @__PURE__ */ jsx35("div", { children: /* @__PURE__ */ jsx35(
2723
- Pagination,
2696
+ /* @__PURE__ */ jsxs13(
2697
+ "div",
2724
2698
  {
2725
- path: props.path,
2726
- query: props.query,
2727
- dataset: response
2699
+ className: dataBindingProperties?.showFacets ? "grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_18rem]" : void 0,
2700
+ children: [
2701
+ /* @__PURE__ */ jsxs13("div", { className: "min-w-0", children: [
2702
+ /* @__PURE__ */ jsx35(
2703
+ Wrapper,
2704
+ {
2705
+ id: guid,
2706
+ style: combinedStyles,
2707
+ className: classNames || void 0,
2708
+ ...wrapperProps,
2709
+ children: dataToRender.map(
2710
+ (item, idx) => item?.links?.view && renderLink ? renderChildren(
2711
+ props.node.children,
2712
+ props,
2713
+ item,
2714
+ idx,
2715
+ props.href ? void 0 : item?.links?.view
2716
+ )?.map((child, i) => /* @__PURE__ */ jsx35(React22.Fragment, { children: child }, i)) : renderChildren(props.node.children, props, item, idx)
2717
+ )
2718
+ }
2719
+ ),
2720
+ dataBindingProperties && props.node.dataBinding.enablePagination && /* @__PURE__ */ jsx35(
2721
+ Pagination,
2722
+ {
2723
+ path: props.path,
2724
+ query: props.query,
2725
+ dataset: response
2726
+ }
2727
+ )
2728
+ ] }),
2729
+ dataBindingProperties?.showFacets && /* @__PURE__ */ jsxs13("aside", { className: "border bg-default p-3 lg:sticky lg:top-[90px] lg:self-start", children: [
2730
+ /* @__PURE__ */ jsx35("h2", { className: "mb-2 text-lg font-semibold", children: "Filters" }),
2731
+ /* @__PURE__ */ jsx35(
2732
+ DataBindingControls,
2733
+ {
2734
+ mode: "facets",
2735
+ path: props.path,
2736
+ query: props.query,
2737
+ facets: response?.facets,
2738
+ showFacets: dataBindingProperties.showFacets
2739
+ }
2740
+ )
2741
+ ] })
2742
+ ]
2728
2743
  }
2729
- ) })
2744
+ )
2730
2745
  ] });
2731
2746
  };
2732
2747
  var DivContainer_default = DivContainer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clyrex-digital/clyrex-controls-dev",
3
- "version": "0.8.1-dev.20260810100746",
3
+ "version": "0.8.1-dev.20260824062326",
4
4
  "description": "Reusable React components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -1,467 +0,0 @@
1
- "use client";
2
- import {
3
- ServiceClient_default
4
- } from "./chunk-3GWLDT7C.mjs";
5
- import {
6
- buttonClasses,
7
- progressClasses
8
- } from "./chunk-56HSDML5.mjs";
9
-
10
- // src/components/pageRenderingEngine/nodes/LinkNodeButton.tsx
11
- import { useCallback, useState as useState3 } from "react";
12
-
13
- // src/components/Button.tsx
14
- import React3, { useState as useState2 } from "react";
15
-
16
- // src/components/ToastService.tsx
17
- var toastHandlersKey = "__digitalStoreToastHandlers";
18
- var getToastHandlers = () => {
19
- const globalScope = globalThis;
20
- if (!globalScope[toastHandlersKey]) {
21
- globalScope[toastHandlersKey] = {};
22
- }
23
- return globalScope[toastHandlersKey];
24
- };
25
- var ToastService = class {
26
- static initialize(showToast, closeToast) {
27
- const handlers = getToastHandlers();
28
- handlers.showToast = showToast;
29
- handlers.closeToast = closeToast;
30
- }
31
- static showError(message) {
32
- const handlers = getToastHandlers();
33
- if (handlers.showToast) {
34
- handlers.showToast(message, "error");
35
- }
36
- }
37
- static showInfo(message) {
38
- const handlers = getToastHandlers();
39
- if (handlers.showToast) {
40
- handlers.showToast(message, "info");
41
- }
42
- }
43
- static showWarning(message) {
44
- const handlers = getToastHandlers();
45
- if (handlers.showToast) {
46
- handlers.showToast(message, "warning");
47
- }
48
- }
49
- static showSuccess(message) {
50
- const handlers = getToastHandlers();
51
- if (handlers.showToast) {
52
- handlers.showToast(message, "success");
53
- }
54
- }
55
- static close() {
56
- const handlers = getToastHandlers();
57
- if (handlers.closeToast) {
58
- handlers.closeToast();
59
- }
60
- }
61
- };
62
- var ToastService_default = ToastService;
63
-
64
- // src/components/Confirm.tsx
65
- import { useState } from "react";
66
-
67
- // src/components/ClientButton.tsx
68
- import React from "react";
69
- import { jsx } from "react/jsx-runtime";
70
- var ClientButton = (props) => {
71
- const execute = async (event) => {
72
- if (props.onClick !== void 0) {
73
- props.onClick();
74
- } else {
75
- ToastService_default.showError("No action defined.");
76
- }
77
- };
78
- let buttonClass = props.ButtonType ? buttonClasses.get(props.ButtonType) : buttonClasses.get("Primary" /* Solid */);
79
- return /* @__PURE__ */ jsx(React.Fragment, { children: /* @__PURE__ */ jsx(
80
- "button",
81
- {
82
- type: "button",
83
- onClick: execute,
84
- className: buttonClass + " " + props.className,
85
- children: props.children
86
- }
87
- ) });
88
- };
89
- var ClientButton_default = ClientButton;
90
-
91
- // src/components/Confirm.tsx
92
- import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
93
- var Confirm = ({ message, onConfirm, onCancel }) => {
94
- const [showModal, setShowModal] = useState(true);
95
- const handleConfirmAction = () => {
96
- setShowModal(false);
97
- if (onConfirm) {
98
- onConfirm();
99
- }
100
- };
101
- const handleCancelAction = () => {
102
- setShowModal(false);
103
- if (onCancel) {
104
- onCancel();
105
- }
106
- };
107
- return /* @__PURE__ */ jsx2(Fragment, { children: showModal && /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 flex items-center justify-center z-50", children: [
108
- /* @__PURE__ */ jsx2("div", { className: "absolute inset-0 bg-black opacity-70" }),
109
- /* @__PURE__ */ jsxs("div", { className: "bg-white rounded-md p-6 w-2/6 shadow border z-50", children: [
110
- /* @__PURE__ */ jsx2("p", { className: "text-xl font-medium mb-4", children: "Confirmation" }),
111
- /* @__PURE__ */ jsx2("p", { className: "mb-4", children: message }),
112
- /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-8", children: [
113
- /* @__PURE__ */ jsx2(
114
- ClientButton_default,
115
- {
116
- onClick: handleCancelAction,
117
- ButtonType: "PrimaryHollow" /* Hollow */,
118
- children: "Cancel"
119
- }
120
- ),
121
- /* @__PURE__ */ jsx2(
122
- ClientButton_default,
123
- {
124
- onClick: handleConfirmAction,
125
- children: "Confirm"
126
- }
127
- )
128
- ] })
129
- ] })
130
- ] }) });
131
- };
132
- var Confirm_default = Confirm;
133
- {
134
- }
135
-
136
- // src/components/Button.tsx
137
- import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
138
- var Button = (props) => {
139
- const [inProgress, setInProgress] = useState2(false);
140
- const [isActionPerformed, setIsActionPerformed] = useState2(false);
141
- const [responseMessage, setResponseMessage] = useState2(null);
142
- const [showModal, setShowModal] = useState2(null);
143
- const execute = async (event) => {
144
- event.preventDefault();
145
- event.stopPropagation();
146
- if (props.confirm) {
147
- const confirmed = await showConfirmation(
148
- "Are you sure you want to delete this item?"
149
- );
150
- setShowModal(null);
151
- if (!confirmed) {
152
- return;
153
- }
154
- }
155
- if (props.oneTimeAction && isActionPerformed) {
156
- return;
157
- }
158
- setInProgress(true);
159
- let isValid = true;
160
- if (props.onValidate !== void 0) {
161
- isValid = await props.onValidate();
162
- if (!isValid) {
163
- setInProgress(false);
164
- ToastService_default.showError(
165
- "There are errors in the form. Please fix them before proceeding."
166
- );
167
- return;
168
- }
169
- }
170
- if (props.onClick !== void 0) {
171
- let response = await props.onClick();
172
- if (response.isSuccessful) {
173
- setIsActionPerformed(true);
174
- setResponseMessage(response.message);
175
- if (props.showToast) {
176
- ToastService_default.showInfo(response.message || "");
177
- }
178
- } else {
179
- ToastService_default.showError(response.message || "");
180
- }
181
- } else {
182
- ToastService_default.showError("No action defined.");
183
- }
184
- setInProgress(false);
185
- };
186
- const showConfirmation = (message) => {
187
- return new Promise((resolve) => {
188
- const onConfirm = () => resolve(true);
189
- const onCancel = () => resolve(false);
190
- setShowModal(
191
- /* @__PURE__ */ jsx3(
192
- Confirm_default,
193
- {
194
- message: props.confirmationMessage,
195
- onConfirm,
196
- onCancel
197
- }
198
- )
199
- );
200
- });
201
- };
202
- let buttonClass = props.ButtonType ? buttonClasses.get(props.ButtonType) : buttonClasses.get("Primary" /* Solid */);
203
- let progressClass = props.ButtonType ? progressClasses.get(props.ButtonType) : progressClasses.get("Primary" /* Solid */);
204
- const isDisabled = inProgress || isActionPerformed && props.oneTimeAction;
205
- return /* @__PURE__ */ jsxs2(React3.Fragment, { children: [
206
- /* @__PURE__ */ jsxs2(
207
- "button",
208
- {
209
- type: "submit",
210
- onClick: execute,
211
- disabled: props.disabled,
212
- title: isDisabled ? "The button is disabled to prevent any action" : "",
213
- className: `${buttonClass} relative inline-flex items-center justify-center gap-2 ${props.className ?? ""}`,
214
- children: [
215
- isActionPerformed && props.oneTimeAction && responseMessage ? responseMessage : props.children,
216
- inProgress && /* @__PURE__ */ jsx3(Fragment2, { children: props.hideProgressIndicator ? /* @__PURE__ */ jsx3("div", { className: "absolute bottom-0 left-0 h-0.5 bg-gray-400 rounded animate-progress" }) : /* @__PURE__ */ jsxs2(
217
- "svg",
218
- {
219
- className: `animate-spin h-5 w-5 flex-shrink-0 ${progressClass}`,
220
- xmlns: "http://www.w3.org/2000/svg",
221
- fill: "none",
222
- viewBox: "0 0 24 24",
223
- children: [
224
- /* @__PURE__ */ jsx3(
225
- "circle",
226
- {
227
- className: "opacity-25",
228
- cx: "12",
229
- cy: "12",
230
- r: "10",
231
- stroke: "currentColor",
232
- strokeWidth: "4"
233
- }
234
- ),
235
- /* @__PURE__ */ jsx3(
236
- "path",
237
- {
238
- className: "opacity-75",
239
- fill: "currentColor",
240
- d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
241
- }
242
- )
243
- ]
244
- }
245
- ) })
246
- ]
247
- }
248
- ),
249
- showModal
250
- ] });
251
- };
252
- var Button_default = Button;
253
-
254
- // src/components/pageRenderingEngine/nodes/LinkNodeButton.tsx
255
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
256
- var LinkNodeButton = (props) => {
257
- const { node, dataitem, children, linkText, linkType, linkUrl } = props;
258
- const [isLoading, setIsLoading] = useState3(false);
259
- const [successMessage, setSuccessMessage] = useState3(null);
260
- console.log("LinkNodeButton props:", props);
261
- const extractFieldNames = useCallback((template) => {
262
- if (!template) return [];
263
- const regex = /\{(\{\})?([a-zA-Z_$][a-zA-Z0-9_$]*)(?:\}\})?\}/g;
264
- const matches = Array.from(template.matchAll(regex));
265
- const fieldNames = matches.map((match) => match[2] || match[1]).filter((name, index, self) => self.indexOf(name) === index);
266
- return fieldNames;
267
- }, []);
268
- const replaceTemplateVariables = useCallback(
269
- (template, responseData) => {
270
- if (!template) return template;
271
- let result = template;
272
- const fieldNames = extractFieldNames(template);
273
- if (responseData) {
274
- fieldNames.forEach((fieldName) => {
275
- const value = getNestedValue(responseData, fieldName);
276
- if (value !== void 0) {
277
- const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
278
- const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
279
- result = result.replace(regex1, String(value));
280
- result = result.replace(regex2, String(value));
281
- }
282
- });
283
- }
284
- if (props.routeParameters) {
285
- Object.entries(props.routeParameters).forEach(([key, value]) => {
286
- const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
287
- result = result.replace(regex, String(value));
288
- });
289
- }
290
- if (dataitem) {
291
- Object.entries(dataitem).forEach(([key, value]) => {
292
- const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
293
- result = result.replace(regex, String(value));
294
- });
295
- }
296
- return result;
297
- },
298
- [props.routeParameters, dataitem, extractFieldNames]
299
- );
300
- const getNestedValue = useCallback((obj, path) => {
301
- if (!obj || !path) return void 0;
302
- if (obj[path] !== void 0) {
303
- return obj[path];
304
- }
305
- const keys = path.split(".");
306
- let current = obj;
307
- for (const key of keys) {
308
- if (current[key] === void 0) {
309
- return void 0;
310
- }
311
- current = current[key];
312
- }
313
- return current;
314
- }, []);
315
- const onClick = useCallback(async () => {
316
- if (!node.postUrl) {
317
- return {
318
- isSuccessful: false,
319
- message: "No POST URL configured for this button"
320
- };
321
- }
322
- setIsLoading(true);
323
- try {
324
- const resolvedPostUrl = replaceTemplateVariables(node.postUrl);
325
- let parsedPayload = {};
326
- if (node.payload) {
327
- try {
328
- const payloadStr = replaceTemplateVariables(node.payload);
329
- parsedPayload = JSON.parse(payloadStr);
330
- console.log("Parsed payload:", parsedPayload);
331
- } catch (err) {
332
- console.error("Failed to parse payload JSON:", err);
333
- parsedPayload = { error: "Invalid payload JSON" };
334
- }
335
- }
336
- const serviceClient = new ServiceClient_default(props.apiBaseUrl, props.session);
337
- const response = await serviceClient.post(resolvedPostUrl, parsedPayload);
338
- console.log("API Response:", response);
339
- if (response && !response.isSuccessful) {
340
- const errorMessage = response.message || "API request failed";
341
- setIsLoading(false);
342
- return { isSuccessful: false, message: errorMessage };
343
- }
344
- if (response?.message) {
345
- ToastService_default.showSuccess(response.message);
346
- setSuccessMessage(response.message);
347
- }
348
- if (response && node.redirectUrl) {
349
- const fieldNames = extractFieldNames(node.redirectUrl);
350
- console.log("Field names in redirect URL:", fieldNames);
351
- const fieldValueMap = {};
352
- fieldNames.forEach((fieldName) => {
353
- const value = getNestedValue(response, fieldName);
354
- if (value !== void 0) {
355
- fieldValueMap[fieldName] = String(value);
356
- } else {
357
- const resultValue = getNestedValue(response, `result.${fieldName}`);
358
- if (resultValue !== void 0) {
359
- fieldValueMap[fieldName] = String(resultValue);
360
- } else {
361
- const dataValue = getNestedValue(response, `data.${fieldName}`);
362
- if (dataValue !== void 0) {
363
- fieldValueMap[fieldName] = String(dataValue);
364
- }
365
- }
366
- }
367
- });
368
- console.log("Field value map:", fieldValueMap);
369
- const missingFields = fieldNames.filter(
370
- (fieldName) => !fieldValueMap[fieldName]
371
- );
372
- if (missingFields.length > 0) {
373
- console.warn(`Missing field values for: ${missingFields.join(", ")}`);
374
- }
375
- let resolvedRedirectUrl = node.redirectUrl;
376
- Object.entries(fieldValueMap).forEach(([fieldName, value]) => {
377
- const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
378
- const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
379
- resolvedRedirectUrl = resolvedRedirectUrl.replace(regex1, value);
380
- resolvedRedirectUrl = resolvedRedirectUrl.replace(regex2, value);
381
- });
382
- resolvedRedirectUrl = replaceTemplateVariables(
383
- resolvedRedirectUrl,
384
- response
385
- );
386
- console.log("Final redirect URL:", resolvedRedirectUrl);
387
- if (resolvedRedirectUrl && !resolvedRedirectUrl.includes("{")) {
388
- window.location.href = resolvedRedirectUrl;
389
- }
390
- } else if (!response) {
391
- const errorMessage = "No response from server";
392
- setIsLoading(false);
393
- return { isSuccessful: false, message: errorMessage };
394
- }
395
- setIsLoading(false);
396
- return {
397
- isSuccessful: true,
398
- message: response?.message,
399
- result: response
400
- };
401
- } catch (err) {
402
- console.error("Button API call failed:", err);
403
- const errorMessage = err.message || "An unexpected error occurred";
404
- setIsLoading(false);
405
- return { isSuccessful: false, message: errorMessage };
406
- }
407
- }, [
408
- node.postUrl,
409
- node.payload,
410
- node.redirectUrl,
411
- replaceTemplateVariables,
412
- extractFieldNames,
413
- getNestedValue,
414
- props.apiBaseUrl,
415
- props.session
416
- ]);
417
- const renderButtonContent = () => {
418
- if (children) {
419
- return children;
420
- }
421
- if (linkText) {
422
- return /* @__PURE__ */ jsx4("span", { children: linkText });
423
- }
424
- return node.title || "Button";
425
- };
426
- const fontSize = node.children?.[0]?.style?.match(/font-size:\s*([^;]+)/)?.[1];
427
- return /* @__PURE__ */ jsx4("div", { className: "link-button-wrapper", children: /* @__PURE__ */ jsx4(
428
- Button_default,
429
- {
430
- ButtonType: linkType,
431
- onClick,
432
- disabled: isLoading || !!successMessage,
433
- className: "w-full",
434
- children: successMessage ? /* @__PURE__ */ jsxs3(
435
- "span",
436
- {
437
- style: fontSize ? { fontSize } : void 0,
438
- className: "inline-flex items-center gap-2",
439
- children: [
440
- /* @__PURE__ */ jsx4(
441
- "svg",
442
- {
443
- xmlns: "http://www.w3.org/2000/svg",
444
- viewBox: "0 0 20 20",
445
- fill: "currentColor",
446
- className: "w-5 h-5",
447
- children: /* @__PURE__ */ jsx4(
448
- "path",
449
- {
450
- fillRule: "evenodd",
451
- d: "M16.704 5.29a1 1 0 010 1.42l-7.25 7.25a1 1 0 01-1.415 0L3.29 9.21a1 1 0 111.415-1.414l4.042 4.042 6.543-6.543a1 1 0 011.414 0z",
452
- clipRule: "evenodd"
453
- }
454
- )
455
- }
456
- ),
457
- /* @__PURE__ */ jsx4("span", { children: successMessage })
458
- ]
459
- }
460
- ) : renderButtonContent()
461
- }
462
- ) });
463
- };
464
- var LinkNodeButton_default = LinkNodeButton;
465
- export {
466
- LinkNodeButton_default as default
467
- };