@consilioweb/payload-support 0.6.1 → 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.
- package/dist/views/BillingView/client.cjs +209 -0
- package/dist/views/BillingView/client.js +204 -0
- package/dist/views/BillingView/index.cjs +34 -0
- package/dist/views/BillingView/index.js +29 -0
- package/dist/views/ChatView/client.cjs +253 -0
- package/dist/views/ChatView/client.js +252 -0
- package/dist/views/ChatView/index.cjs +34 -0
- package/dist/views/ChatView/index.js +29 -0
- package/dist/views/CrmView/client.cjs +233 -0
- package/dist/views/CrmView/client.js +232 -0
- package/dist/views/CrmView/index.cjs +34 -0
- package/dist/views/CrmView/index.js +29 -0
- package/dist/views/EmailTrackingView/client.cjs +159 -0
- package/dist/views/EmailTrackingView/client.js +154 -0
- package/dist/views/EmailTrackingView/index.cjs +34 -0
- package/dist/views/EmailTrackingView/index.js +29 -0
- package/dist/views/ImportConversationView/client.cjs +205 -0
- package/dist/views/ImportConversationView/client.js +204 -0
- package/dist/views/ImportConversationView/index.cjs +34 -0
- package/dist/views/ImportConversationView/index.js +29 -0
- package/dist/views/LogsView/client.cjs +149 -0
- package/dist/views/LogsView/client.js +148 -0
- package/dist/views/LogsView/index.cjs +32 -0
- package/dist/views/LogsView/index.js +27 -0
- package/dist/views/NewTicketView/client.cjs +229 -0
- package/dist/views/NewTicketView/client.js +224 -0
- package/dist/views/NewTicketView/index.cjs +32 -0
- package/dist/views/NewTicketView/index.js +27 -0
- package/dist/views/PendingEmailsView/client.cjs +173 -0
- package/dist/views/PendingEmailsView/client.js +172 -0
- package/dist/views/PendingEmailsView/index.cjs +34 -0
- package/dist/views/PendingEmailsView/index.js +29 -0
- package/dist/views/SupportDashboardView/client.cjs +301 -0
- package/dist/views/SupportDashboardView/client.js +296 -0
- package/dist/views/SupportDashboardView/index.cjs +34 -0
- package/dist/views/SupportDashboardView/index.js +29 -0
- package/dist/views/TicketDetailView/client.cjs +850 -0
- package/dist/views/TicketDetailView/client.js +844 -0
- package/dist/views/TicketDetailView/index.cjs +34 -0
- package/dist/views/TicketDetailView/index.js +29 -0
- package/dist/views/TicketInboxView/client.cjs +299 -0
- package/dist/views/TicketInboxView/client.js +294 -0
- package/dist/views/TicketInboxView/index.cjs +32 -0
- package/dist/views/TicketInboxView/index.js +27 -0
- package/dist/{views.css → views/TicketingSettingsView/TicketingSettings.module.scss} +138 -66
- package/dist/views/TicketingSettingsView/client.cjs +733 -0
- package/dist/views/TicketingSettingsView/client.js +728 -0
- package/dist/views/TicketingSettingsView/index.cjs +34 -0
- package/dist/views/TicketingSettingsView/index.js +29 -0
- package/dist/views/TimeDashboardView/client.cjs +169 -0
- package/dist/views/TimeDashboardView/client.js +164 -0
- package/dist/views/TimeDashboardView/index.cjs +34 -0
- package/dist/views/TimeDashboardView/index.js +29 -0
- package/dist/views/shared/AdminViewHeader.cjs +68 -0
- package/dist/views/shared/AdminViewHeader.js +67 -0
- package/dist/views/shared/ErrorBoundary.cjs +55 -0
- package/dist/views/shared/ErrorBoundary.js +50 -0
- package/dist/views/shared/Skeleton.cjs +77 -0
- package/dist/views/shared/Skeleton.js +72 -0
- package/dist/views/shared/adminTokens.cjs +34 -0
- package/dist/views/shared/adminTokens.js +31 -0
- package/dist/views/shared/config.cjs +44 -0
- package/dist/views/shared/config.js +40 -0
- package/dist/views/shared/index.cjs +58 -0
- package/dist/views/shared/index.js +5 -0
- package/dist/views.cjs +77 -6175
- package/dist/views.d.cts +13 -30
- package/dist/views.d.ts +13 -30
- package/dist/views.js +13 -6165
- package/package.json +1 -1
|
@@ -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,172 @@
|
|
|
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 };
|
|
@@ -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;
|
|
@@ -0,0 +1,29 @@
|
|
|
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 };
|