@acoustte-digital-services/digitalstore-controls-dev 0.8.1-dev.20260722071904 → 0.8.1-dev.20260722072521
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.
- package/dist/EnterAnimationClient-4OKXLKSA.mjs +45 -0
- package/dist/EnterAnimationClient-ZN3NLFNO.mjs +47 -0
- package/dist/InputControlClient-AZRPSTUZ.mjs +677 -0
- package/dist/InputControlClient-HIZOJLKW.mjs +677 -0
- package/dist/{InputControlClient-7FJWGZDN.mjs → InputControlClient-QAZKQLFO.mjs} +23 -23
- package/dist/{InputControlClient-5RK7QDZZ.mjs → InputControlClient-QQCQD4EG.mjs} +23 -23
- package/dist/{LinkNodeButton-AOEDCCL7.mjs → LinkNodeButton-LX3KKGZY.mjs} +38 -92
- package/dist/LinkNodeButton-U7T2NP22.mjs +374 -0
- package/dist/{LinkNodeButton-BIZA2NPE.mjs → LinkNodeButton-XA7Z5IDR.mjs} +38 -92
- package/dist/Pagination-6OFACRMQ.mjs +229 -0
- package/dist/Pagination-OQT7Q2XO.mjs +183 -0
- package/dist/chunk-3R4VVVNK.mjs +903 -0
- package/dist/chunk-FI2KJBK2.mjs +110 -0
- package/dist/{chunk-23WJE3YB.mjs → chunk-JKP4XOZB.mjs} +9 -48
- package/dist/chunk-OGGIS4AN.mjs +201 -0
- package/dist/chunk-TVL6KVD5.mjs +229 -0
- package/dist/{chunk-RHVNJMS4.mjs → chunk-YL6E76X2.mjs} +9 -48
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +100 -191
- package/dist/index.mjs +51 -45
- package/dist/server.d.mts +113 -0
- package/dist/server.d.ts +113 -0
- package/dist/server.js +5179 -0
- package/dist/server.mjs +2736 -0
- package/package.json +5 -8
- package/server.d.ts +0 -1
- package/server.js +0 -1
|
@@ -0,0 +1,374 @@
|
|
|
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 { 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("Are you sure you want to delete this item?");
|
|
148
|
+
setShowModal(null);
|
|
149
|
+
if (!confirmed) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (props.oneTimeAction && isActionPerformed) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
setInProgress(true);
|
|
157
|
+
let isValid = true;
|
|
158
|
+
if (props.onValidate !== void 0) {
|
|
159
|
+
isValid = await props.onValidate();
|
|
160
|
+
if (!isValid) {
|
|
161
|
+
setInProgress(false);
|
|
162
|
+
ToastService_default.showError("There are errors in the form. Please fix them before proceeding.");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (props.onClick !== void 0) {
|
|
167
|
+
let response = await props.onClick();
|
|
168
|
+
if (response.isSuccessful) {
|
|
169
|
+
setIsActionPerformed(true);
|
|
170
|
+
setResponseMessage(response.message);
|
|
171
|
+
if (props.showToast) {
|
|
172
|
+
ToastService_default.showInfo(response.message || "");
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
ToastService_default.showError(response.message || "");
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
ToastService_default.showError("No action defined.");
|
|
179
|
+
}
|
|
180
|
+
setInProgress(false);
|
|
181
|
+
};
|
|
182
|
+
const showConfirmation = (message) => {
|
|
183
|
+
return new Promise((resolve) => {
|
|
184
|
+
const onConfirm = () => resolve(true);
|
|
185
|
+
const onCancel = () => resolve(false);
|
|
186
|
+
setShowModal(/* @__PURE__ */ jsx3(Confirm_default, { message: props.confirmationMessage, onConfirm, onCancel }));
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
let buttonClass = props.ButtonType ? buttonClasses.get(props.ButtonType) : buttonClasses.get("Primary" /* Solid */);
|
|
190
|
+
let progressClass = props.ButtonType ? progressClasses.get(props.ButtonType) : progressClasses.get("Primary" /* Solid */);
|
|
191
|
+
const isDisabled = inProgress || isActionPerformed && props.oneTimeAction;
|
|
192
|
+
return /* @__PURE__ */ jsxs2(React3.Fragment, { children: [
|
|
193
|
+
/* @__PURE__ */ jsxs2(
|
|
194
|
+
"button",
|
|
195
|
+
{
|
|
196
|
+
type: "submit",
|
|
197
|
+
onClick: execute,
|
|
198
|
+
disabled: props.disabled,
|
|
199
|
+
title: isDisabled ? "The button is disabled to prevent any action" : "",
|
|
200
|
+
className: buttonClass + " relative " + props.className,
|
|
201
|
+
children: [
|
|
202
|
+
isActionPerformed && props.oneTimeAction && responseMessage ? responseMessage : props.children,
|
|
203
|
+
inProgress && /* @__PURE__ */ jsx3(React3.Fragment, { children: props.hideProgressIndicator === true ? /* @__PURE__ */ jsx3("div", { className: "absolute bottom-0 left-0 h-0.5 bg-gray-400 rounded animate-progress" }) : /* @__PURE__ */ jsxs2("svg", { className: "animate-spin ml-2 mr-3 h-5 w-5 " + progressClass, xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
|
|
204
|
+
/* @__PURE__ */ jsx3("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
205
|
+
/* @__PURE__ */ jsx3("path", { className: "opacity-75", fill: "currentColor", 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" })
|
|
206
|
+
] }) })
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
showModal
|
|
211
|
+
] });
|
|
212
|
+
};
|
|
213
|
+
var Button_default = Button;
|
|
214
|
+
|
|
215
|
+
// src/components/pageRenderingEngine/nodes/LinkNodeButton.tsx
|
|
216
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
217
|
+
var LinkNodeButton = (props) => {
|
|
218
|
+
const { node, dataitem, children, linkText, linkType, linkUrl } = props;
|
|
219
|
+
const [isLoading, setIsLoading] = useState3(false);
|
|
220
|
+
const extractFieldNames = useCallback((template) => {
|
|
221
|
+
if (!template) return [];
|
|
222
|
+
const regex = /\{(\{\})?([a-zA-Z_$][a-zA-Z0-9_$]*)(?:\}\})?\}/g;
|
|
223
|
+
const matches = Array.from(template.matchAll(regex));
|
|
224
|
+
const fieldNames = matches.map((match) => match[2] || match[1]).filter((name, index, self) => self.indexOf(name) === index);
|
|
225
|
+
return fieldNames;
|
|
226
|
+
}, []);
|
|
227
|
+
const replaceTemplateVariables = useCallback((template, responseData) => {
|
|
228
|
+
if (!template) return template;
|
|
229
|
+
let result = template;
|
|
230
|
+
const fieldNames = extractFieldNames(template);
|
|
231
|
+
if (responseData) {
|
|
232
|
+
fieldNames.forEach((fieldName) => {
|
|
233
|
+
const value = getNestedValue(responseData, fieldName);
|
|
234
|
+
if (value !== void 0) {
|
|
235
|
+
const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
|
|
236
|
+
const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
|
|
237
|
+
result = result.replace(regex1, String(value));
|
|
238
|
+
result = result.replace(regex2, String(value));
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (props.routeParameters) {
|
|
243
|
+
Object.entries(props.routeParameters).forEach(([key, value]) => {
|
|
244
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
|
|
245
|
+
result = result.replace(regex, String(value));
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
if (dataitem) {
|
|
249
|
+
Object.entries(dataitem).forEach(([key, value]) => {
|
|
250
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
|
|
251
|
+
result = result.replace(regex, String(value));
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
255
|
+
}, [props.routeParameters, dataitem, extractFieldNames]);
|
|
256
|
+
const getNestedValue = useCallback((obj, path) => {
|
|
257
|
+
if (!obj || !path) return void 0;
|
|
258
|
+
if (obj[path] !== void 0) {
|
|
259
|
+
return obj[path];
|
|
260
|
+
}
|
|
261
|
+
const keys = path.split(".");
|
|
262
|
+
let current = obj;
|
|
263
|
+
for (const key of keys) {
|
|
264
|
+
if (current[key] === void 0) {
|
|
265
|
+
return void 0;
|
|
266
|
+
}
|
|
267
|
+
current = current[key];
|
|
268
|
+
}
|
|
269
|
+
return current;
|
|
270
|
+
}, []);
|
|
271
|
+
const onClick = useCallback(async () => {
|
|
272
|
+
if (!node.postUrl) {
|
|
273
|
+
return { isSuccessful: false, message: "No POST URL configured for this button" };
|
|
274
|
+
}
|
|
275
|
+
setIsLoading(true);
|
|
276
|
+
try {
|
|
277
|
+
const resolvedPostUrl = replaceTemplateVariables(node.postUrl);
|
|
278
|
+
let parsedPayload = {};
|
|
279
|
+
if (node.payload) {
|
|
280
|
+
try {
|
|
281
|
+
const payloadStr = replaceTemplateVariables(node.payload);
|
|
282
|
+
parsedPayload = JSON.parse(payloadStr);
|
|
283
|
+
console.log("Parsed payload:", parsedPayload);
|
|
284
|
+
} catch (err) {
|
|
285
|
+
console.error("Failed to parse payload JSON:", err);
|
|
286
|
+
parsedPayload = { error: "Invalid payload JSON" };
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const serviceClient = new ServiceClient_default(props.apiBaseUrl, props.session);
|
|
290
|
+
const response = await serviceClient.post(resolvedPostUrl, parsedPayload);
|
|
291
|
+
console.log("API Response:", response);
|
|
292
|
+
if (response && !response.isSuccessful) {
|
|
293
|
+
const errorMessage = response.message || "API request failed";
|
|
294
|
+
setIsLoading(false);
|
|
295
|
+
return { isSuccessful: false, message: errorMessage };
|
|
296
|
+
}
|
|
297
|
+
if (response?.message) {
|
|
298
|
+
ToastService_default.showSuccess(response.message);
|
|
299
|
+
}
|
|
300
|
+
if (response && node.redirectUrl) {
|
|
301
|
+
const fieldNames = extractFieldNames(node.redirectUrl);
|
|
302
|
+
console.log("Field names in redirect URL:", fieldNames);
|
|
303
|
+
const fieldValueMap = {};
|
|
304
|
+
fieldNames.forEach((fieldName) => {
|
|
305
|
+
const value = getNestedValue(response, fieldName);
|
|
306
|
+
if (value !== void 0) {
|
|
307
|
+
fieldValueMap[fieldName] = String(value);
|
|
308
|
+
} else {
|
|
309
|
+
const resultValue = getNestedValue(response, `result.${fieldName}`);
|
|
310
|
+
if (resultValue !== void 0) {
|
|
311
|
+
fieldValueMap[fieldName] = String(resultValue);
|
|
312
|
+
} else {
|
|
313
|
+
const dataValue = getNestedValue(response, `data.${fieldName}`);
|
|
314
|
+
if (dataValue !== void 0) {
|
|
315
|
+
fieldValueMap[fieldName] = String(dataValue);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
console.log("Field value map:", fieldValueMap);
|
|
321
|
+
const missingFields = fieldNames.filter((fieldName) => !fieldValueMap[fieldName]);
|
|
322
|
+
if (missingFields.length > 0) {
|
|
323
|
+
console.warn(`Missing field values for: ${missingFields.join(", ")}`);
|
|
324
|
+
}
|
|
325
|
+
let resolvedRedirectUrl = node.redirectUrl;
|
|
326
|
+
Object.entries(fieldValueMap).forEach(([fieldName, value]) => {
|
|
327
|
+
const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
|
|
328
|
+
const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
|
|
329
|
+
resolvedRedirectUrl = resolvedRedirectUrl.replace(regex1, value);
|
|
330
|
+
resolvedRedirectUrl = resolvedRedirectUrl.replace(regex2, value);
|
|
331
|
+
});
|
|
332
|
+
resolvedRedirectUrl = replaceTemplateVariables(resolvedRedirectUrl, response);
|
|
333
|
+
console.log("Final redirect URL:", resolvedRedirectUrl);
|
|
334
|
+
if (resolvedRedirectUrl && !resolvedRedirectUrl.includes("{")) {
|
|
335
|
+
window.location.href = resolvedRedirectUrl;
|
|
336
|
+
}
|
|
337
|
+
} else if (!response) {
|
|
338
|
+
const errorMessage = "No response from server";
|
|
339
|
+
setIsLoading(false);
|
|
340
|
+
return { isSuccessful: false, message: errorMessage };
|
|
341
|
+
}
|
|
342
|
+
setIsLoading(false);
|
|
343
|
+
return { isSuccessful: true, message: response?.message, result: response };
|
|
344
|
+
} catch (err) {
|
|
345
|
+
console.error("Button API call failed:", err);
|
|
346
|
+
const errorMessage = err.message || "An unexpected error occurred";
|
|
347
|
+
setIsLoading(false);
|
|
348
|
+
return { isSuccessful: false, message: errorMessage };
|
|
349
|
+
}
|
|
350
|
+
}, [node.postUrl, node.payload, node.redirectUrl, replaceTemplateVariables, extractFieldNames, getNestedValue, props.apiBaseUrl, props.session]);
|
|
351
|
+
const renderButtonContent = () => {
|
|
352
|
+
if (children) {
|
|
353
|
+
return children;
|
|
354
|
+
}
|
|
355
|
+
if (linkText) {
|
|
356
|
+
return /* @__PURE__ */ jsx4("span", { children: linkText });
|
|
357
|
+
}
|
|
358
|
+
return node.title || "Button";
|
|
359
|
+
};
|
|
360
|
+
return /* @__PURE__ */ jsx4("div", { className: "link-button-wrapper", children: /* @__PURE__ */ jsx4(
|
|
361
|
+
Button_default,
|
|
362
|
+
{
|
|
363
|
+
ButtonType: linkType,
|
|
364
|
+
onClick,
|
|
365
|
+
disabled: isLoading,
|
|
366
|
+
className: "w-full",
|
|
367
|
+
children: renderButtonContent()
|
|
368
|
+
}
|
|
369
|
+
) });
|
|
370
|
+
};
|
|
371
|
+
var LinkNodeButton_default = LinkNodeButton;
|
|
372
|
+
export {
|
|
373
|
+
LinkNodeButton_default as default
|
|
374
|
+
};
|
|
@@ -5,17 +5,15 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
Button_default,
|
|
7
7
|
ToastService_default
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YL6E76X2.mjs";
|
|
9
9
|
import "./chunk-56HSDML5.mjs";
|
|
10
10
|
|
|
11
11
|
// src/components/pageRenderingEngine/nodes/LinkNodeButton.tsx
|
|
12
12
|
import { useCallback, useState } from "react";
|
|
13
|
-
import { jsx
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
14
|
var LinkNodeButton = (props) => {
|
|
15
15
|
const { node, dataitem, children, linkText, linkType, linkUrl } = props;
|
|
16
16
|
const [isLoading, setIsLoading] = useState(false);
|
|
17
|
-
const [successMessage, setSuccessMessage] = useState(null);
|
|
18
|
-
console.log("LinkNodeButton props:", props);
|
|
19
17
|
const extractFieldNames = useCallback((template) => {
|
|
20
18
|
if (!template) return [];
|
|
21
19
|
const regex = /\{(\{\})?([a-zA-Z_$][a-zA-Z0-9_$]*)(?:\}\})?\}/g;
|
|
@@ -23,38 +21,35 @@ var LinkNodeButton = (props) => {
|
|
|
23
21
|
const fieldNames = matches.map((match) => match[2] || match[1]).filter((name, index, self) => self.indexOf(name) === index);
|
|
24
22
|
return fieldNames;
|
|
25
23
|
}, []);
|
|
26
|
-
const replaceTemplateVariables = useCallback(
|
|
27
|
-
(template
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
[props.routeParameters, dataitem, extractFieldNames]
|
|
57
|
-
);
|
|
24
|
+
const replaceTemplateVariables = useCallback((template, responseData) => {
|
|
25
|
+
if (!template) return template;
|
|
26
|
+
let result = template;
|
|
27
|
+
const fieldNames = extractFieldNames(template);
|
|
28
|
+
if (responseData) {
|
|
29
|
+
fieldNames.forEach((fieldName) => {
|
|
30
|
+
const value = getNestedValue(responseData, fieldName);
|
|
31
|
+
if (value !== void 0) {
|
|
32
|
+
const regex1 = new RegExp(`\\{${fieldName}\\}`, "g");
|
|
33
|
+
const regex2 = new RegExp(`\\{\\{${fieldName}\\}\\}`, "g");
|
|
34
|
+
result = result.replace(regex1, String(value));
|
|
35
|
+
result = result.replace(regex2, String(value));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (props.routeParameters) {
|
|
40
|
+
Object.entries(props.routeParameters).forEach(([key, value]) => {
|
|
41
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
|
|
42
|
+
result = result.replace(regex, String(value));
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (dataitem) {
|
|
46
|
+
Object.entries(dataitem).forEach(([key, value]) => {
|
|
47
|
+
const regex = new RegExp(`\\{\\{${key}\\}\\}`, "g");
|
|
48
|
+
result = result.replace(regex, String(value));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}, [props.routeParameters, dataitem, extractFieldNames]);
|
|
58
53
|
const getNestedValue = useCallback((obj, path) => {
|
|
59
54
|
if (!obj || !path) return void 0;
|
|
60
55
|
if (obj[path] !== void 0) {
|
|
@@ -72,10 +67,7 @@ var LinkNodeButton = (props) => {
|
|
|
72
67
|
}, []);
|
|
73
68
|
const onClick = useCallback(async () => {
|
|
74
69
|
if (!node.postUrl) {
|
|
75
|
-
return {
|
|
76
|
-
isSuccessful: false,
|
|
77
|
-
message: "No POST URL configured for this button"
|
|
78
|
-
};
|
|
70
|
+
return { isSuccessful: false, message: "No POST URL configured for this button" };
|
|
79
71
|
}
|
|
80
72
|
setIsLoading(true);
|
|
81
73
|
try {
|
|
@@ -101,7 +93,6 @@ var LinkNodeButton = (props) => {
|
|
|
101
93
|
}
|
|
102
94
|
if (response?.message) {
|
|
103
95
|
ToastService_default.showSuccess(response.message);
|
|
104
|
-
setSuccessMessage(response.message);
|
|
105
96
|
}
|
|
106
97
|
if (response && node.redirectUrl) {
|
|
107
98
|
const fieldNames = extractFieldNames(node.redirectUrl);
|
|
@@ -124,9 +115,7 @@ var LinkNodeButton = (props) => {
|
|
|
124
115
|
}
|
|
125
116
|
});
|
|
126
117
|
console.log("Field value map:", fieldValueMap);
|
|
127
|
-
const missingFields = fieldNames.filter(
|
|
128
|
-
(fieldName) => !fieldValueMap[fieldName]
|
|
129
|
-
);
|
|
118
|
+
const missingFields = fieldNames.filter((fieldName) => !fieldValueMap[fieldName]);
|
|
130
119
|
if (missingFields.length > 0) {
|
|
131
120
|
console.warn(`Missing field values for: ${missingFields.join(", ")}`);
|
|
132
121
|
}
|
|
@@ -137,10 +126,7 @@ var LinkNodeButton = (props) => {
|
|
|
137
126
|
resolvedRedirectUrl = resolvedRedirectUrl.replace(regex1, value);
|
|
138
127
|
resolvedRedirectUrl = resolvedRedirectUrl.replace(regex2, value);
|
|
139
128
|
});
|
|
140
|
-
resolvedRedirectUrl = replaceTemplateVariables(
|
|
141
|
-
resolvedRedirectUrl,
|
|
142
|
-
response
|
|
143
|
-
);
|
|
129
|
+
resolvedRedirectUrl = replaceTemplateVariables(resolvedRedirectUrl, response);
|
|
144
130
|
console.log("Final redirect URL:", resolvedRedirectUrl);
|
|
145
131
|
if (resolvedRedirectUrl && !resolvedRedirectUrl.includes("{")) {
|
|
146
132
|
window.location.href = resolvedRedirectUrl;
|
|
@@ -151,27 +137,14 @@ var LinkNodeButton = (props) => {
|
|
|
151
137
|
return { isSuccessful: false, message: errorMessage };
|
|
152
138
|
}
|
|
153
139
|
setIsLoading(false);
|
|
154
|
-
return {
|
|
155
|
-
isSuccessful: true,
|
|
156
|
-
message: response?.message,
|
|
157
|
-
result: response
|
|
158
|
-
};
|
|
140
|
+
return { isSuccessful: true, message: response?.message, result: response };
|
|
159
141
|
} catch (err) {
|
|
160
142
|
console.error("Button API call failed:", err);
|
|
161
143
|
const errorMessage = err.message || "An unexpected error occurred";
|
|
162
144
|
setIsLoading(false);
|
|
163
145
|
return { isSuccessful: false, message: errorMessage };
|
|
164
146
|
}
|
|
165
|
-
}, [
|
|
166
|
-
node.postUrl,
|
|
167
|
-
node.payload,
|
|
168
|
-
node.redirectUrl,
|
|
169
|
-
replaceTemplateVariables,
|
|
170
|
-
extractFieldNames,
|
|
171
|
-
getNestedValue,
|
|
172
|
-
props.apiBaseUrl,
|
|
173
|
-
props.session
|
|
174
|
-
]);
|
|
147
|
+
}, [node.postUrl, node.payload, node.redirectUrl, replaceTemplateVariables, extractFieldNames, getNestedValue, props.apiBaseUrl, props.session]);
|
|
175
148
|
const renderButtonContent = () => {
|
|
176
149
|
if (children) {
|
|
177
150
|
return children;
|
|
@@ -181,41 +154,14 @@ var LinkNodeButton = (props) => {
|
|
|
181
154
|
}
|
|
182
155
|
return node.title || "Button";
|
|
183
156
|
};
|
|
184
|
-
const fontSize = node.children?.[0]?.style?.match(/font-size:\s*([^;]+)/)?.[1];
|
|
185
157
|
return /* @__PURE__ */ jsx("div", { className: "link-button-wrapper", children: /* @__PURE__ */ jsx(
|
|
186
158
|
Button_default,
|
|
187
159
|
{
|
|
188
160
|
ButtonType: linkType,
|
|
189
161
|
onClick,
|
|
190
|
-
disabled: isLoading
|
|
162
|
+
disabled: isLoading,
|
|
191
163
|
className: "w-full",
|
|
192
|
-
children:
|
|
193
|
-
"span",
|
|
194
|
-
{
|
|
195
|
-
style: fontSize ? { fontSize } : void 0,
|
|
196
|
-
className: "inline-flex items-center gap-2",
|
|
197
|
-
children: [
|
|
198
|
-
/* @__PURE__ */ jsx(
|
|
199
|
-
"svg",
|
|
200
|
-
{
|
|
201
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
202
|
-
viewBox: "0 0 20 20",
|
|
203
|
-
fill: "currentColor",
|
|
204
|
-
className: "w-5 h-5",
|
|
205
|
-
children: /* @__PURE__ */ jsx(
|
|
206
|
-
"path",
|
|
207
|
-
{
|
|
208
|
-
fillRule: "evenodd",
|
|
209
|
-
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",
|
|
210
|
-
clipRule: "evenodd"
|
|
211
|
-
}
|
|
212
|
-
)
|
|
213
|
-
}
|
|
214
|
-
),
|
|
215
|
-
/* @__PURE__ */ jsx("span", { children: successMessage })
|
|
216
|
-
]
|
|
217
|
-
}
|
|
218
|
-
) : renderButtonContent()
|
|
164
|
+
children: renderButtonContent()
|
|
219
165
|
}
|
|
220
166
|
) });
|
|
221
167
|
};
|