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