@consilioweb/payload-support 0.6.0 → 0.6.2

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 (85) hide show
  1. package/dist/{styles/theme.css → components/TicketConversation.css} +13 -326
  2. package/dist/components/TicketConversation.js +3004 -0
  3. package/dist/index.cjs +11 -11
  4. package/dist/index.js +11 -11
  5. package/dist/views/BillingView/client.cjs +209 -0
  6. package/dist/views/BillingView/index.cjs +34 -0
  7. package/dist/views/ChatView/client.cjs +253 -0
  8. package/dist/views/ChatView/index.cjs +34 -0
  9. package/dist/views/CrmView/client.cjs +233 -0
  10. package/dist/views/CrmView/index.cjs +34 -0
  11. package/dist/views/EmailTrackingView/client.cjs +159 -0
  12. package/dist/views/EmailTrackingView/index.cjs +34 -0
  13. package/dist/views/ImportConversationView/client.cjs +205 -0
  14. package/dist/views/ImportConversationView/index.cjs +34 -0
  15. package/dist/views/LogsView/client.cjs +149 -0
  16. package/dist/views/LogsView/index.cjs +32 -0
  17. package/dist/views/NewTicketView/client.cjs +229 -0
  18. package/dist/views/NewTicketView/index.cjs +32 -0
  19. package/dist/views/PendingEmailsView/client.cjs +173 -0
  20. package/dist/views/PendingEmailsView/index.cjs +34 -0
  21. package/dist/views/SupportDashboardView/client.cjs +301 -0
  22. package/dist/views/SupportDashboardView/index.cjs +34 -0
  23. package/dist/views/TicketDetailView/client.cjs +850 -0
  24. package/dist/views/TicketDetailView/index.cjs +34 -0
  25. package/dist/views/TicketInboxView/client.cjs +299 -0
  26. package/dist/views/TicketInboxView/index.cjs +32 -0
  27. package/dist/views/TicketingSettingsView/client.cjs +733 -0
  28. package/dist/views/TicketingSettingsView/index.cjs +34 -0
  29. package/dist/views/TimeDashboardView/client.cjs +169 -0
  30. package/dist/views/TimeDashboardView/index.cjs +34 -0
  31. package/dist/views/shared/AdminViewHeader.cjs +68 -0
  32. package/dist/views/shared/ErrorBoundary.cjs +55 -0
  33. package/dist/views/shared/Skeleton.cjs +77 -0
  34. package/dist/views/shared/adminTokens.cjs +34 -0
  35. package/dist/views/shared/adminTokens.js +0 -1
  36. package/dist/{components/TicketConversation/config.js → views/shared/config.cjs} +5 -2
  37. package/dist/views/shared/config.js +0 -1
  38. package/dist/views/shared/index.cjs +58 -0
  39. package/dist/views/shared/index.js +0 -1
  40. package/dist/views.cjs +86 -0
  41. package/dist/views.d.cts +13 -0
  42. package/dist/views.d.ts +13 -0
  43. package/dist/views.js +13 -0
  44. package/package.json +14 -7
  45. package/src/plugin.ts +11 -11
  46. package/src/views.ts +17 -0
  47. package/dist/components/TicketConversation/components/AISummaryPanel.js +0 -76
  48. package/dist/components/TicketConversation/components/ActionPanels.js +0 -118
  49. package/dist/components/TicketConversation/components/ActivityLog.js +0 -23
  50. package/dist/components/TicketConversation/components/ClientBar.js +0 -42
  51. package/dist/components/TicketConversation/components/ClientHistory.js +0 -137
  52. package/dist/components/TicketConversation/components/CodeBlock.js +0 -152
  53. package/dist/components/TicketConversation/components/CodeBlockInserter.js +0 -155
  54. package/dist/components/TicketConversation/components/QuickActions.js +0 -65
  55. package/dist/components/TicketConversation/components/TicketHeader.js +0 -92
  56. package/dist/components/TicketConversation/components/TimeTrackingPanel.js +0 -133
  57. package/dist/components/TicketConversation/constants.js +0 -96
  58. package/dist/components/TicketConversation/context.js +0 -11
  59. package/dist/components/TicketConversation/hooks/useAI.js +0 -176
  60. package/dist/components/TicketConversation/hooks/useMessageActions.js +0 -135
  61. package/dist/components/TicketConversation/hooks/useReply.js +0 -187
  62. package/dist/components/TicketConversation/hooks/useTicketActions.js +0 -230
  63. package/dist/components/TicketConversation/hooks/useTimeTracking.js +0 -122
  64. package/dist/components/TicketConversation/hooks/useTranslation.js +0 -70
  65. package/dist/components/TicketConversation/index.js +0 -1123
  66. package/dist/components/TicketConversation/locales/en.json +0 -878
  67. package/dist/components/TicketConversation/locales/fr.json +0 -878
  68. package/dist/components/TicketConversation/types.js +0 -2
  69. package/dist/components/TicketConversation/utils.js +0 -25
  70. package/dist/styles/BillingView.module.scss +0 -311
  71. package/dist/styles/ChatView.module.scss +0 -438
  72. package/dist/styles/CommandPalette.module.scss +0 -160
  73. package/dist/styles/CrmView.module.scss +0 -554
  74. package/dist/styles/EmailTracking.module.scss +0 -238
  75. package/dist/styles/ImportConversation.module.scss +0 -267
  76. package/dist/styles/Layout.module.scss +0 -55
  77. package/dist/styles/Logs.module.scss +0 -164
  78. package/dist/styles/NewTicket.module.scss +0 -143
  79. package/dist/styles/PendingEmails.module.scss +0 -629
  80. package/dist/styles/SupportDashboard.module.scss +0 -649
  81. package/dist/styles/TicketDetail.module.scss +0 -1050
  82. package/dist/styles/TicketInbox.module.scss +0 -296
  83. package/dist/styles/TicketingSettings.module.scss +0 -358
  84. package/dist/styles/TimeDashboard.module.scss +0 -287
  85. package/dist/styles/_tokens.scss +0 -78
@@ -0,0 +1,229 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var Link = require('next/link');
6
+ var navigation = require('next/navigation');
7
+ var useTranslation = require('../../components/TicketConversation/hooks/useTranslation');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var Link__default = /*#__PURE__*/_interopDefault(Link);
12
+
13
+ const CATEGORY_KEYS = [
14
+ { value: "", key: "ticket.category.select" },
15
+ { value: "bug", key: "ticket.category.bugFull" },
16
+ { value: "content", key: "ticket.category.contentFull" },
17
+ { value: "feature", key: "ticket.category.featureFull" },
18
+ { value: "question", key: "ticket.category.questionFull" },
19
+ { value: "hosting", key: "ticket.category.hostingFull" }
20
+ ];
21
+ const PRIORITY_KEYS = [
22
+ { value: "low", key: "ticket.priority.low" },
23
+ { value: "normal", key: "ticket.priority.normal" },
24
+ { value: "high", key: "ticket.priority.high" },
25
+ { value: "urgent", key: "ticket.priority.urgent" }
26
+ ];
27
+ const NewTicketClient = () => {
28
+ const { t } = useTranslation.useTranslation();
29
+ const router = navigation.useRouter();
30
+ const [subject, setSubject] = react.useState("");
31
+ const [description, setDescription] = react.useState("");
32
+ const [category, setCategory] = react.useState("");
33
+ const [priority, setPriority] = react.useState("normal");
34
+ const [clientSearch, setClientSearch] = react.useState("");
35
+ const [clientId, setClientId] = react.useState(null);
36
+ const [clientResults, setClientResults] = react.useState([]);
37
+ const [selectedClient, setSelectedClient] = react.useState(null);
38
+ const [projectId, setProjectId] = react.useState(null);
39
+ const [projects, setProjects] = react.useState([]);
40
+ const [submitting, setSubmitting] = react.useState(false);
41
+ const [error, setError] = react.useState("");
42
+ react.useEffect(() => {
43
+ if (clientSearch.length < 2) {
44
+ setClientResults([]);
45
+ return;
46
+ }
47
+ const timer = setTimeout(async () => {
48
+ try {
49
+ const res = await fetch(`/api/support-clients?where[or][0][email][contains]=${encodeURIComponent(clientSearch)}&where[or][1][firstName][contains]=${encodeURIComponent(clientSearch)}&where[or][2][company][contains]=${encodeURIComponent(clientSearch)}&limit=8&depth=0`, { credentials: "include" });
50
+ if (res.ok) {
51
+ const d = await res.json();
52
+ setClientResults(d.docs || []);
53
+ }
54
+ } catch (err) {
55
+ console.warn("[support] client search error:", err);
56
+ }
57
+ }, 300);
58
+ return () => clearTimeout(timer);
59
+ }, [clientSearch]);
60
+ react.useEffect(() => {
61
+ fetch("/api/projects?where[status][equals]=active&limit=50&depth=0", { credentials: "include" }).then((r) => r.json()).then((d) => setProjects(d.docs || [])).catch(() => {
62
+ });
63
+ }, []);
64
+ const handleSubmit = async (e) => {
65
+ e.preventDefault();
66
+ setError("");
67
+ if (!subject.trim()) {
68
+ setError(t("newTicket.errors.subjectRequired"));
69
+ return;
70
+ }
71
+ if (!clientId) {
72
+ setError(t("newTicket.errors.clientRequired"));
73
+ return;
74
+ }
75
+ setSubmitting(true);
76
+ try {
77
+ const res = await fetch("/api/tickets", {
78
+ method: "POST",
79
+ headers: { "Content-Type": "application/json" },
80
+ credentials: "include",
81
+ body: JSON.stringify({
82
+ subject: subject.trim(),
83
+ client: clientId,
84
+ category: category || void 0,
85
+ priority,
86
+ project: projectId || void 0,
87
+ source: "admin",
88
+ status: "open"
89
+ })
90
+ });
91
+ if (!res.ok) {
92
+ const d = await res.json().catch(() => ({}));
93
+ setError(d.errors?.[0]?.message || t("newTicket.errors.creationError"));
94
+ return;
95
+ }
96
+ const ticket = await res.json();
97
+ if (description.trim()) {
98
+ await fetch("/api/ticket-messages", {
99
+ method: "POST",
100
+ headers: { "Content-Type": "application/json" },
101
+ credentials: "include",
102
+ body: JSON.stringify({
103
+ ticket: ticket.doc.id,
104
+ body: description.trim(),
105
+ authorType: "admin",
106
+ isInternal: false
107
+ })
108
+ });
109
+ }
110
+ router.push(`/admin/support/ticket?id=${ticket.doc.id}`);
111
+ } catch {
112
+ setError(t("newTicket.errors.networkError"));
113
+ } finally {
114
+ setSubmitting(false);
115
+ }
116
+ };
117
+ const S = {
118
+ page: { padding: "20px 30px", maxWidth: 720, margin: "0 auto" },
119
+ header: { marginBottom: 24 },
120
+ backLink: { fontSize: 13, color: "#2563eb", textDecoration: "none" },
121
+ title: { fontSize: 24, fontWeight: 700, margin: "8px 0 4px", color: "var(--theme-text)" },
122
+ subtitle: { fontSize: 14, color: "var(--theme-elevation-500)" },
123
+ error: { padding: "10px 14px", borderRadius: 8, background: "#fef2f2", color: "#dc2626", fontSize: 13, marginBottom: 16, border: "1px solid #fecaca" },
124
+ fieldGroup: { marginBottom: 16 },
125
+ label: { display: "block", fontSize: 13, fontWeight: 600, marginBottom: 6, color: "var(--theme-text)" },
126
+ required: { color: "#dc2626" },
127
+ input: { width: "100%", padding: "8px 12px", borderRadius: 8, border: "1px solid var(--theme-elevation-200)", fontSize: 13, color: "var(--theme-text)", background: "var(--theme-elevation-0)" },
128
+ select: { width: "100%", padding: "8px 12px", borderRadius: 8, border: "1px solid var(--theme-elevation-200)", fontSize: 13, color: "var(--theme-text)", background: "var(--theme-elevation-0)" },
129
+ textarea: { width: "100%", padding: "8px 12px", borderRadius: 8, border: "1px solid var(--theme-elevation-200)", fontSize: 13, color: "var(--theme-text)", background: "var(--theme-elevation-0)", minHeight: 120, fontFamily: "inherit", resize: "vertical" },
130
+ row3: { display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 12, marginBottom: 16 },
131
+ submitBtn: { padding: "10px 20px", borderRadius: 8, background: "#2563eb", color: "#fff", fontSize: 14, fontWeight: 600, border: "none", cursor: "pointer" },
132
+ searchResults: { position: "absolute", top: "100%", left: 0, right: 0, background: "var(--theme-elevation-0)", border: "1px solid var(--theme-elevation-200)", borderRadius: 8, boxShadow: "0 4px 12px rgba(0,0,0,0.1)", zIndex: 50, maxHeight: 200, overflowY: "auto" },
133
+ searchItem: { padding: "8px 12px", cursor: "pointer", fontSize: 13, borderBottom: "1px solid var(--theme-elevation-100)" }
134
+ };
135
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.page, children: [
136
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.header, children: [
137
+ /* @__PURE__ */ jsxRuntime.jsxs(Link__default.default, { href: "/admin/support/inbox", style: S.backLink, children: [
138
+ "\u2190 ",
139
+ t("newTicket.backToInbox")
140
+ ] }),
141
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { style: S.title, children: t("newTicket.title") }),
142
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: S.subtitle, children: t("newTicket.subtitle") })
143
+ ] }),
144
+ error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: S.error, children: error }),
145
+ /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: handleSubmit, children: [
146
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
147
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: S.label, children: [
148
+ t("newTicket.clientLabel"),
149
+ " ",
150
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: S.required, children: "*" })
151
+ ] }),
152
+ selectedClient ? /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 10, padding: "8px 14px", borderRadius: 10, border: "1px solid var(--theme-elevation-200)", background: "var(--theme-elevation-50)" }, children: [
153
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontWeight: 600, fontSize: 13, color: "var(--theme-text)" }, children: [
154
+ selectedClient.firstName,
155
+ " ",
156
+ selectedClient.lastName,
157
+ " -- ",
158
+ selectedClient.company
159
+ ] }),
160
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: 12, color: "var(--theme-elevation-500)" }, children: selectedClient.email }),
161
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => {
162
+ setSelectedClient(null);
163
+ setClientId(null);
164
+ setClientSearch("");
165
+ }, style: { marginLeft: "auto", background: "none", border: "none", cursor: "pointer", color: "var(--theme-elevation-400)", fontSize: 16 }, children: "\xD7" })
166
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, children: [
167
+ /* @__PURE__ */ jsxRuntime.jsx(
168
+ "input",
169
+ {
170
+ type: "text",
171
+ style: S.input,
172
+ placeholder: t("newTicket.clientSearchPlaceholder"),
173
+ value: clientSearch,
174
+ onChange: (e) => setClientSearch(e.target.value)
175
+ }
176
+ ),
177
+ clientResults.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { style: S.searchResults, children: clientResults.map((c) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.searchItem, onClick: () => {
178
+ setSelectedClient(c);
179
+ setClientId(c.id);
180
+ setClientSearch("");
181
+ setClientResults([]);
182
+ }, children: [
183
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { children: [
184
+ c.firstName,
185
+ " ",
186
+ c.lastName
187
+ ] }),
188
+ " -- ",
189
+ c.company,
190
+ " ",
191
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "var(--theme-elevation-400)", fontSize: 12 }, children: c.email })
192
+ ] }, c.id)) })
193
+ ] })
194
+ ] }),
195
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
196
+ /* @__PURE__ */ jsxRuntime.jsxs("label", { style: S.label, children: [
197
+ t("newTicket.subjectLabel"),
198
+ " ",
199
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: S.required, children: "*" })
200
+ ] }),
201
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "text", style: S.input, placeholder: t("newTicket.subjectPlaceholder"), value: subject, onChange: (e) => setSubject(e.target.value) })
202
+ ] }),
203
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.row3, children: [
204
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
205
+ /* @__PURE__ */ jsxRuntime.jsx("label", { style: S.label, children: t("newTicket.categoryLabel") }),
206
+ /* @__PURE__ */ jsxRuntime.jsx("select", { style: S.select, value: category, onChange: (e) => setCategory(e.target.value), children: CATEGORY_KEYS.map((c) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: c.value, children: t(c.key) }, c.value)) })
207
+ ] }),
208
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
209
+ /* @__PURE__ */ jsxRuntime.jsx("label", { style: S.label, children: t("newTicket.priorityLabel") }),
210
+ /* @__PURE__ */ jsxRuntime.jsx("select", { style: S.select, value: priority, onChange: (e) => setPriority(e.target.value), children: PRIORITY_KEYS.map((p) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: p.value, children: t(p.key) }, p.value)) })
211
+ ] }),
212
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
213
+ /* @__PURE__ */ jsxRuntime.jsx("label", { style: S.label, children: t("newTicket.projectLabel") }),
214
+ /* @__PURE__ */ jsxRuntime.jsxs("select", { style: S.select, value: projectId || "", onChange: (e) => setProjectId(e.target.value ? Number(e.target.value) : null), children: [
215
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: t("ticket.noProject") }),
216
+ projects.map((p) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: p.id, children: p.name }, p.id))
217
+ ] })
218
+ ] })
219
+ ] }),
220
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.fieldGroup, children: [
221
+ /* @__PURE__ */ jsxRuntime.jsx("label", { style: S.label, children: t("newTicket.descriptionLabel") }),
222
+ /* @__PURE__ */ jsxRuntime.jsx("textarea", { style: S.textarea, placeholder: t("newTicket.descriptionPlaceholder"), value: description, onChange: (e) => setDescription(e.target.value) })
223
+ ] }),
224
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", style: S.submitBtn, disabled: submitting, children: submitting ? t("newTicket.submitting") : t("newTicket.submitButton") })
225
+ ] })
226
+ ] });
227
+ };
228
+
229
+ exports.NewTicketClient = NewTicketClient;
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var templates = require('@payloadcms/next/templates');
7
+ var navigation = require('next/navigation');
8
+ var ErrorBoundary = require('../shared/ErrorBoundary');
9
+ var client = require('./client');
10
+
11
+ const NewTicketView = ({ initPageResult }) => {
12
+ const { req, visibleEntities } = initPageResult;
13
+ if (!req.user) navigation.redirect("/admin/login");
14
+ return /* @__PURE__ */ jsxRuntime.jsx(
15
+ templates.DefaultTemplate,
16
+ {
17
+ i18n: req.i18n,
18
+ locale: initPageResult.locale,
19
+ params: {},
20
+ payload: req.payload,
21
+ permissions: initPageResult.permissions,
22
+ searchParams: {},
23
+ user: req.user,
24
+ visibleEntities,
25
+ children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary.AdminErrorBoundary, { viewName: "NewTicketView", children: /* @__PURE__ */ jsxRuntime.jsx(client.NewTicketClient, {}) })
26
+ }
27
+ );
28
+ };
29
+ var NewTicketView_default = NewTicketView;
30
+
31
+ exports.NewTicketView = NewTicketView;
32
+ exports.default = NewTicketView_default;
@@ -0,0 +1,173 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var react = require('react');
5
+ var useTranslation = require('../../components/TicketConversation/hooks/useTranslation');
6
+
7
+ function timeAgo(dateStr) {
8
+ const diff = Date.now() - new Date(dateStr).getTime();
9
+ const mins = Math.floor(diff / 6e4);
10
+ if (mins < 1) return "a l'instant";
11
+ if (mins < 60) return `il y a ${mins}min`;
12
+ const hours = Math.floor(mins / 60);
13
+ if (hours < 24) return `il y a ${hours}h`;
14
+ return `il y a ${Math.floor(hours / 24)}j`;
15
+ }
16
+ function EmailCard({ email, onProcess, processing, t }) {
17
+ const [expanded, setExpanded] = react.useState(false);
18
+ const [showLinkModal, setShowLinkModal] = react.useState(false);
19
+ const [linkSearch, setLinkSearch] = react.useState("");
20
+ const [linkResults, setLinkResults] = react.useState([]);
21
+ const isPending = email.status === "pending";
22
+ const preview = email.body.slice(0, 200) + (email.body.length > 200 ? "..." : "");
23
+ const suggestions = email.suggestedTickets || [];
24
+ react.useEffect(() => {
25
+ if (!linkSearch || linkSearch.length < 2) {
26
+ setLinkResults([]);
27
+ return;
28
+ }
29
+ const timer = setTimeout(async () => {
30
+ try {
31
+ const res = await fetch(`/api/tickets?where[or][0][ticketNumber][contains]=${encodeURIComponent(linkSearch)}&where[or][1][subject][contains]=${encodeURIComponent(linkSearch)}&limit=10&sort=-updatedAt&depth=0`);
32
+ if (res.ok) {
33
+ const data = await res.json();
34
+ setLinkResults(data.docs.map((d) => ({ id: d.id, ticketNumber: d.ticketNumber, subject: d.subject })));
35
+ }
36
+ } catch (err) {
37
+ console.warn("[support] ticket search error:", err);
38
+ }
39
+ }, 300);
40
+ return () => clearTimeout(timer);
41
+ }, [linkSearch]);
42
+ const S = {
43
+ card: { padding: 16, borderRadius: 10, border: "1px solid var(--theme-elevation-150)", marginBottom: 12, opacity: processing ? 0.5 : 1 },
44
+ senderName: { fontWeight: 600, fontSize: 14 },
45
+ senderEmail: { fontSize: 12, color: "var(--theme-elevation-500)" },
46
+ subject: { fontWeight: 600, fontSize: 13, marginTop: 4 },
47
+ meta: { fontSize: 12, color: "var(--theme-elevation-400)", marginTop: 2 },
48
+ body: { fontSize: 13, color: "var(--theme-text)", padding: "8px 0", whiteSpace: "pre-wrap", lineHeight: 1.5 },
49
+ actions: { display: "flex", gap: 8, marginTop: 8 },
50
+ btn: { padding: "6px 14px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 12, fontWeight: 600, cursor: "pointer", background: "var(--theme-elevation-0)", color: "var(--theme-text)" },
51
+ btnCreate: { background: "#2563eb", color: "#fff", border: "none" },
52
+ btnIgnore: { color: "#dc2626", borderColor: "#dc2626" },
53
+ overlay: { position: "fixed", inset: 0, background: "rgba(0,0,0,0.5)", display: "flex", alignItems: "center", justifyContent: "center", zIndex: 100 },
54
+ modal: { background: "var(--theme-elevation-0)", borderRadius: 12, padding: 24, maxWidth: 480, width: "100%", maxHeight: "80vh", overflowY: "auto" }
55
+ };
56
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.card, children: [
57
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
58
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: S.senderName, children: email.senderName || email.senderEmail }),
59
+ email.senderName && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: S.senderEmail, children: [
60
+ " <",
61
+ email.senderEmail,
62
+ ">"
63
+ ] })
64
+ ] }),
65
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: S.subject, children: email.subject }),
66
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.meta, children: [
67
+ timeAgo(email.createdAt),
68
+ " ",
69
+ email.attachments?.length ? `-- ${email.attachments.length} PJ` : ""
70
+ ] }),
71
+ suggestions.length > 0 && isPending && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", gap: 6, marginTop: 6, flexWrap: "wrap" }, children: suggestions.map((s2) => /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { padding: "2px 8px", borderRadius: 4, fontSize: 11, background: s2.score >= 0.7 ? "#dcfce7" : "#fef3c7", color: s2.score >= 0.7 ? "#166534" : "#92400e" }, children: [
72
+ "Similaire a ",
73
+ s2.ticketNumber,
74
+ " (",
75
+ Math.round(s2.score * 100),
76
+ "%)"
77
+ ] }, s2.id)) }),
78
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: S.body, children: expanded ? email.body : preview }),
79
+ email.body.length > 200 && /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setExpanded(!expanded), style: { ...S.btn, fontSize: 11, padding: "2px 8px" }, children: expanded ? t("pendingEmails.collapse") : t("pendingEmails.expand") }),
80
+ isPending && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.actions, children: [
81
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => {
82
+ const clientId = typeof email.client === "object" && email.client ? email.client.id : void 0;
83
+ onProcess("create_ticket", void 0, clientId);
84
+ }, disabled: processing, style: { ...S.btn, ...S.btnCreate }, children: t("pendingEmails.actions.createTicket") }),
85
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setShowLinkModal(true), disabled: processing, style: S.btn, children: t("pendingEmails.actions.linkToTicket") }),
86
+ /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => onProcess("ignore"), disabled: processing, style: { ...S.btn, ...S.btnIgnore }, children: t("pendingEmails.actions.ignore") })
87
+ ] }),
88
+ showLinkModal && /* @__PURE__ */ jsxRuntime.jsx("div", { style: S.overlay, onClick: () => setShowLinkModal(false), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { style: S.modal, onClick: (e) => e.stopPropagation(), children: [
89
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { margin: "0 0 12px", fontSize: 16, fontWeight: 700 }, children: t("pendingEmails.linkModal.title") }),
90
+ suggestions.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { marginBottom: 12 }, children: [
91
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 12, fontWeight: 600, marginBottom: 4, color: "var(--theme-elevation-500)" }, children: t("pendingEmails.linkModal.suggestions") }),
92
+ suggestions.map((s2) => /* @__PURE__ */ jsxRuntime.jsxs("button", { onClick: () => {
93
+ setShowLinkModal(false);
94
+ onProcess("add_to_ticket", s2.id);
95
+ }, style: { display: "block", width: "100%", padding: "8px 12px", border: "1px solid var(--theme-elevation-200)", borderRadius: 6, background: "var(--theme-elevation-0)", cursor: "pointer", textAlign: "left", marginBottom: 4, fontSize: 13 }, children: [
96
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: s2.ticketNumber }),
97
+ " ",
98
+ s2.subject,
99
+ " ",
100
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontSize: 11, color: "#16a34a" }, children: [
101
+ Math.round(s2.score * 100),
102
+ "%"
103
+ ] })
104
+ ] }, s2.id))
105
+ ] }),
106
+ /* @__PURE__ */ jsxRuntime.jsx("input", { type: "text", placeholder: t("pendingEmails.linkModal.searchPlaceholder"), value: linkSearch, onChange: (e) => setLinkSearch(e.target.value), style: { width: "100%", padding: "8px 12px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 13, marginBottom: 8, color: "var(--theme-text)", background: "var(--theme-elevation-0)" } }),
107
+ linkResults.map((r) => /* @__PURE__ */ jsxRuntime.jsxs("button", { onClick: () => {
108
+ setShowLinkModal(false);
109
+ onProcess("add_to_ticket", r.id);
110
+ }, style: { display: "block", width: "100%", padding: "8px 12px", border: "1px solid var(--theme-elevation-200)", borderRadius: 6, background: "var(--theme-elevation-0)", cursor: "pointer", textAlign: "left", marginBottom: 4, fontSize: 13 }, children: [
111
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: r.ticketNumber }),
112
+ " ",
113
+ r.subject
114
+ ] }, r.id))
115
+ ] }) })
116
+ ] });
117
+ }
118
+ const PendingEmailsClient = () => {
119
+ const { t } = useTranslation.useTranslation();
120
+ const [emails, setEmails] = react.useState([]);
121
+ const [loading, setLoading] = react.useState(true);
122
+ const [tab, setTab] = react.useState("pending");
123
+ const [processing, setProcessing] = react.useState(null);
124
+ const fetchEmails = react.useCallback(async () => {
125
+ try {
126
+ const res = await fetch(`/api/pending-emails?where[status][equals]=${tab}&sort=-createdAt&limit=50&depth=1`);
127
+ if (res.ok) {
128
+ const data = await res.json();
129
+ setEmails(data.docs);
130
+ }
131
+ } catch {
132
+ }
133
+ setLoading(false);
134
+ }, [tab]);
135
+ react.useEffect(() => {
136
+ setLoading(true);
137
+ fetchEmails();
138
+ }, [fetchEmails]);
139
+ react.useEffect(() => {
140
+ if (tab !== "pending") return;
141
+ const iv = setInterval(fetchEmails, 3e4);
142
+ return () => clearInterval(iv);
143
+ }, [fetchEmails, tab]);
144
+ const handleProcess = async (emailId, action, ticketId, clientId) => {
145
+ setProcessing(emailId);
146
+ try {
147
+ const res = await fetch(`/api/support/pending-emails/${emailId}/process`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action, ticketId, clientId }) });
148
+ if (res.ok) {
149
+ setEmails((prev) => prev.filter((e) => e.id !== emailId));
150
+ } else {
151
+ const err = await res.json().catch(() => ({ error: "Unknown error" }));
152
+ alert(`Erreur : ${err.error || res.statusText}`);
153
+ }
154
+ } catch {
155
+ alert("Erreur reseau");
156
+ }
157
+ setProcessing(null);
158
+ };
159
+ const tabs = [{ key: "pending", label: t("pendingEmails.tabs.pending") }, { key: "processed", label: t("pendingEmails.tabs.processed") }, { key: "ignored", label: t("pendingEmails.tabs.ignored") }];
160
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { padding: "20px 30px", maxWidth: 900, margin: "0 auto" }, children: [
161
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 16 }, children: [
162
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
163
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { style: { fontSize: 22, fontWeight: 700, margin: 0, color: "var(--theme-text)" }, children: t("pendingEmails.title") }),
164
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { fontSize: 13, color: "var(--theme-elevation-500)", margin: "4px 0 0" }, children: t("pendingEmails.subtitle") })
165
+ ] }),
166
+ tab === "pending" && emails.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { padding: "4px 10px", borderRadius: 10, background: "#fef2f2", color: "#dc2626", fontSize: 12, fontWeight: 700 }, children: t("pendingEmails.pendingCount", { count: String(emails.length) }) })
167
+ ] }),
168
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", gap: 4, marginBottom: 16 }, children: tabs.map((tb) => /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setTab(tb.key), style: { padding: "6px 12px", borderRadius: 6, border: "none", background: tab === tb.key ? "var(--theme-elevation-100)" : "none", cursor: "pointer", fontSize: 13, fontWeight: tab === tb.key ? 700 : 500, color: tab === tb.key ? "var(--theme-text)" : "var(--theme-elevation-500)" }, children: tb.label }, tb.key)) }),
169
+ loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: 40, textAlign: "center", color: "#94a3b8" }, children: t("common.loading") }) : emails.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: 40, textAlign: "center", color: "#94a3b8" }, children: t(`pendingEmails.empty.${tab}`) }) : emails.map((email) => /* @__PURE__ */ jsxRuntime.jsx(EmailCard, { email, onProcess: (action, ticketId, clientId) => handleProcess(email.id, action, ticketId, clientId), processing: processing === email.id, t }, email.id))
170
+ ] });
171
+ };
172
+
173
+ exports.PendingEmailsClient = PendingEmailsClient;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var templates = require('@payloadcms/next/templates');
7
+ var navigation = require('next/navigation');
8
+ var ErrorBoundary = require('../shared/ErrorBoundary');
9
+ var client = require('./client');
10
+
11
+ const PendingEmailsView = ({ initPageResult }) => {
12
+ const { req, visibleEntities } = initPageResult;
13
+ if (!req.user) {
14
+ navigation.redirect("/admin/login");
15
+ }
16
+ return /* @__PURE__ */ jsxRuntime.jsx(
17
+ templates.DefaultTemplate,
18
+ {
19
+ i18n: req.i18n,
20
+ locale: initPageResult.locale,
21
+ params: {},
22
+ payload: req.payload,
23
+ permissions: initPageResult.permissions,
24
+ searchParams: {},
25
+ user: req.user,
26
+ visibleEntities,
27
+ children: /* @__PURE__ */ jsxRuntime.jsx(ErrorBoundary.AdminErrorBoundary, { viewName: "PendingEmailsView", children: /* @__PURE__ */ jsxRuntime.jsx(client.PendingEmailsClient, {}) })
28
+ }
29
+ );
30
+ };
31
+ var PendingEmailsView_default = PendingEmailsView;
32
+
33
+ exports.PendingEmailsView = PendingEmailsView;
34
+ exports.default = PendingEmailsView_default;