@inspirer-dev/crm-dashboard 1.0.10 → 1.0.12
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/admin/src/components/ButtonsBuilder/index.tsx +259 -0
- package/admin/src/components/CancelConditionsField/constants.ts +104 -0
- package/admin/src/components/CancelConditionsField/index.tsx +381 -0
- package/admin/src/components/TriggerConfigField/index.tsx +333 -0
- package/admin/src/index.ts +76 -2
- package/dist/_chunks/{index-CNvqpnNt.mjs → index-BSDO36Pf.mjs} +1 -468
- package/dist/_chunks/index-Bnjm_sYk.mjs +339 -0
- package/dist/_chunks/index-Cf8DZYT6.js +341 -0
- package/dist/_chunks/index-CiwOzO0B.js +377 -0
- package/dist/_chunks/index-DFqEb9sm.mjs +253 -0
- package/dist/_chunks/index-DRJ5o0cz.js +253 -0
- package/dist/_chunks/index-XE6toVNT.mjs +170 -0
- package/dist/_chunks/index-d16UivTb.js +170 -0
- package/dist/_chunks/utils-C6_ndVAZ.mjs +491 -0
- package/dist/_chunks/utils-CmonL0io.js +490 -0
- package/dist/admin/index.js +73 -2
- package/dist/admin/index.mjs +74 -3
- package/dist/server/index.js +15 -0
- package/dist/server/index.mjs +15 -0
- package/package.json +1 -1
- package/server/src/register.ts +18 -0
- package/dist/_chunks/index-DIwnSzER.js +0 -844
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const designSystem = require("@strapi/design-system");
|
|
6
|
+
const DEFAULT_CONFIG = {
|
|
7
|
+
type: "event_based",
|
|
8
|
+
eventName: "",
|
|
9
|
+
delayValue: 10,
|
|
10
|
+
delayUnit: "minutes",
|
|
11
|
+
scheduleType: "daily",
|
|
12
|
+
scheduleTime: "12:00",
|
|
13
|
+
scheduleDays: [1, 2, 3, 4, 5],
|
|
14
|
+
scheduleCron: "0 12 * * *"
|
|
15
|
+
};
|
|
16
|
+
const WEEKDAYS = [
|
|
17
|
+
{ value: 0, label: "Sun" },
|
|
18
|
+
{ value: 1, label: "Mon" },
|
|
19
|
+
{ value: 2, label: "Tue" },
|
|
20
|
+
{ value: 3, label: "Wed" },
|
|
21
|
+
{ value: 4, label: "Thu" },
|
|
22
|
+
{ value: 5, label: "Fri" },
|
|
23
|
+
{ value: 6, label: "Sat" }
|
|
24
|
+
];
|
|
25
|
+
const parseConfig = (value) => {
|
|
26
|
+
if (!value) return DEFAULT_CONFIG;
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(value);
|
|
29
|
+
return {
|
|
30
|
+
type: parsed.type || "event_based",
|
|
31
|
+
eventName: parsed.eventName || "",
|
|
32
|
+
delayValue: parsed.delayValue ?? 10,
|
|
33
|
+
delayUnit: parsed.delayUnit || "minutes",
|
|
34
|
+
scheduleType: parsed.scheduleType || "daily",
|
|
35
|
+
scheduleTime: parsed.scheduleTime || "12:00",
|
|
36
|
+
scheduleDays: parsed.scheduleDays || [1, 2, 3, 4, 5],
|
|
37
|
+
scheduleCron: parsed.scheduleCron || "0 12 * * *"
|
|
38
|
+
};
|
|
39
|
+
} catch {
|
|
40
|
+
return DEFAULT_CONFIG;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const serializeConfig = (config) => {
|
|
44
|
+
return JSON.stringify(config);
|
|
45
|
+
};
|
|
46
|
+
const TriggerConfigField = React.forwardRef(
|
|
47
|
+
({ name, value, onChange, intlLabel, disabled, error, required, hint }, ref) => {
|
|
48
|
+
const [config, setConfig] = React.useState(() => parseConfig(value));
|
|
49
|
+
React.useEffect(() => {
|
|
50
|
+
const parsed = parseConfig(value);
|
|
51
|
+
setConfig(parsed);
|
|
52
|
+
}, [value]);
|
|
53
|
+
const handleUpdate = (updates) => {
|
|
54
|
+
const newConfig = { ...config, ...updates };
|
|
55
|
+
setConfig(newConfig);
|
|
56
|
+
onChange({
|
|
57
|
+
target: {
|
|
58
|
+
name,
|
|
59
|
+
value: serializeConfig(newConfig)
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const toggleDay = (day) => {
|
|
64
|
+
const days = config.scheduleDays || [];
|
|
65
|
+
const newDays = days.includes(day) ? days.filter((d) => d !== day) : [...days, day].sort((a, b) => a - b);
|
|
66
|
+
handleUpdate({ scheduleDays: newDays });
|
|
67
|
+
};
|
|
68
|
+
const isEventBased = config.type === "event_based";
|
|
69
|
+
const isDbBased = config.type === "db_based";
|
|
70
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Root, { name, error, required, hint, ref, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 3, children: [
|
|
71
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: intlLabel?.defaultMessage || "Trigger Configuration" }),
|
|
72
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { marginBottom: "8px", display: "block" }, children: "Campaign Type" }),
|
|
74
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
|
|
75
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
76
|
+
designSystem.Box,
|
|
77
|
+
{
|
|
78
|
+
padding: 3,
|
|
79
|
+
background: isEventBased ? "primary100" : "neutral100",
|
|
80
|
+
hasRadius: true,
|
|
81
|
+
style: {
|
|
82
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
83
|
+
border: `2px solid ${isEventBased ? "#4945ff" : "#dcdce4"}`,
|
|
84
|
+
flex: 1,
|
|
85
|
+
textAlign: "center"
|
|
86
|
+
},
|
|
87
|
+
onClick: () => !disabled && handleUpdate({ type: "event_based" }),
|
|
88
|
+
children: [
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
90
|
+
designSystem.Typography,
|
|
91
|
+
{
|
|
92
|
+
variant: "omega",
|
|
93
|
+
fontWeight: isEventBased ? "bold" : "regular",
|
|
94
|
+
textColor: isEventBased ? "primary600" : "neutral600",
|
|
95
|
+
children: "Event-Based"
|
|
96
|
+
}
|
|
97
|
+
),
|
|
98
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: "Fires on user action" })
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
),
|
|
102
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
103
|
+
designSystem.Box,
|
|
104
|
+
{
|
|
105
|
+
padding: 3,
|
|
106
|
+
background: isDbBased ? "primary100" : "neutral100",
|
|
107
|
+
hasRadius: true,
|
|
108
|
+
style: {
|
|
109
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
110
|
+
border: `2px solid ${isDbBased ? "#4945ff" : "#dcdce4"}`,
|
|
111
|
+
flex: 1,
|
|
112
|
+
textAlign: "center"
|
|
113
|
+
},
|
|
114
|
+
onClick: () => !disabled && handleUpdate({ type: "db_based" }),
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
117
|
+
designSystem.Typography,
|
|
118
|
+
{
|
|
119
|
+
variant: "omega",
|
|
120
|
+
fontWeight: isDbBased ? "bold" : "regular",
|
|
121
|
+
textColor: isDbBased ? "primary600" : "neutral600",
|
|
122
|
+
children: "DB-Based (Scheduled)"
|
|
123
|
+
}
|
|
124
|
+
),
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: "Runs on schedule" })
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
] })
|
|
130
|
+
] }),
|
|
131
|
+
isEventBased && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { background: "neutral100", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.CardContent, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 4, padding: 4, children: [
|
|
132
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Event Configuration" }),
|
|
133
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `${name}-eventName`, children: [
|
|
134
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Event Name" }),
|
|
135
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
136
|
+
designSystem.TextInput,
|
|
137
|
+
{
|
|
138
|
+
placeholder: "e.g., gg-case-deposit",
|
|
139
|
+
value: config.eventName || "",
|
|
140
|
+
onChange: (e) => handleUpdate({ eventName: e.target.value }),
|
|
141
|
+
disabled
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: "The event that triggers this campaign (e.g., gg-case-deposit, gg-deposit-suggestion-selected)" })
|
|
145
|
+
] }),
|
|
146
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
|
|
147
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral800", style: { marginBottom: "8px", display: "block" }, children: "Delay Before Sending" }),
|
|
148
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "flex-start", children: [
|
|
149
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { width: "120px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
150
|
+
designSystem.TextInput,
|
|
151
|
+
{
|
|
152
|
+
type: "number",
|
|
153
|
+
value: String(config.delayValue || 0),
|
|
154
|
+
onChange: (e) => handleUpdate({ delayValue: parseInt(e.target.value, 10) || 0 }),
|
|
155
|
+
disabled,
|
|
156
|
+
"aria-label": "Delay value"
|
|
157
|
+
}
|
|
158
|
+
) }),
|
|
159
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { width: "150px" }, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
160
|
+
designSystem.SingleSelect,
|
|
161
|
+
{
|
|
162
|
+
value: config.delayUnit || "minutes",
|
|
163
|
+
onChange: (val) => handleUpdate({ delayUnit: val }),
|
|
164
|
+
disabled,
|
|
165
|
+
children: [
|
|
166
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "seconds", children: "seconds" }),
|
|
167
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "minutes", children: "minutes" }),
|
|
168
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "hours", children: "hours" })
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
) })
|
|
172
|
+
] }),
|
|
173
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", style: { marginTop: "4px" }, children: "Wait this long after the event before checking segment rules and sending" })
|
|
174
|
+
] })
|
|
175
|
+
] }) }) }),
|
|
176
|
+
isDbBased && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Card, { background: "neutral100", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.CardContent, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 4, padding: 4, children: [
|
|
177
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", children: "Schedule Configuration" }),
|
|
178
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `${name}-scheduleType`, children: [
|
|
179
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Schedule Type" }),
|
|
180
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
181
|
+
designSystem.SingleSelect,
|
|
182
|
+
{
|
|
183
|
+
value: config.scheduleType || "daily",
|
|
184
|
+
onChange: (val) => handleUpdate({ scheduleType: val }),
|
|
185
|
+
disabled,
|
|
186
|
+
children: [
|
|
187
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "daily", children: "Daily" }),
|
|
188
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "weekly", children: "Weekly" }),
|
|
189
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "cron", children: "Custom (Cron)" })
|
|
190
|
+
]
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
] }),
|
|
194
|
+
(config.scheduleType === "daily" || config.scheduleType === "weekly") && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `${name}-scheduleTime`, children: [
|
|
195
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Time of Day (UTC)" }),
|
|
196
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
197
|
+
designSystem.TextInput,
|
|
198
|
+
{
|
|
199
|
+
type: "time",
|
|
200
|
+
value: config.scheduleTime || "12:00",
|
|
201
|
+
onChange: (e) => handleUpdate({ scheduleTime: e.target.value }),
|
|
202
|
+
disabled
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
] }),
|
|
206
|
+
config.scheduleType === "weekly" && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
|
|
207
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral800", style: { marginBottom: "8px", display: "block" }, children: "Days of Week" }),
|
|
208
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 2, wrap: "wrap", children: WEEKDAYS.map((day) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
209
|
+
designSystem.Box,
|
|
210
|
+
{
|
|
211
|
+
padding: 2,
|
|
212
|
+
background: (config.scheduleDays || []).includes(day.value) ? "primary100" : "neutral100",
|
|
213
|
+
hasRadius: true,
|
|
214
|
+
style: {
|
|
215
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
216
|
+
border: `1px solid ${(config.scheduleDays || []).includes(day.value) ? "#4945ff" : "#dcdce4"}`,
|
|
217
|
+
minWidth: "50px",
|
|
218
|
+
textAlign: "center"
|
|
219
|
+
},
|
|
220
|
+
onClick: () => !disabled && toggleDay(day.value),
|
|
221
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
222
|
+
designSystem.Typography,
|
|
223
|
+
{
|
|
224
|
+
variant: "omega",
|
|
225
|
+
textColor: (config.scheduleDays || []).includes(day.value) ? "primary600" : "neutral600",
|
|
226
|
+
children: day.label
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
},
|
|
230
|
+
day.value
|
|
231
|
+
)) })
|
|
232
|
+
] }),
|
|
233
|
+
config.scheduleType === "cron" && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `${name}-scheduleCron`, children: [
|
|
234
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Cron Expression" }),
|
|
235
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
236
|
+
designSystem.TextInput,
|
|
237
|
+
{
|
|
238
|
+
placeholder: "0 12 * * *",
|
|
239
|
+
value: config.scheduleCron || "",
|
|
240
|
+
onChange: (e) => handleUpdate({ scheduleCron: e.target.value }),
|
|
241
|
+
disabled
|
|
242
|
+
}
|
|
243
|
+
),
|
|
244
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: 'Standard cron format: minute hour day month weekday (e.g., "0 12 * * *" = daily at 12:00 UTC)' })
|
|
245
|
+
] })
|
|
246
|
+
] }) }) }),
|
|
247
|
+
error && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, { children: error }),
|
|
248
|
+
hint && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: hint })
|
|
249
|
+
] }) });
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
TriggerConfigField.displayName = "TriggerConfigField";
|
|
253
|
+
exports.default = TriggerConfigField;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useState, useEffect, useMemo } from "react";
|
|
3
|
+
import { Field, Flex, Typography, Box, TextInput, Tooltip, IconButton, Button, Badge } from "@strapi/design-system";
|
|
4
|
+
import { ArrowUp, ArrowDown, Trash, Plus } from "@strapi/icons";
|
|
5
|
+
import { m as generateId } from "./utils-C6_ndVAZ.mjs";
|
|
6
|
+
const parseButtons = (value) => {
|
|
7
|
+
if (!value) return [];
|
|
8
|
+
try {
|
|
9
|
+
const parsed = JSON.parse(value);
|
|
10
|
+
if (!Array.isArray(parsed)) return [];
|
|
11
|
+
return parsed.map((b) => ({
|
|
12
|
+
id: typeof b?.id === "string" ? b.id : generateId(),
|
|
13
|
+
text: typeof b?.text === "string" ? b.text : "",
|
|
14
|
+
url: typeof b?.url === "string" ? b.url : "",
|
|
15
|
+
row: typeof b?.row === "number" ? b.row : 0
|
|
16
|
+
}));
|
|
17
|
+
} catch {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const serializeButtons = (buttons) => JSON.stringify(buttons);
|
|
22
|
+
const isValidUrl = (url) => {
|
|
23
|
+
try {
|
|
24
|
+
const u = new URL(url);
|
|
25
|
+
return u.protocol === "http:" || u.protocol === "https:";
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const ButtonsBuilder = forwardRef(
|
|
31
|
+
({ name, value, onChange, intlLabel, disabled, error, required, hint }, ref) => {
|
|
32
|
+
const [buttons, setButtons] = useState(() => parseButtons(value));
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
setButtons(parseButtons(value));
|
|
35
|
+
}, [value]);
|
|
36
|
+
const update = (next) => {
|
|
37
|
+
setButtons(next);
|
|
38
|
+
onChange({ target: { name, value: serializeButtons(next) } });
|
|
39
|
+
};
|
|
40
|
+
const addButton = () => {
|
|
41
|
+
update([
|
|
42
|
+
...buttons,
|
|
43
|
+
{ id: generateId(), text: "Button", url: "https://cases.gg", row: 0 }
|
|
44
|
+
]);
|
|
45
|
+
};
|
|
46
|
+
const updateButton = (id, patch) => {
|
|
47
|
+
update(buttons.map((b) => b.id === id ? { ...b, ...patch } : b));
|
|
48
|
+
};
|
|
49
|
+
const deleteButton = (id) => {
|
|
50
|
+
update(buttons.filter((b) => b.id !== id));
|
|
51
|
+
};
|
|
52
|
+
const move = (from, to) => {
|
|
53
|
+
if (to < 0 || to >= buttons.length) return;
|
|
54
|
+
const copy = [...buttons];
|
|
55
|
+
const [item] = copy.splice(from, 1);
|
|
56
|
+
copy.splice(to, 0, item);
|
|
57
|
+
update(copy);
|
|
58
|
+
};
|
|
59
|
+
const previewRows = useMemo(() => {
|
|
60
|
+
const rows = /* @__PURE__ */ new Map();
|
|
61
|
+
for (const b of buttons) {
|
|
62
|
+
const row = b.row ?? 0;
|
|
63
|
+
rows.set(row, [...rows.get(row) || [], b]);
|
|
64
|
+
}
|
|
65
|
+
return Array.from(rows.entries()).sort((a, b) => a[0] - b[0]).map(([row, items]) => ({ row, items }));
|
|
66
|
+
}, [buttons]);
|
|
67
|
+
return /* @__PURE__ */ jsx(Field.Root, { name, error, required, hint, ref, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 3, children: [
|
|
68
|
+
/* @__PURE__ */ jsx(Field.Label, { children: intlLabel?.defaultMessage || "Buttons" }),
|
|
69
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: "Build Telegram inline keyboard buttons (text + URL). Stored as JSON." }),
|
|
70
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 2, children: [
|
|
71
|
+
buttons.map((btn, idx) => {
|
|
72
|
+
const urlOk = btn.url.length === 0 ? true : isValidUrl(btn.url);
|
|
73
|
+
return /* @__PURE__ */ jsxs(
|
|
74
|
+
Flex,
|
|
75
|
+
{
|
|
76
|
+
gap: 2,
|
|
77
|
+
alignItems: "flex-start",
|
|
78
|
+
padding: 3,
|
|
79
|
+
background: "neutral0",
|
|
80
|
+
hasRadius: true,
|
|
81
|
+
style: { border: "1px solid #dcdce4" },
|
|
82
|
+
children: [
|
|
83
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 2, minWidth: 180 }, children: /* @__PURE__ */ jsxs(Field.Root, { name: `${name}.${btn.id}.text`, children: [
|
|
84
|
+
/* @__PURE__ */ jsx(Field.Label, { children: "Text" }),
|
|
85
|
+
/* @__PURE__ */ jsx(
|
|
86
|
+
TextInput,
|
|
87
|
+
{
|
|
88
|
+
value: btn.text,
|
|
89
|
+
onChange: (e) => updateButton(btn.id, { text: e.target.value }),
|
|
90
|
+
disabled
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
] }) }),
|
|
94
|
+
/* @__PURE__ */ jsx(Box, { style: { flex: 3, minWidth: 220 }, children: /* @__PURE__ */ jsxs(Field.Root, { name: `${name}.${btn.id}.url`, children: [
|
|
95
|
+
/* @__PURE__ */ jsx(Field.Label, { children: "URL" }),
|
|
96
|
+
/* @__PURE__ */ jsx(
|
|
97
|
+
TextInput,
|
|
98
|
+
{
|
|
99
|
+
value: btn.url,
|
|
100
|
+
onChange: (e) => updateButton(btn.id, { url: e.target.value }),
|
|
101
|
+
disabled
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
!urlOk && /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger600", style: { marginTop: 4 }, children: "Please enter a valid http/https URL" })
|
|
105
|
+
] }) }),
|
|
106
|
+
/* @__PURE__ */ jsx(Box, { style: { width: 90 }, children: /* @__PURE__ */ jsxs(Field.Root, { name: `${name}.${btn.id}.row`, children: [
|
|
107
|
+
/* @__PURE__ */ jsx(Field.Label, { children: "Row" }),
|
|
108
|
+
/* @__PURE__ */ jsx(
|
|
109
|
+
TextInput,
|
|
110
|
+
{
|
|
111
|
+
type: "number",
|
|
112
|
+
value: String(btn.row ?? 0),
|
|
113
|
+
onChange: (e) => updateButton(btn.id, { row: parseInt(e.target.value, 10) || 0 }),
|
|
114
|
+
disabled
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
] }) }),
|
|
118
|
+
/* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, paddingTop: 6, children: [
|
|
119
|
+
/* @__PURE__ */ jsx(Tooltip, { label: "Move up", children: /* @__PURE__ */ jsx(
|
|
120
|
+
IconButton,
|
|
121
|
+
{
|
|
122
|
+
onClick: () => move(idx, idx - 1),
|
|
123
|
+
label: "Move up",
|
|
124
|
+
variant: "ghost",
|
|
125
|
+
disabled: disabled || idx === 0,
|
|
126
|
+
children: /* @__PURE__ */ jsx(ArrowUp, {})
|
|
127
|
+
}
|
|
128
|
+
) }),
|
|
129
|
+
/* @__PURE__ */ jsx(Tooltip, { label: "Move down", children: /* @__PURE__ */ jsx(
|
|
130
|
+
IconButton,
|
|
131
|
+
{
|
|
132
|
+
onClick: () => move(idx, idx + 1),
|
|
133
|
+
label: "Move down",
|
|
134
|
+
variant: "ghost",
|
|
135
|
+
disabled: disabled || idx === buttons.length - 1,
|
|
136
|
+
children: /* @__PURE__ */ jsx(ArrowDown, {})
|
|
137
|
+
}
|
|
138
|
+
) }),
|
|
139
|
+
/* @__PURE__ */ jsx(Tooltip, { label: "Delete button", children: /* @__PURE__ */ jsx(
|
|
140
|
+
IconButton,
|
|
141
|
+
{
|
|
142
|
+
onClick: () => deleteButton(btn.id),
|
|
143
|
+
label: "Delete button",
|
|
144
|
+
variant: "ghost",
|
|
145
|
+
disabled,
|
|
146
|
+
children: /* @__PURE__ */ jsx(Trash, {})
|
|
147
|
+
}
|
|
148
|
+
) })
|
|
149
|
+
] })
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
btn.id
|
|
153
|
+
);
|
|
154
|
+
}),
|
|
155
|
+
buttons.length === 0 && /* @__PURE__ */ jsx(Box, { padding: 4, background: "neutral0", hasRadius: true, style: { border: "1px dashed #dcdce4" }, children: /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: "No buttons. Add one to create an inline keyboard." }) })
|
|
156
|
+
] }),
|
|
157
|
+
/* @__PURE__ */ jsx(Flex, { gap: 2, children: /* @__PURE__ */ jsx(Button, { startIcon: /* @__PURE__ */ jsx(Plus, {}), onClick: addButton, disabled, variant: "secondary", children: "Add button" }) }),
|
|
158
|
+
buttons.length > 0 && /* @__PURE__ */ jsxs(Box, { paddingTop: 2, children: [
|
|
159
|
+
/* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", style: { marginBottom: 8, display: "block" }, children: "Preview" }),
|
|
160
|
+
/* @__PURE__ */ jsx(Flex, { direction: "column", gap: 2, children: previewRows.map((row) => /* @__PURE__ */ jsx(Flex, { gap: 1, wrap: "wrap", children: row.items.map((b) => /* @__PURE__ */ jsx(Badge, { backgroundColor: "primary100", children: b.text || "(empty)" }, b.id)) }, row.row)) })
|
|
161
|
+
] }),
|
|
162
|
+
error && /* @__PURE__ */ jsx(Field.Error, { children: error }),
|
|
163
|
+
hint && /* @__PURE__ */ jsx(Field.Hint, { children: hint })
|
|
164
|
+
] }) });
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
ButtonsBuilder.displayName = "ButtonsBuilder";
|
|
168
|
+
export {
|
|
169
|
+
ButtonsBuilder as default
|
|
170
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const designSystem = require("@strapi/design-system");
|
|
6
|
+
const icons = require("@strapi/icons");
|
|
7
|
+
const utils = require("./utils-CmonL0io.js");
|
|
8
|
+
const parseButtons = (value) => {
|
|
9
|
+
if (!value) return [];
|
|
10
|
+
try {
|
|
11
|
+
const parsed = JSON.parse(value);
|
|
12
|
+
if (!Array.isArray(parsed)) return [];
|
|
13
|
+
return parsed.map((b) => ({
|
|
14
|
+
id: typeof b?.id === "string" ? b.id : utils.generateId(),
|
|
15
|
+
text: typeof b?.text === "string" ? b.text : "",
|
|
16
|
+
url: typeof b?.url === "string" ? b.url : "",
|
|
17
|
+
row: typeof b?.row === "number" ? b.row : 0
|
|
18
|
+
}));
|
|
19
|
+
} catch {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const serializeButtons = (buttons) => JSON.stringify(buttons);
|
|
24
|
+
const isValidUrl = (url) => {
|
|
25
|
+
try {
|
|
26
|
+
const u = new URL(url);
|
|
27
|
+
return u.protocol === "http:" || u.protocol === "https:";
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const ButtonsBuilder = React.forwardRef(
|
|
33
|
+
({ name, value, onChange, intlLabel, disabled, error, required, hint }, ref) => {
|
|
34
|
+
const [buttons, setButtons] = React.useState(() => parseButtons(value));
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
setButtons(parseButtons(value));
|
|
37
|
+
}, [value]);
|
|
38
|
+
const update = (next) => {
|
|
39
|
+
setButtons(next);
|
|
40
|
+
onChange({ target: { name, value: serializeButtons(next) } });
|
|
41
|
+
};
|
|
42
|
+
const addButton = () => {
|
|
43
|
+
update([
|
|
44
|
+
...buttons,
|
|
45
|
+
{ id: utils.generateId(), text: "Button", url: "https://cases.gg", row: 0 }
|
|
46
|
+
]);
|
|
47
|
+
};
|
|
48
|
+
const updateButton = (id, patch) => {
|
|
49
|
+
update(buttons.map((b) => b.id === id ? { ...b, ...patch } : b));
|
|
50
|
+
};
|
|
51
|
+
const deleteButton = (id) => {
|
|
52
|
+
update(buttons.filter((b) => b.id !== id));
|
|
53
|
+
};
|
|
54
|
+
const move = (from, to) => {
|
|
55
|
+
if (to < 0 || to >= buttons.length) return;
|
|
56
|
+
const copy = [...buttons];
|
|
57
|
+
const [item] = copy.splice(from, 1);
|
|
58
|
+
copy.splice(to, 0, item);
|
|
59
|
+
update(copy);
|
|
60
|
+
};
|
|
61
|
+
const previewRows = React.useMemo(() => {
|
|
62
|
+
const rows = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const b of buttons) {
|
|
64
|
+
const row = b.row ?? 0;
|
|
65
|
+
rows.set(row, [...rows.get(row) || [], b]);
|
|
66
|
+
}
|
|
67
|
+
return Array.from(rows.entries()).sort((a, b) => a[0] - b[0]).map(([row, items]) => ({ row, items }));
|
|
68
|
+
}, [buttons]);
|
|
69
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Root, { name, error, required, hint, ref, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 3, children: [
|
|
70
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: intlLabel?.defaultMessage || "Buttons" }),
|
|
71
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: "Build Telegram inline keyboard buttons (text + URL). Stored as JSON." }),
|
|
72
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
|
|
73
|
+
buttons.map((btn, idx) => {
|
|
74
|
+
const urlOk = btn.url.length === 0 ? true : isValidUrl(btn.url);
|
|
75
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
76
|
+
designSystem.Flex,
|
|
77
|
+
{
|
|
78
|
+
gap: 2,
|
|
79
|
+
alignItems: "flex-start",
|
|
80
|
+
padding: 3,
|
|
81
|
+
background: "neutral0",
|
|
82
|
+
hasRadius: true,
|
|
83
|
+
style: { border: "1px solid #dcdce4" },
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: 2, minWidth: 180 }, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `${name}.${btn.id}.text`, children: [
|
|
86
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Text" }),
|
|
87
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
+
designSystem.TextInput,
|
|
89
|
+
{
|
|
90
|
+
value: btn.text,
|
|
91
|
+
onChange: (e) => updateButton(btn.id, { text: e.target.value }),
|
|
92
|
+
disabled
|
|
93
|
+
}
|
|
94
|
+
)
|
|
95
|
+
] }) }),
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: 3, minWidth: 220 }, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `${name}.${btn.id}.url`, children: [
|
|
97
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "URL" }),
|
|
98
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
99
|
+
designSystem.TextInput,
|
|
100
|
+
{
|
|
101
|
+
value: btn.url,
|
|
102
|
+
onChange: (e) => updateButton(btn.id, { url: e.target.value }),
|
|
103
|
+
disabled
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
!urlOk && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "danger600", style: { marginTop: 4 }, children: "Please enter a valid http/https URL" })
|
|
107
|
+
] }) }),
|
|
108
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { width: 90 }, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { name: `${name}.${btn.id}.row`, children: [
|
|
109
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: "Row" }),
|
|
110
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
111
|
+
designSystem.TextInput,
|
|
112
|
+
{
|
|
113
|
+
type: "number",
|
|
114
|
+
value: String(btn.row ?? 0),
|
|
115
|
+
onChange: (e) => updateButton(btn.id, { row: parseInt(e.target.value, 10) || 0 }),
|
|
116
|
+
disabled
|
|
117
|
+
}
|
|
118
|
+
)
|
|
119
|
+
] }) }),
|
|
120
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 1, paddingTop: 6, children: [
|
|
121
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tooltip, { label: "Move up", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
122
|
+
designSystem.IconButton,
|
|
123
|
+
{
|
|
124
|
+
onClick: () => move(idx, idx - 1),
|
|
125
|
+
label: "Move up",
|
|
126
|
+
variant: "ghost",
|
|
127
|
+
disabled: disabled || idx === 0,
|
|
128
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUp, {})
|
|
129
|
+
}
|
|
130
|
+
) }),
|
|
131
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tooltip, { label: "Move down", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
132
|
+
designSystem.IconButton,
|
|
133
|
+
{
|
|
134
|
+
onClick: () => move(idx, idx + 1),
|
|
135
|
+
label: "Move down",
|
|
136
|
+
variant: "ghost",
|
|
137
|
+
disabled: disabled || idx === buttons.length - 1,
|
|
138
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDown, {})
|
|
139
|
+
}
|
|
140
|
+
) }),
|
|
141
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tooltip, { label: "Delete button", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
142
|
+
designSystem.IconButton,
|
|
143
|
+
{
|
|
144
|
+
onClick: () => deleteButton(btn.id),
|
|
145
|
+
label: "Delete button",
|
|
146
|
+
variant: "ghost",
|
|
147
|
+
disabled,
|
|
148
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {})
|
|
149
|
+
}
|
|
150
|
+
) })
|
|
151
|
+
] })
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
btn.id
|
|
155
|
+
);
|
|
156
|
+
}),
|
|
157
|
+
buttons.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, style: { border: "1px dashed #dcdce4" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", textColor: "neutral600", children: "No buttons. Add one to create an inline keyboard." }) })
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 2, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}), onClick: addButton, disabled, variant: "secondary", children: "Add button" }) }),
|
|
160
|
+
buttons.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { paddingTop: 2, children: [
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { marginBottom: 8, display: "block" }, children: "Preview" }),
|
|
162
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", gap: 2, children: previewRows.map((row) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { gap: 1, wrap: "wrap", children: row.items.map((b) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "primary100", children: b.text || "(empty)" }, b.id)) }, row.row)) })
|
|
163
|
+
] }),
|
|
164
|
+
error && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Error, { children: error }),
|
|
165
|
+
hint && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, { children: hint })
|
|
166
|
+
] }) });
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
ButtonsBuilder.displayName = "ButtonsBuilder";
|
|
170
|
+
exports.default = ButtonsBuilder;
|