strapi-plugin-magic-link-v5 5.5.8 → 6.0.0

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 (58) hide show
  1. package/CHANGELOG.md +740 -0
  2. package/README.md +662 -928
  3. package/dist/admin/LicenseGuard-BgLA9go3.mjs +495 -0
  4. package/dist/admin/LicenseGuard-ewCjpc17.js +513 -0
  5. package/dist/admin/de-B1FNErPH.mjs +673 -0
  6. package/dist/admin/de-e75OECdq.js +673 -0
  7. package/dist/admin/en-CABKGbxH.js +673 -0
  8. package/dist/admin/en-HqDOFBCc.mjs +673 -0
  9. package/dist/admin/es-DpWl0Fax.js +673 -0
  10. package/dist/admin/es-jb94jqPR.mjs +673 -0
  11. package/dist/admin/fr-BQhLPvYw.js +673 -0
  12. package/dist/admin/fr-BseH1wrr.mjs +673 -0
  13. package/dist/admin/index-6ot9j1cN.js +5268 -0
  14. package/dist/admin/index-B390rccl.js +622 -0
  15. package/dist/admin/index-BPGKtruf.mjs +5266 -0
  16. package/dist/admin/index-BaTIQtnA.js +3869 -0
  17. package/dist/admin/index-CmG-93yx.js +141 -0
  18. package/dist/admin/index-DXe_ge4v.mjs +620 -0
  19. package/dist/admin/index-Dv5PVT1E.mjs +3867 -0
  20. package/dist/admin/index-k240ls6p.mjs +142 -0
  21. package/dist/admin/index.js +3 -3
  22. package/dist/admin/index.mjs +1 -2
  23. package/dist/admin/pt-CPkaveti.js +673 -0
  24. package/dist/admin/pt-DhlSCJn2.mjs +673 -0
  25. package/dist/admin/useUnsavedChangesGuard-BVZ4Mg4E.js +225 -0
  26. package/dist/admin/useUnsavedChangesGuard-QnkiZTLP.mjs +224 -0
  27. package/dist/server/i18n/de.json +32 -1
  28. package/dist/server/i18n/en.json +32 -1
  29. package/dist/server/i18n/es.json +32 -1
  30. package/dist/server/i18n/fr.json +32 -1
  31. package/dist/server/i18n/pt.json +32 -1
  32. package/dist/server/index.js +7092 -5979
  33. package/dist/server/index.mjs +7114 -5979
  34. package/package.json +42 -41
  35. package/strapi-admin.js +3 -1
  36. package/strapi-server.js +3 -2
  37. package/dist/_chunks/LicenseGuard-CiyjFnrw.js +0 -54
  38. package/dist/_chunks/LicenseGuard-DJ5fq2UZ.mjs +0 -55
  39. package/dist/_chunks/de-BSOk5suQ.js +0 -454
  40. package/dist/_chunks/de-CwhYs3O3.mjs +0 -454
  41. package/dist/_chunks/en-DnvSpXvu.js +0 -454
  42. package/dist/_chunks/en-gXXgGDV1.mjs +0 -454
  43. package/dist/_chunks/es-B-tnwByt.js +0 -407
  44. package/dist/_chunks/es-DG5gW3RZ.mjs +0 -407
  45. package/dist/_chunks/fr-BKo8t7Fx.js +0 -407
  46. package/dist/_chunks/fr-BQn1OHOR.mjs +0 -407
  47. package/dist/_chunks/index-01GHNxSr.js +0 -307
  48. package/dist/_chunks/index-B9Ch8Jpe.mjs +0 -5066
  49. package/dist/_chunks/index-Bj-erY7g.mjs +0 -143
  50. package/dist/_chunks/index-CGxbhJfg.js +0 -142
  51. package/dist/_chunks/index-DF3Edydl.mjs +0 -330
  52. package/dist/_chunks/index-Dufv-daf.mjs +0 -305
  53. package/dist/_chunks/index-I72rBTkL.js +0 -332
  54. package/dist/_chunks/index-SCxv154G.mjs +0 -2904
  55. package/dist/_chunks/index-XYWLmmEs.js +0 -5068
  56. package/dist/_chunks/index-zzoovbM0.js +0 -2906
  57. package/dist/_chunks/pt-CjEkXBAz.js +0 -407
  58. package/dist/_chunks/pt-trziAOzT.mjs +0 -407
@@ -1,305 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useState, useEffect } from "react";
3
- import { Loader, Box, Alert, Flex, Typography, Button, Badge, Accordion } from "@strapi/design-system";
4
- import { useFetchClient, useNotification } from "@strapi/strapi/admin";
5
- import { ArrowClockwise, Duplicate, Download, User, Shield, ChartBubble } from "@strapi/icons";
6
- import styled, { keyframes } from "styled-components";
7
- const theme = {
8
- colors: {
9
- neutral: { 200: "#E5E7EB" }
10
- },
11
- shadows: { sm: "0 1px 3px rgba(0,0,0,0.1)" },
12
- borderRadius: { lg: "12px" }
13
- };
14
- const fadeIn = keyframes`
15
- from { opacity: 0; transform: translateY(10px); }
16
- to { opacity: 1; transform: translateY(0); }
17
- `;
18
- const shimmer = keyframes`
19
- 0% { background-position: -200% 0; }
20
- 100% { background-position: 200% 0; }
21
- `;
22
- const Container = styled(Box)`
23
- animation: ${fadeIn} 0.5s;
24
- max-width: 1400px;
25
- margin: 0 auto;
26
- `;
27
- const StickySaveBar = styled(Box)`
28
- position: sticky;
29
- top: 0;
30
- z-index: 10;
31
- background: white;
32
- border-bottom: 1px solid ${theme.colors.neutral[200]};
33
- box-shadow: ${theme.shadows.sm};
34
- `;
35
- const LicenseKeyBanner = styled(Box)`
36
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
37
- border-radius: ${theme.borderRadius.lg};
38
- padding: 28px 32px;
39
- color: white;
40
- position: relative;
41
- overflow: hidden;
42
- box-shadow: 0 4px 20px rgba(102, 126, 234, 0.25);
43
- margin-bottom: 24px;
44
-
45
- &::after {
46
- content: '';
47
- position: absolute;
48
- top: -50%;
49
- right: -50%;
50
- width: 200%;
51
- height: 200%;
52
- background: linear-gradient(
53
- 45deg,
54
- transparent,
55
- rgba(255, 255, 255, 0.08),
56
- transparent
57
- );
58
- animation: ${shimmer} 3s infinite;
59
- pointer-events: none;
60
- z-index: 0;
61
- }
62
-
63
- & > * {
64
- position: relative;
65
- z-index: 1;
66
- }
67
- `;
68
- styled(Flex)`
69
- padding: 16px 0;
70
- border-bottom: 1px solid ${theme.colors.neutral[200]};
71
-
72
- &:last-child {
73
- border-bottom: none;
74
- }
75
- `;
76
- const LoaderContainer = styled(Flex)`
77
- min-height: 400px;
78
- align-items: center;
79
- justify-content: center;
80
- flex-direction: column;
81
- gap: 16px;
82
- `;
83
- const LicensePage = () => {
84
- const { get } = useFetchClient();
85
- const { toggleNotification } = useNotification();
86
- const [loading, setLoading] = useState(true);
87
- const [licenseData, setLicenseData] = useState(null);
88
- const [error, setError] = useState(null);
89
- const fetchLicenseStatus = async () => {
90
- setLoading(true);
91
- setError(null);
92
- try {
93
- const response = await get("/magic-link/license/status");
94
- setLicenseData(response.data);
95
- } catch (err) {
96
- console.error("Error fetching license:", err);
97
- setError("Failed to load license information");
98
- } finally {
99
- setLoading(false);
100
- }
101
- };
102
- const handleCopyLicenseKey = async () => {
103
- try {
104
- await navigator.clipboard.writeText(licenseData?.data?.licenseKey || "");
105
- toggleNotification({
106
- type: "success",
107
- message: "License key copied to clipboard!",
108
- title: "Copied"
109
- });
110
- } catch (err) {
111
- toggleNotification({
112
- type: "danger",
113
- message: "Failed to copy license key",
114
- title: "Error"
115
- });
116
- }
117
- };
118
- const handleDownloadLicenseKey = () => {
119
- try {
120
- const data2 = licenseData?.data || {};
121
- const licenseKey = data2.licenseKey || "";
122
- const email = data2.email || "N/A";
123
- const firstName = data2.firstName || "";
124
- const lastName = data2.lastName || "";
125
- const fullName = `${firstName} ${lastName}`.trim() || "N/A";
126
- const content = `Magic Link Plugin License Key
127
- ═══════════════════════════════════════
128
-
129
- License Key: ${licenseKey}
130
-
131
- License Holder Information:
132
- ──────────────────────────────────────
133
- Name: ${fullName}
134
- Email: ${email}
135
-
136
- License Status:
137
- ──────────────────────────────────────
138
- Status: ${data2.isActive ? "ACTIVE" : "INACTIVE"}
139
- Expires: ${data2.expiresAt ? new Date(data2.expiresAt).toLocaleDateString() : "Never"}
140
-
141
- ═══════════════════════════════════════
142
- Generated: ${(/* @__PURE__ */ new Date()).toLocaleString()}
143
- `;
144
- const blob = new Blob([content], { type: "text/plain" });
145
- const url = window.URL.createObjectURL(blob);
146
- const link = document.createElement("a");
147
- link.href = url;
148
- link.download = `magic-link-license-${licenseKey.substring(0, 8)}.txt`;
149
- document.body.appendChild(link);
150
- link.click();
151
- document.body.removeChild(link);
152
- window.URL.revokeObjectURL(url);
153
- toggleNotification({
154
- type: "success",
155
- message: "License key downloaded successfully!",
156
- title: "Downloaded"
157
- });
158
- } catch (err) {
159
- toggleNotification({
160
- type: "danger",
161
- message: "Failed to download license key",
162
- title: "Error"
163
- });
164
- }
165
- };
166
- useEffect(() => {
167
- fetchLicenseStatus();
168
- }, []);
169
- if (loading) {
170
- return /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(LoaderContainer, { children: /* @__PURE__ */ jsx(Loader, { children: "Loading license information..." }) }) });
171
- }
172
- if (error) {
173
- return /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Box, { padding: 8, children: /* @__PURE__ */ jsx(Alert, { variant: "danger", title: "Error", children: error }) }) });
174
- }
175
- const isValid = licenseData?.valid !== false;
176
- const hasKey = !!licenseData?.hasKey;
177
- const data = licenseData?.data || {};
178
- return /* @__PURE__ */ jsxs(Container, { children: [
179
- /* @__PURE__ */ jsx(StickySaveBar, { paddingTop: 5, paddingBottom: 5, paddingLeft: 6, paddingRight: 6, children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [
180
- /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 1, children: [
181
- /* @__PURE__ */ jsx(Typography, { variant: "alpha", fontWeight: "bold", children: "License Management" }),
182
- /* @__PURE__ */ jsx(Typography, { variant: "epsilon", textColor: "neutral600", children: "View your Magic Link plugin license" })
183
- ] }),
184
- /* @__PURE__ */ jsx(
185
- Button,
186
- {
187
- startIcon: /* @__PURE__ */ jsx(ArrowClockwise, {}),
188
- onClick: fetchLicenseStatus,
189
- size: "L",
190
- style: {
191
- background: "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
192
- color: "white",
193
- fontWeight: "600",
194
- border: "none"
195
- },
196
- children: "Refresh Status"
197
- }
198
- )
199
- ] }) }),
200
- /* @__PURE__ */ jsxs(Box, { paddingTop: 6, paddingLeft: 6, paddingRight: 6, paddingBottom: 10, children: [
201
- hasKey && isValid ? /* @__PURE__ */ jsx(Alert, { variant: "success", title: "License Active", children: "License key registered. Thanks for supporting the plugin!" }) : hasKey && !isValid ? /* @__PURE__ */ jsx(Alert, { variant: "warning", title: "License Verification", children: "We couldn't reach the license server right now. The plugin keeps working — try Refresh Status later." }) : /* @__PURE__ */ jsx(Alert, { variant: "default", title: "No license key registered", children: 'All Magic Link features are available without activation. If you want to register a license key, use the form below or run "Auto-Activate" to generate one for your admin email.' }),
202
- data.licenseKey && /* @__PURE__ */ jsx(Box, { marginTop: 6, children: /* @__PURE__ */ jsx(LicenseKeyBanner, { children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "flex-start", children: [
203
- /* @__PURE__ */ jsxs(Box, { style: { flex: 1 }, children: [
204
- /* @__PURE__ */ jsx(Typography, { variant: "pi", style: { color: "rgba(255,255,255,0.8)", marginBottom: "12px", textTransform: "uppercase", fontSize: "11px", letterSpacing: "0.5px", display: "block" }, children: "License Key" }),
205
- /* @__PURE__ */ jsx(Typography, { style: { color: "white", fontFamily: "monospace", fontSize: "28px", fontWeight: "bold", wordBreak: "break-all", marginBottom: "16px" }, children: data.licenseKey }),
206
- /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
207
- /* @__PURE__ */ jsx(
208
- Button,
209
- {
210
- onClick: handleCopyLicenseKey,
211
- startIcon: /* @__PURE__ */ jsx(Duplicate, {}),
212
- size: "S",
213
- variant: "secondary",
214
- style: {
215
- backgroundColor: "rgba(255,255,255,0.2)",
216
- color: "white",
217
- border: "1px solid rgba(255,255,255,0.3)",
218
- fontWeight: "600"
219
- },
220
- children: "Copy Key"
221
- }
222
- ),
223
- /* @__PURE__ */ jsx(
224
- Button,
225
- {
226
- onClick: handleDownloadLicenseKey,
227
- startIcon: /* @__PURE__ */ jsx(Download, {}),
228
- size: "S",
229
- variant: "secondary",
230
- style: {
231
- backgroundColor: "rgba(255,255,255,0.2)",
232
- color: "white",
233
- border: "1px solid rgba(255,255,255,0.3)",
234
- fontWeight: "600"
235
- },
236
- children: "Download as TXT"
237
- }
238
- )
239
- ] })
240
- ] }),
241
- /* @__PURE__ */ jsx(
242
- Badge,
243
- {
244
- backgroundColor: data.isActive ? "success100" : "danger100",
245
- textColor: data.isActive ? "success700" : "danger700",
246
- style: { fontSize: "11px", fontWeight: "700", padding: "6px 12px", marginLeft: "16px", flexShrink: 0 },
247
- children: data.isActive ? "ACTIVE" : "INACTIVE"
248
- }
249
- )
250
- ] }) }) }),
251
- /* @__PURE__ */ jsx(Box, { marginTop: 6, children: /* @__PURE__ */ jsxs(Accordion.Root, { defaultValue: ["account", "details", "features", "status"], children: [
252
- /* @__PURE__ */ jsxs(Accordion.Item, { value: "account", children: [
253
- /* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(Accordion.Trigger, { icon: User, children: "Account Information" }) }),
254
- /* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsx(Box, { padding: 6, children: /* @__PURE__ */ jsxs(Flex, { gap: 8, wrap: "wrap", children: [
255
- /* @__PURE__ */ jsxs(Box, { style: { flex: "1", minWidth: "200px" }, children: [
256
- /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: "Email Address" }),
257
- /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: data.email || "Not provided" })
258
- ] }),
259
- /* @__PURE__ */ jsxs(Box, { style: { flex: "1", minWidth: "200px" }, children: [
260
- /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: "License Holder" }),
261
- /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: data.firstName && data.lastName ? `${data.firstName} ${data.lastName}` : "Not specified" })
262
- ] })
263
- ] }) }) })
264
- ] }),
265
- /* @__PURE__ */ jsxs(Accordion.Item, { value: "details", children: [
266
- /* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(Accordion.Trigger, { icon: Shield, children: "License Details" }) }),
267
- /* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsx(Box, { padding: 6, children: /* @__PURE__ */ jsxs(Flex, { gap: 8, wrap: "wrap", children: [
268
- /* @__PURE__ */ jsxs(Box, { style: { flex: "1", minWidth: "180px" }, children: [
269
- /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: data.isExpired ? "Expired On" : "Expires On" }),
270
- /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: data.expiresAt ? new Date(data.expiresAt).toLocaleDateString("en-US", {
271
- year: "numeric",
272
- month: "long",
273
- day: "numeric"
274
- }) : "Never" })
275
- ] }),
276
- /* @__PURE__ */ jsxs(Box, { style: { flex: "1", minWidth: "180px" }, children: [
277
- /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: "Device Name" }),
278
- /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: data.deviceName || "Unknown" })
279
- ] }),
280
- /* @__PURE__ */ jsxs(Box, { style: { flex: "1", minWidth: "180px" }, children: [
281
- /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: "IP Address" }),
282
- /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: data.ipAddress || "Not detected" })
283
- ] })
284
- ] }) }) })
285
- ] }),
286
- /* @__PURE__ */ jsxs(Accordion.Item, { value: "status", children: [
287
- /* @__PURE__ */ jsx(Accordion.Header, { children: /* @__PURE__ */ jsx(Accordion.Trigger, { icon: ChartBubble, children: "System Status" }) }),
288
- /* @__PURE__ */ jsx(Accordion.Content, { children: /* @__PURE__ */ jsx(Box, { padding: 6, children: /* @__PURE__ */ jsxs(Flex, { gap: 8, wrap: "wrap", children: [
289
- /* @__PURE__ */ jsxs(Box, { style: { flex: "1", minWidth: "150px" }, children: [
290
- /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: "License Status" }),
291
- /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: hasKey ? data.isActive ? "Active" : "Inactive" : "No key registered" })
292
- ] }),
293
- /* @__PURE__ */ jsxs(Box, { style: { flex: "1", minWidth: "150px" }, children: [
294
- /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", textTransform: "uppercase", style: { marginBottom: "8px", display: "block" }, children: "Plugin Mode" }),
295
- /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", children: "Fully unlocked" })
296
- ] })
297
- ] }) }) })
298
- ] })
299
- ] }) })
300
- ] })
301
- ] });
302
- };
303
- export {
304
- LicensePage as default
305
- };
@@ -1,332 +0,0 @@
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 styled = require("styled-components");
6
- const reactIntl = require("react-intl");
7
- const designSystem = require("@strapi/design-system");
8
- const icons = require("@strapi/icons");
9
- const admin = require("@strapi/strapi/admin");
10
- const index = require("./index-CGxbhJfg.js");
11
- const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
12
- const styled__default = /* @__PURE__ */ _interopDefault(styled);
13
- const theme = {
14
- colors: {
15
- primary: { 700: "#075985", 100: "#E0F2FE", 50: "#F0F9FF" },
16
- success: { 600: "#16A34A", 700: "#15803D", 100: "#DCFCE7" },
17
- danger: { 700: "#B91C1C", 100: "#FEE2E2" },
18
- warning: { 700: "#A16207", 100: "#FEF3C7", 50: "#FFFBEB" },
19
- whatsapp: { 600: "#25D366" },
20
- neutral: { 50: "#F9FAFB", 100: "#F3F4F6", 200: "#E5E7EB", 800: "#1F2937" }
21
- },
22
- shadows: { md: "0 4px 6px rgba(0,0,0,0.1)" },
23
- borderRadius: { md: "8px", lg: "12px" }
24
- };
25
- const Container = styled__default.default(designSystem.Box)`
26
- max-width: 900px;
27
- margin: 0 auto;
28
- padding: 32px;
29
- `;
30
- const Card = styled__default.default(designSystem.Box)`
31
- background: white;
32
- border-radius: ${theme.borderRadius.lg};
33
- box-shadow: ${theme.shadows.md};
34
- padding: 24px;
35
- margin-bottom: 24px;
36
- `;
37
- const QRCodeContainer = styled__default.default(designSystem.Box)`
38
- display: flex;
39
- justify-content: center;
40
- align-items: center;
41
- padding: 24px;
42
- background: ${theme.colors.neutral[50]};
43
- border-radius: ${theme.borderRadius.lg};
44
- border: 2px dashed ${theme.colors.neutral[200]};
45
- min-height: 280px;
46
-
47
- img {
48
- max-width: 256px;
49
- border-radius: ${theme.borderRadius.md};
50
- }
51
- `;
52
- const StatusBadge = styled__default.default(designSystem.Badge)`
53
- background: ${(props) => {
54
- switch (props.$status) {
55
- case "connected":
56
- return theme.colors.success[100];
57
- case "connecting":
58
- return theme.colors.warning[100];
59
- case "qr_pending":
60
- return theme.colors.primary[100];
61
- default:
62
- return theme.colors.danger[100];
63
- }
64
- }};
65
- color: ${(props) => {
66
- switch (props.$status) {
67
- case "connected":
68
- return theme.colors.success[700];
69
- case "connecting":
70
- return theme.colors.warning[700];
71
- case "qr_pending":
72
- return theme.colors.primary[700];
73
- default:
74
- return theme.colors.danger[700];
75
- }
76
- }};
77
- font-weight: 600;
78
- padding: 8px 16px;
79
- font-size: 14px;
80
- `;
81
- const WhatsAppIcon = styled__default.default.div`
82
- width: 48px;
83
- height: 48px;
84
- border-radius: 50%;
85
- background: ${theme.colors.whatsapp[600]};
86
- display: flex;
87
- align-items: center;
88
- justify-content: center;
89
- color: white;
90
- font-size: 24px;
91
- `;
92
- const WhatsAppPage = () => {
93
- const { formatMessage } = reactIntl.useIntl();
94
- const { toggleNotification } = admin.useNotification();
95
- const { get, post } = admin.useFetchClient();
96
- const [loading, setLoading] = react.useState(true);
97
- const [status, setStatus] = react.useState({
98
- available: false,
99
- status: "disconnected",
100
- qrCode: null,
101
- session: null,
102
- delegatedTo: null
103
- });
104
- const [settings, setSettings] = react.useState({
105
- whatsapp_enabled: false,
106
- whatsapp_app_name: "Magic Link"
107
- });
108
- const [testPhone, setTestPhone] = react.useState("");
109
- const [testMessage, setTestMessage] = react.useState("");
110
- const [sending, setSending] = react.useState(false);
111
- const [connecting, setConnecting] = react.useState(false);
112
- const fetchStatus = react.useCallback(async () => {
113
- try {
114
- const response = await get("/magic-link/whatsapp/status");
115
- setStatus(response.data);
116
- } catch (error) {
117
- console.error("Error fetching WhatsApp status:", error);
118
- }
119
- }, [get]);
120
- const fetchSettings = react.useCallback(async () => {
121
- try {
122
- const response = await get("/magic-link/settings");
123
- setSettings(response.data || {});
124
- } catch (error) {
125
- console.error("Error fetching settings:", error);
126
- }
127
- }, [get]);
128
- react.useEffect(() => {
129
- const init = async () => {
130
- setLoading(true);
131
- await Promise.all([fetchStatus(), fetchSettings()]);
132
- setLoading(false);
133
- };
134
- init();
135
- }, [fetchStatus, fetchSettings]);
136
- react.useEffect(() => {
137
- if (status.status === "connecting" || status.status === "qr_pending") {
138
- const interval = setInterval(fetchStatus, 3e3);
139
- return () => clearInterval(interval);
140
- }
141
- }, [status.status, fetchStatus]);
142
- const handleConnect = async () => {
143
- setConnecting(true);
144
- try {
145
- await post("/magic-link/whatsapp/connect");
146
- await fetchStatus();
147
- toggleNotification({
148
- type: "success",
149
- message: formatMessage({ id: index.getTrad("whatsapp.notifications.connecting") })
150
- });
151
- } catch (error) {
152
- toggleNotification({
153
- type: "warning",
154
- message: error.response?.data?.error?.message || "Connection failed"
155
- });
156
- }
157
- setConnecting(false);
158
- };
159
- const handleDisconnect = async () => {
160
- try {
161
- await post("/magic-link/whatsapp/disconnect");
162
- await fetchStatus();
163
- toggleNotification({
164
- type: "success",
165
- message: formatMessage({ id: index.getTrad("whatsapp.notifications.disconnected") })
166
- });
167
- } catch (error) {
168
- toggleNotification({
169
- type: "warning",
170
- message: "Disconnect failed"
171
- });
172
- }
173
- };
174
- const handleTestMessage = async () => {
175
- if (!testPhone) {
176
- toggleNotification({
177
- type: "warning",
178
- message: formatMessage({ id: index.getTrad("whatsapp.notifications.phoneRequired") })
179
- });
180
- return;
181
- }
182
- setSending(true);
183
- try {
184
- const response = await post("/magic-link/whatsapp/test-message", {
185
- phoneNumber: testPhone,
186
- message: testMessage || void 0
187
- });
188
- if (response.data.success) {
189
- toggleNotification({
190
- type: "success",
191
- message: formatMessage({ id: index.getTrad("whatsapp.notifications.messageSent") })
192
- });
193
- setTestMessage("");
194
- } else {
195
- toggleNotification({
196
- type: "warning",
197
- message: response.data.error || "Failed to send"
198
- });
199
- }
200
- } catch (error) {
201
- toggleNotification({
202
- type: "warning",
203
- message: error.response?.data?.error?.message || "Failed to send message"
204
- });
205
- }
206
- setSending(false);
207
- };
208
- const getStatusLabel = () => {
209
- switch (status.status) {
210
- case "connected":
211
- return "Connected";
212
- case "connecting":
213
- return "Connecting...";
214
- case "qr_pending":
215
- return "Scan QR Code";
216
- case "not_installed":
217
- return "Baileys not installed";
218
- default:
219
- return "Disconnected";
220
- }
221
- };
222
- if (loading) {
223
- return /* @__PURE__ */ jsxRuntime.jsx(Container, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", padding: 8, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Loader, {}) }) });
224
- }
225
- return /* @__PURE__ */ jsxRuntime.jsxs(Container, { children: [
226
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { marginBottom: 6, children: [
227
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { justifyContent: "space-between", alignItems: "flex-start", marginBottom: 2, children: [
228
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "center", gap: 4, children: [
229
- /* @__PURE__ */ jsxRuntime.jsx(WhatsAppIcon, { children: /* @__PURE__ */ jsxRuntime.jsx(icons.Phone, {}) }),
230
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "alpha", fontWeight: "bold", children: formatMessage({ id: index.getTrad("whatsapp.title") }) })
231
- ] }),
232
- /* @__PURE__ */ jsxRuntime.jsx(StatusBadge, { $status: status.status, children: getStatusLabel() })
233
- ] }),
234
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "epsilon", textColor: "neutral600", style: { marginLeft: "64px" }, children: formatMessage({ id: index.getTrad("whatsapp.subtitle") }) })
235
- ] }),
236
- status.delegatedTo === "magic-mail" && /* @__PURE__ */ jsxRuntime.jsxs(Card, { style: { background: theme.colors.primary[50], border: `2px solid ${theme.colors.primary[100]}` }, children: [
237
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", style: { display: "block", marginBottom: "12px" }, children: "WhatsApp managed by Magic-Mail" }),
238
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { display: "block", lineHeight: "1.6", marginBottom: "16px" }, children: "Magic-Mail plugin is installed and handles the WhatsApp connection. You only need to scan the QR code once in Magic-Mail, and both plugins will share the same WhatsApp session." }),
239
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { padding: "12px", background: theme.colors.neutral[100], borderRadius: theme.borderRadius.md }, children: [
240
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", style: { display: "block", marginBottom: "8px" }, children: "Go to: Plugins → Magic-Mail → WhatsApp" }),
241
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: "All WhatsApp settings and connection management is done there." })
242
- ] })
243
- ] }),
244
- !status.available && !status.delegatedTo && /* @__PURE__ */ jsxRuntime.jsxs(Card, { style: { background: theme.colors.warning[50], border: `2px solid ${theme.colors.warning[100]}` }, children: [
245
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", style: { display: "block", marginBottom: "12px" }, children: formatMessage({ id: index.getTrad("whatsapp.notInstalled.title") }) }),
246
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { display: "block", lineHeight: "1.6", marginBottom: "16px" }, children: formatMessage({ id: index.getTrad("whatsapp.notInstalled.description") }) }),
247
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { padding: "12px", background: theme.colors.neutral[100], borderRadius: theme.borderRadius.md }, children: /* @__PURE__ */ jsxRuntime.jsx("code", { style: { fontSize: "14px" }, children: "npm install @whiskeysockets/baileys pino" }) })
248
- ] }),
249
- status.available && !status.delegatedTo && /* @__PURE__ */ jsxRuntime.jsxs(Card, { children: [
250
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", marginBottom: 4, children: formatMessage({ id: index.getTrad("whatsapp.connection.title") }) }),
251
- (status.status === "qr_pending" || status.status === "disconnected" || status.status === "connecting") && /* @__PURE__ */ jsxRuntime.jsx(QRCodeContainer, { children: status.qrCode ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { textAlign: "center", children: [
252
- /* @__PURE__ */ jsxRuntime.jsx("img", { src: status.qrCode, alt: "WhatsApp QR Code" }),
253
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { marginTop: "16px", display: "block" }, children: formatMessage({ id: index.getTrad("whatsapp.qr.instruction") }) })
254
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "center", gap: 4, children: [
255
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: status.status === "connecting" ? formatMessage({ id: index.getTrad("whatsapp.connection.generating") }) : formatMessage({ id: index.getTrad("whatsapp.connection.clickToConnect") }) }),
256
- status.status !== "connecting" && /* @__PURE__ */ jsxRuntime.jsx(
257
- designSystem.Button,
258
- {
259
- onClick: handleConnect,
260
- loading: connecting,
261
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Phone, {}),
262
- style: { background: theme.colors.whatsapp[600] },
263
- children: formatMessage({ id: index.getTrad("whatsapp.actions.connect") })
264
- }
265
- )
266
- ] }) }),
267
- status.status === "connected" && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
268
- /* @__PURE__ */ jsxRuntime.jsxs(
269
- designSystem.Flex,
270
- {
271
- alignItems: "flex-start",
272
- justifyContent: "space-between",
273
- padding: 4,
274
- background: "success100",
275
- style: { borderRadius: theme.borderRadius.md, marginBottom: "16px" },
276
- children: [
277
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { alignItems: "flex-start", gap: 3, children: [
278
- /* @__PURE__ */ jsxRuntime.jsx(icons.Check, { style: { color: theme.colors.success[600], marginTop: "4px" } }),
279
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
280
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", style: { display: "block", marginBottom: "8px" }, children: formatMessage({ id: index.getTrad("whatsapp.connected.title") }) }),
281
- status.session && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral600", style: { display: "block" }, children: [
282
- status.session.phoneNumber,
283
- " • ",
284
- status.session.name || "WhatsApp User"
285
- ] })
286
- ] })
287
- ] }),
288
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger", onClick: handleDisconnect, size: "S", children: formatMessage({ id: index.getTrad("whatsapp.actions.disconnect") }) })
289
- ]
290
- }
291
- ),
292
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { marginTop: "24px" }, children: [
293
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", style: { display: "block", marginBottom: "16px" }, children: formatMessage({ id: index.getTrad("whatsapp.test.title") }) }),
294
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "flex-start", children: [
295
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: 1 }, children: /* @__PURE__ */ jsxRuntime.jsx(
296
- designSystem.TextInput,
297
- {
298
- placeholder: "491234567890",
299
- value: testPhone,
300
- onChange: (e) => setTestPhone(e.target.value)
301
- }
302
- ) }),
303
- /* @__PURE__ */ jsxRuntime.jsx(
304
- designSystem.Button,
305
- {
306
- onClick: handleTestMessage,
307
- loading: sending,
308
- startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Message, {}),
309
- children: formatMessage({ id: index.getTrad("whatsapp.actions.sendTest") })
310
- }
311
- )
312
- ] })
313
- ] })
314
- ] }),
315
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", marginTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", onClick: fetchStatus, startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowClockwise, {}), children: formatMessage({ id: index.getTrad("whatsapp.actions.refresh") }) }) })
316
- ] }),
317
- !status.delegatedTo && /* @__PURE__ */ jsxRuntime.jsxs(Card, { style: { background: theme.colors.primary[50], border: `2px solid ${theme.colors.primary[100]}` }, children: [
318
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", fontWeight: "bold", style: { display: "block", marginBottom: "12px" }, children: formatMessage({ id: index.getTrad("whatsapp.info.title") }) }),
319
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral700", style: { display: "block", lineHeight: "1.6", marginBottom: "16px" }, children: formatMessage({ id: index.getTrad("whatsapp.info.description") }) }),
320
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { marginTop: "16px" }, children: [
321
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", style: { display: "block", marginBottom: "8px" }, children: formatMessage({ id: index.getTrad("whatsapp.info.apiExample") }) }),
322
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { padding: "12px", background: theme.colors.neutral[800], borderRadius: theme.borderRadius.md, color: "#fff", fontFamily: "monospace", fontSize: "13px" }, children: /* @__PURE__ */ jsxRuntime.jsx("pre", { style: { margin: 0, whiteSpace: "pre-wrap" }, children: `POST /api/magic-link/send-link
323
- {
324
- "email": "user@example.com",
325
- "phoneNumber": "491234567890",
326
- "delivery": "whatsapp"
327
- }` }) })
328
- ] })
329
- ] })
330
- ] });
331
- };
332
- exports.default = WhatsAppPage;