@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.
Files changed (84) 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.cjs +6184 -0
  6. package/dist/{views/TicketingSettingsView/TicketingSettings.module.scss → views.css} +66 -138
  7. package/dist/views.d.cts +30 -0
  8. package/dist/views.d.ts +30 -0
  9. package/dist/views.js +6165 -0
  10. package/package.json +14 -7
  11. package/src/plugin.ts +11 -11
  12. package/src/views.ts +17 -0
  13. package/dist/components/TicketConversation/components/AISummaryPanel.js +0 -76
  14. package/dist/components/TicketConversation/components/ActionPanels.js +0 -118
  15. package/dist/components/TicketConversation/components/ActivityLog.js +0 -23
  16. package/dist/components/TicketConversation/components/ClientBar.js +0 -42
  17. package/dist/components/TicketConversation/components/ClientHistory.js +0 -137
  18. package/dist/components/TicketConversation/components/CodeBlock.js +0 -152
  19. package/dist/components/TicketConversation/components/CodeBlockInserter.js +0 -155
  20. package/dist/components/TicketConversation/components/QuickActions.js +0 -65
  21. package/dist/components/TicketConversation/components/TicketHeader.js +0 -92
  22. package/dist/components/TicketConversation/components/TimeTrackingPanel.js +0 -133
  23. package/dist/components/TicketConversation/config.js +0 -41
  24. package/dist/components/TicketConversation/constants.js +0 -96
  25. package/dist/components/TicketConversation/context.js +0 -11
  26. package/dist/components/TicketConversation/hooks/useAI.js +0 -176
  27. package/dist/components/TicketConversation/hooks/useMessageActions.js +0 -135
  28. package/dist/components/TicketConversation/hooks/useReply.js +0 -187
  29. package/dist/components/TicketConversation/hooks/useTicketActions.js +0 -230
  30. package/dist/components/TicketConversation/hooks/useTimeTracking.js +0 -122
  31. package/dist/components/TicketConversation/hooks/useTranslation.js +0 -70
  32. package/dist/components/TicketConversation/index.js +0 -1123
  33. package/dist/components/TicketConversation/locales/en.json +0 -878
  34. package/dist/components/TicketConversation/locales/fr.json +0 -878
  35. package/dist/components/TicketConversation/types.js +0 -2
  36. package/dist/components/TicketConversation/utils.js +0 -25
  37. package/dist/styles/BillingView.module.scss +0 -311
  38. package/dist/styles/ChatView.module.scss +0 -438
  39. package/dist/styles/CommandPalette.module.scss +0 -160
  40. package/dist/styles/CrmView.module.scss +0 -554
  41. package/dist/styles/EmailTracking.module.scss +0 -238
  42. package/dist/styles/ImportConversation.module.scss +0 -267
  43. package/dist/styles/Layout.module.scss +0 -55
  44. package/dist/styles/Logs.module.scss +0 -164
  45. package/dist/styles/NewTicket.module.scss +0 -143
  46. package/dist/styles/PendingEmails.module.scss +0 -629
  47. package/dist/styles/SupportDashboard.module.scss +0 -649
  48. package/dist/styles/TicketDetail.module.scss +0 -1050
  49. package/dist/styles/TicketInbox.module.scss +0 -296
  50. package/dist/styles/TicketingSettings.module.scss +0 -358
  51. package/dist/styles/TimeDashboard.module.scss +0 -287
  52. package/dist/styles/_tokens.scss +0 -78
  53. package/dist/views/BillingView/client.js +0 -204
  54. package/dist/views/BillingView/index.js +0 -29
  55. package/dist/views/ChatView/client.js +0 -252
  56. package/dist/views/ChatView/index.js +0 -29
  57. package/dist/views/CrmView/client.js +0 -232
  58. package/dist/views/CrmView/index.js +0 -29
  59. package/dist/views/EmailTrackingView/client.js +0 -154
  60. package/dist/views/EmailTrackingView/index.js +0 -29
  61. package/dist/views/ImportConversationView/client.js +0 -204
  62. package/dist/views/ImportConversationView/index.js +0 -29
  63. package/dist/views/LogsView/client.js +0 -148
  64. package/dist/views/LogsView/index.js +0 -27
  65. package/dist/views/NewTicketView/client.js +0 -224
  66. package/dist/views/NewTicketView/index.js +0 -27
  67. package/dist/views/PendingEmailsView/client.js +0 -172
  68. package/dist/views/PendingEmailsView/index.js +0 -29
  69. package/dist/views/SupportDashboardView/client.js +0 -296
  70. package/dist/views/SupportDashboardView/index.js +0 -29
  71. package/dist/views/TicketDetailView/client.js +0 -844
  72. package/dist/views/TicketDetailView/index.js +0 -29
  73. package/dist/views/TicketInboxView/client.js +0 -294
  74. package/dist/views/TicketInboxView/index.js +0 -27
  75. package/dist/views/TicketingSettingsView/client.js +0 -728
  76. package/dist/views/TicketingSettingsView/index.js +0 -29
  77. package/dist/views/TimeDashboardView/client.js +0 -164
  78. package/dist/views/TimeDashboardView/index.js +0 -29
  79. package/dist/views/shared/AdminViewHeader.js +0 -67
  80. package/dist/views/shared/ErrorBoundary.js +0 -50
  81. package/dist/views/shared/Skeleton.js +0 -72
  82. package/dist/views/shared/adminTokens.js +0 -32
  83. package/dist/views/shared/config.js +0 -41
  84. package/dist/views/shared/index.js +0 -6
@@ -1,252 +0,0 @@
1
- "use client";
2
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
- import { useState, useRef, useCallback, useEffect } from 'react';
4
- import { useTranslation } from '../../components/TicketConversation/hooks/useTranslation';
5
-
6
- const ChatViewClient = () => {
7
- const { t } = useTranslation();
8
- const [sessions, setSessions] = useState({ active: [], closed: [] });
9
- const [selectedSession, setSelectedSession] = useState(null);
10
- const [messages, setMessages] = useState([]);
11
- const [input, setInput] = useState("");
12
- const [sending, setSending] = useState(false);
13
- const [showClosed, setShowClosed] = useState(false);
14
- const [loading, setLoading] = useState(true);
15
- const [cannedResponses, setCannedResponses] = useState([]);
16
- const messagesEndRef = useRef(null);
17
- const lastFetchRef = useRef(null);
18
- const [sessionExpired, setSessionExpired] = useState(false);
19
- const sessionsESRef = useRef(null);
20
- const messagesESRef = useRef(null);
21
- const fetchSessions = useCallback(async () => {
22
- try {
23
- const res = await fetch("/api/support/admin-chat");
24
- if (res.status === 401 || res.status === 403) {
25
- setSessionExpired(true);
26
- return;
27
- }
28
- if (res.ok) {
29
- const data = await res.json();
30
- setSessions({ active: data.active || [], closed: data.closed || [] });
31
- }
32
- } catch {
33
- }
34
- setLoading(false);
35
- }, []);
36
- useEffect(() => {
37
- if (sessionExpired) return;
38
- fetchSessions();
39
- if (typeof EventSource !== "undefined") {
40
- const es = new EventSource("/api/support/admin-chat-stream");
41
- sessionsESRef.current = es;
42
- es.onmessage = (event) => {
43
- try {
44
- const parsed = JSON.parse(event.data);
45
- if (parsed.type === "sessions" && parsed.data) {
46
- setSessions({ active: parsed.data.active || [], closed: parsed.data.closed || [] });
47
- setLoading(false);
48
- }
49
- } catch {
50
- }
51
- };
52
- es.onerror = () => {
53
- es.close();
54
- sessionsESRef.current = null;
55
- const iv2 = setInterval(fetchSessions, 5e3);
56
- return () => clearInterval(iv2);
57
- };
58
- return () => {
59
- es.close();
60
- sessionsESRef.current = null;
61
- };
62
- }
63
- const iv = setInterval(fetchSessions, 5e3);
64
- return () => clearInterval(iv);
65
- }, [fetchSessions, sessionExpired]);
66
- useEffect(() => {
67
- fetch("/api/canned-responses?sort=sortOrder&limit=50&depth=0", { credentials: "include" }).then((res) => res.ok ? res.json() : null).then((data) => {
68
- if (data?.docs) setCannedResponses(data.docs);
69
- }).catch(() => {
70
- });
71
- }, []);
72
- useEffect(() => {
73
- if (!selectedSession) return;
74
- const fetchMessages = async () => {
75
- try {
76
- const after = lastFetchRef.current || "";
77
- const url = `/api/support/admin-chat?session=${selectedSession}${after ? `&after=${after}` : ""}`;
78
- const res = await fetch(url);
79
- if (res.ok) {
80
- const data = await res.json();
81
- if (!lastFetchRef.current) {
82
- setMessages(data.messages || []);
83
- } else if (data.messages?.length > 0) {
84
- setMessages((prev) => {
85
- const ids = new Set(prev.map((m) => m.id));
86
- const newMsgs = data.messages.filter((m) => !ids.has(m.id));
87
- return newMsgs.length > 0 ? [...prev, ...newMsgs] : prev;
88
- });
89
- }
90
- if (data.messages?.length > 0) {
91
- lastFetchRef.current = data.messages[data.messages.length - 1].createdAt;
92
- }
93
- }
94
- } catch {
95
- }
96
- };
97
- lastFetchRef.current = null;
98
- fetchMessages();
99
- if (typeof EventSource !== "undefined") {
100
- const es = new EventSource(`/api/support/admin-chat-stream?session=${selectedSession}`);
101
- messagesESRef.current = es;
102
- es.onmessage = (event) => {
103
- try {
104
- const parsed = JSON.parse(event.data);
105
- if (parsed.type === "messages" && parsed.data?.length > 0) {
106
- setMessages((prev) => {
107
- const ids = new Set(prev.map((m) => m.id));
108
- const newMsgs = parsed.data.filter((m) => !ids.has(m.id));
109
- return newMsgs.length > 0 ? [...prev, ...newMsgs] : prev;
110
- });
111
- }
112
- } catch {
113
- }
114
- };
115
- es.onerror = () => {
116
- es.close();
117
- messagesESRef.current = null;
118
- const iv2 = setInterval(fetchMessages, 3e3);
119
- fetchMessages._fallbackIv = iv2;
120
- };
121
- return () => {
122
- es.close();
123
- messagesESRef.current = null;
124
- if (fetchMessages._fallbackIv) clearInterval(fetchMessages._fallbackIv);
125
- };
126
- }
127
- const iv = setInterval(fetchMessages, 3e3);
128
- return () => clearInterval(iv);
129
- }, [selectedSession]);
130
- useEffect(() => {
131
- messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
132
- }, [messages]);
133
- const sendMessage = async (e) => {
134
- e.preventDefault();
135
- if (!input.trim() || !selectedSession || sending) return;
136
- setSending(true);
137
- try {
138
- const res = await fetch("/api/support/admin-chat", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "send", session: selectedSession, message: input.trim() }) });
139
- if (res.ok) {
140
- const data = await res.json();
141
- setMessages((prev) => [...prev, data.message]);
142
- lastFetchRef.current = data.message.createdAt;
143
- setInput("");
144
- }
145
- } catch {
146
- }
147
- setSending(false);
148
- };
149
- const closeSession = async () => {
150
- if (!selectedSession) return;
151
- try {
152
- await fetch("/api/support/admin-chat", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "close", session: selectedSession }) });
153
- setSelectedSession(null);
154
- fetchSessions();
155
- } catch {
156
- }
157
- };
158
- const getClientName = (client) => {
159
- if (typeof client === "number") return `Client #${client}`;
160
- const parts = [client.firstName, client.lastName].filter(Boolean);
161
- if (parts.length > 0) return parts.join(" ");
162
- return client.email || `Client #${client.id}`;
163
- };
164
- const displayedSessions = showClosed ? sessions.closed : sessions.active;
165
- const S = {
166
- page: { padding: "20px 30px", maxWidth: 1200, margin: "0 auto" },
167
- container: { display: "grid", gridTemplateColumns: "320px 1fr", gap: 16, minHeight: "calc(100vh - 300px)" },
168
- sidebar: { borderRight: "1px solid var(--theme-elevation-200)" },
169
- sessionItem: { display: "block", width: "100%", padding: "10px 14px", border: "none", background: "none", cursor: "pointer", textAlign: "left", borderBottom: "1px solid var(--theme-elevation-100)", fontSize: 13 },
170
- sessionActive: { background: "var(--theme-elevation-50)" },
171
- chatPanel: { display: "flex", flexDirection: "column" },
172
- messagesArea: { flex: 1, overflowY: "auto", padding: "12px 0" },
173
- bubble: { maxWidth: "70%", padding: "8px 12px", borderRadius: 10, marginBottom: 8, fontSize: 14 },
174
- bubbleAgent: { background: "#dbeafe", color: "#1e3a5f", marginLeft: "auto" },
175
- bubbleClient: { background: "var(--theme-elevation-100)", color: "var(--theme-text)" },
176
- bubbleSystem: { margin: "4px auto", padding: "4px 12px", fontSize: 11, color: "#6b7280", textAlign: "center" },
177
- composer: { borderTop: "1px solid var(--theme-elevation-200)", padding: "8px 0" },
178
- composerInput: { flex: 1, padding: "8px 12px", borderRadius: 8, border: "1px solid var(--theme-elevation-200)", fontSize: 13, background: "var(--theme-elevation-0)", color: "var(--theme-text)" },
179
- sendBtn: { padding: "8px 16px", borderRadius: 8, background: "#2563eb", color: "#fff", border: "none", fontWeight: 600, cursor: "pointer", fontSize: 13 },
180
- tabsRow: { display: "flex", gap: 4, padding: "8px 14px", borderBottom: "1px solid var(--theme-elevation-200)" },
181
- tab: { padding: "4px 10px", borderRadius: 6, border: "none", background: "none", cursor: "pointer", fontSize: 12, color: "var(--theme-elevation-500)" },
182
- tabActive: { background: "var(--theme-elevation-100)", fontWeight: 700, color: "var(--theme-text)" }
183
- };
184
- return /* @__PURE__ */ jsxs("div", { style: S.page, children: [
185
- /* @__PURE__ */ jsxs("div", { style: { marginBottom: 16 }, children: [
186
- /* @__PURE__ */ jsx("h1", { style: { fontSize: 22, fontWeight: 700, margin: 0, color: "var(--theme-text)" }, children: t("chat.title") }),
187
- /* @__PURE__ */ jsx("p", { style: { color: "var(--theme-elevation-500)", fontSize: 13, margin: "4px 0 0" }, children: sessions.active.length !== 1 ? t("chat.sessionCountPlural", { count: String(sessions.active.length) }) : t("chat.sessionCount", { count: String(sessions.active.length) }) })
188
- ] }),
189
- /* @__PURE__ */ jsxs("div", { style: S.container, children: [
190
- /* @__PURE__ */ jsxs("div", { style: S.sidebar, children: [
191
- /* @__PURE__ */ jsxs("div", { style: S.tabsRow, children: [
192
- /* @__PURE__ */ jsxs("button", { onClick: () => setShowClosed(false), style: { ...S.tab, ...!showClosed ? S.tabActive : {} }, children: [
193
- t("chat.tabs.active"),
194
- " (",
195
- sessions.active.length,
196
- ")"
197
- ] }),
198
- /* @__PURE__ */ jsxs("button", { onClick: () => setShowClosed(true), style: { ...S.tab, ...showClosed ? S.tabActive : {} }, children: [
199
- t("chat.tabs.closed"),
200
- " (",
201
- sessions.closed.length,
202
- ")"
203
- ] })
204
- ] }),
205
- /* @__PURE__ */ jsx("div", { children: loading ? /* @__PURE__ */ jsx("div", { style: { padding: 20, textAlign: "center", color: "#94a3b8" }, children: t("common.loading") }) : displayedSessions.length === 0 ? /* @__PURE__ */ jsx("div", { style: { padding: 20, textAlign: "center", color: "#94a3b8" }, children: showClosed ? t("chat.noSessionClosed") : t("chat.noSessionActive") }) : displayedSessions.map((s2) => /* @__PURE__ */ jsxs("button", { onClick: () => setSelectedSession(s2.session), style: { ...S.sessionItem, ...selectedSession === s2.session ? S.sessionActive : {} }, children: [
206
- /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between" }, children: [
207
- /* @__PURE__ */ jsx("span", { style: { fontWeight: 600 }, children: getClientName(s2.client) }),
208
- s2.unreadCount > 0 && /* @__PURE__ */ jsx("span", { style: { padding: "1px 6px", borderRadius: 10, background: "#dc2626", color: "#fff", fontSize: 10, fontWeight: 700 }, children: s2.unreadCount })
209
- ] }),
210
- /* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "var(--theme-elevation-500)", marginTop: 2, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: s2.lastMessage }),
211
- /* @__PURE__ */ jsxs("div", { style: { fontSize: 11, color: "var(--theme-elevation-400)", marginTop: 2 }, children: [
212
- new Date(s2.lastMessageAt).toLocaleString("fr-FR", { day: "2-digit", month: "2-digit", hour: "2-digit", minute: "2-digit" }),
213
- " -- ",
214
- s2.messageCount,
215
- " ",
216
- t("chat.msg")
217
- ] })
218
- ] }, s2.session)) })
219
- ] }),
220
- /* @__PURE__ */ jsx("div", { style: S.chatPanel, children: !selectedSession ? /* @__PURE__ */ jsx("div", { style: { flex: 1, display: "flex", alignItems: "center", justifyContent: "center", color: "#94a3b8", fontSize: 14 }, children: t("chat.selectSession") }) : /* @__PURE__ */ jsxs(Fragment, { children: [
221
- /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", padding: "8px 14px", borderBottom: "1px solid var(--theme-elevation-200)" }, children: [
222
- /* @__PURE__ */ jsx("span", { style: { fontFamily: "monospace", fontSize: 12, color: "var(--theme-elevation-500)" }, children: selectedSession }),
223
- /* @__PURE__ */ jsx("button", { onClick: closeSession, style: { padding: "4px 12px", borderRadius: 6, border: "1px solid #dc2626", background: "none", color: "#dc2626", fontSize: 12, cursor: "pointer" }, children: t("chat.closeChat") })
224
- ] }),
225
- /* @__PURE__ */ jsxs("div", { style: S.messagesArea, children: [
226
- messages.map((msg) => /* @__PURE__ */ jsx("div", { style: { display: "flex", flexDirection: msg.senderType === "agent" ? "row-reverse" : "row", padding: "2px 14px" }, children: msg.senderType === "system" ? /* @__PURE__ */ jsx("div", { style: S.bubbleSystem, children: msg.message }) : /* @__PURE__ */ jsxs("div", { style: { ...S.bubble, ...msg.senderType === "agent" ? S.bubbleAgent : S.bubbleClient }, children: [
227
- /* @__PURE__ */ jsx("div", { style: { fontSize: 11, fontWeight: 600, marginBottom: 2 }, children: msg.senderType === "agent" ? t("chat.you") : t("chat.clientLabel") }),
228
- /* @__PURE__ */ jsx("div", { children: msg.message }),
229
- /* @__PURE__ */ jsx("div", { style: { fontSize: 10, color: msg.senderType === "agent" ? "#1e40af" : "var(--theme-elevation-400)", marginTop: 2 }, children: new Date(msg.createdAt).toLocaleTimeString("fr-FR", { hour: "2-digit", minute: "2-digit" }) })
230
- ] }) }, msg.id)),
231
- /* @__PURE__ */ jsx("div", { ref: messagesEndRef })
232
- ] }),
233
- /* @__PURE__ */ jsxs("form", { onSubmit: sendMessage, style: S.composer, children: [
234
- cannedResponses.length > 0 && /* @__PURE__ */ jsxs("select", { onChange: (e) => {
235
- const cr = cannedResponses.find((c) => String(c.id) === e.target.value);
236
- if (cr) setInput(cr.body);
237
- e.target.value = "";
238
- }, style: { padding: "4px 8px", borderRadius: 6, border: "1px solid var(--theme-elevation-200)", fontSize: 11, marginBottom: 6, color: "var(--theme-text)", background: "var(--theme-elevation-0)" }, children: [
239
- /* @__PURE__ */ jsx("option", { value: "", children: t("chat.quickReply") }),
240
- cannedResponses.map((cr) => /* @__PURE__ */ jsx("option", { value: String(cr.id), children: cr.title }, cr.id))
241
- ] }),
242
- /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8 }, children: [
243
- /* @__PURE__ */ jsx("input", { type: "text", value: input, onChange: (e) => setInput(e.target.value), placeholder: t("chat.inputPlaceholder"), maxLength: 2e3, style: S.composerInput, autoFocus: true }),
244
- /* @__PURE__ */ jsx("button", { type: "submit", disabled: !input.trim() || sending, style: S.sendBtn, children: t("chat.sendButton") })
245
- ] })
246
- ] })
247
- ] }) })
248
- ] })
249
- ] });
250
- };
251
-
252
- export { ChatViewClient };
@@ -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 { ChatViewClient } from './client';
6
-
7
- const ChatView = ({ 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: "ChatView", children: /* @__PURE__ */ jsx(ChatViewClient, {}) })
24
- }
25
- );
26
- };
27
- var ChatView_default = ChatView;
28
-
29
- export { ChatView, ChatView_default as default };
@@ -1,232 +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
- const statusLabelKeys = { open: "ticket.status.open", waiting_client: "ticket.status.waiting_client", resolved: "ticket.status.resolved" };
7
- const statusColors = { open: "#3b82f6", waiting_client: "#f59e0b", resolved: "#22c55e" };
8
- function formatDuration(minutes) {
9
- const h = Math.floor(minutes / 60);
10
- const m = minutes % 60;
11
- if (h === 0) return `${m}min`;
12
- if (m === 0) return `${h}h`;
13
- return `${h}h${m}m`;
14
- }
15
- function timeAgo(dateStr) {
16
- const diff = Date.now() - new Date(dateStr).getTime();
17
- const days = Math.floor(diff / 864e5);
18
- if (days === 0) return "Aujourd'hui";
19
- if (days === 1) return "Hier";
20
- if (days < 30) return `Il y a ${days}j`;
21
- return `Il y a ${Math.floor(days / 30)} mois`;
22
- }
23
- const CrmClient = () => {
24
- const { t } = useTranslation();
25
- const [clients, setClients] = useState([]);
26
- const [loading, setLoading] = useState(true);
27
- const [search, setSearch] = useState("");
28
- const [selectedId, setSelectedId] = useState(null);
29
- const [detail, setDetail] = useState(null);
30
- const [detailLoading, setDetailLoading] = useState(false);
31
- const [showMerge, setShowMerge] = useState(false);
32
- const [mergeSearch, setMergeSearch] = useState("");
33
- const [mergeResults, setMergeResults] = useState([]);
34
- const [merging, setMerging] = useState(false);
35
- const [mergeSuccess, setMergeSuccess] = useState("");
36
- const fetchClients = useCallback(async () => {
37
- try {
38
- const params = new URLSearchParams({ limit: "100", sort: "company", depth: "0" });
39
- if (search) params.set("where[company][like]", search);
40
- const res = await fetch(`/api/support-clients?${params}`);
41
- if (res.ok) {
42
- const json = await res.json();
43
- setClients(json.docs || []);
44
- }
45
- } catch {
46
- }
47
- setLoading(false);
48
- }, [search]);
49
- useEffect(() => {
50
- const timeout = setTimeout(fetchClients, 300);
51
- return () => clearTimeout(timeout);
52
- }, [fetchClients]);
53
- const fetchDetail = useCallback(async (clientId) => {
54
- setDetailLoading(true);
55
- try {
56
- const [clientRes, ticketsRes, projectsRes, timeRes] = await Promise.all([
57
- fetch(`/api/support-clients/${clientId}?depth=0`),
58
- fetch(`/api/tickets?where[client][equals]=${clientId}&sort=-createdAt&limit=20&depth=0`),
59
- fetch(`/api/projects?where[client][equals]=${clientId}&depth=0`),
60
- fetch(`/api/time-entries?limit=0&depth=0`)
61
- ]);
62
- const client = clientRes.ok ? await clientRes.json() : null;
63
- const tickets = ticketsRes.ok ? (await ticketsRes.json()).docs || [] : [];
64
- const projects = projectsRes.ok ? (await projectsRes.json()).docs || [] : [];
65
- const ticketIds = tickets.map((t2) => t2.id);
66
- let totalTimeMinutes = 0;
67
- if (timeRes.ok) {
68
- const timeData = await timeRes.json();
69
- totalTimeMinutes = timeData.docs.filter((e) => ticketIds.includes(e.ticket)).reduce((sum, e) => sum + (e.duration || 0), 0);
70
- }
71
- const openTickets = tickets.filter((t2) => ["open", "waiting_client"].includes(t2.status)).length;
72
- const resolvedTickets = tickets.filter((t2) => t2.status === "resolved").length;
73
- setDetail({ client, tickets, projects, stats: { totalTickets: tickets.length, openTickets, resolvedTickets, totalTimeMinutes, lastActivity: tickets.length > 0 ? tickets[0].createdAt : null } });
74
- } catch {
75
- setDetail(null);
76
- }
77
- setDetailLoading(false);
78
- }, []);
79
- const selectClient = (id) => {
80
- setSelectedId(id);
81
- fetchDetail(id);
82
- setShowMerge(false);
83
- setMergeSuccess("");
84
- };
85
- useEffect(() => {
86
- if (!mergeSearch || mergeSearch.length < 2) {
87
- setMergeResults([]);
88
- return;
89
- }
90
- const timer = setTimeout(async () => {
91
- try {
92
- const res = await fetch(`/api/support-clients?where[or][0][company][like]=${encodeURIComponent(mergeSearch)}&where[or][1][email][like]=${encodeURIComponent(mergeSearch)}&limit=10&depth=0`);
93
- if (res.ok) {
94
- const json = await res.json();
95
- setMergeResults((json.docs || []).filter((c) => c.id !== selectedId));
96
- }
97
- } catch {
98
- }
99
- }, 300);
100
- return () => clearTimeout(timer);
101
- }, [mergeSearch, selectedId]);
102
- const handleMerge = async (targetId) => {
103
- if (!selectedId || !detail) return;
104
- if (!confirm(`Fusionner ce client dans un autre ? Cette action est irreversible.`)) return;
105
- setMerging(true);
106
- try {
107
- const res = await fetch("/api/support/merge-clients", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ sourceId: selectedId, targetId }) });
108
- if (res.ok) {
109
- const data = await res.json();
110
- setMergeSuccess(data.message);
111
- setShowMerge(false);
112
- setSelectedId(targetId);
113
- fetchDetail(targetId);
114
- fetchClients();
115
- } else {
116
- const err = await res.json().catch(() => ({ error: "Erreur inconnue" }));
117
- alert(`Erreur : ${err.error}`);
118
- }
119
- } catch {
120
- alert("Erreur reseau");
121
- }
122
- setMerging(false);
123
- };
124
- const S = {
125
- page: { padding: "20px 30px", maxWidth: 1200, margin: "0 auto" },
126
- grid: { display: "grid", gridTemplateColumns: "300px 1fr", gap: 20 },
127
- sidebar: { borderRight: "1px solid var(--theme-elevation-200)", paddingRight: 16 },
128
- searchInput: { width: "100%", padding: "8px 12px", borderRadius: 8, border: "1px solid var(--theme-elevation-200)", fontSize: 13, marginBottom: 12, color: "var(--theme-text)", background: "var(--theme-elevation-0)" },
129
- clientItem: { padding: "10px 12px", borderRadius: 8, cursor: "pointer", marginBottom: 4, border: "1px solid transparent" },
130
- clientItemActive: { background: "var(--theme-elevation-50)", borderColor: "var(--theme-elevation-200)" },
131
- statsGrid: { display: "grid", gridTemplateColumns: "repeat(5, 1fr)", gap: 8, marginBottom: 16 },
132
- statCard: { padding: "10px 12px", borderRadius: 8, border: "1px solid var(--theme-elevation-150)", textAlign: "center" },
133
- table: { width: "100%", borderCollapse: "collapse", fontSize: 13 },
134
- th: { textAlign: "left", padding: "6px 8px", borderBottom: "1px solid var(--theme-elevation-200)", fontSize: 11, color: "var(--theme-elevation-500)" },
135
- td: { padding: "6px 8px", borderBottom: "1px solid var(--theme-elevation-100)" },
136
- badge: { padding: "2px 6px", borderRadius: 4, fontSize: 10, fontWeight: 600 }
137
- };
138
- return /* @__PURE__ */ jsxs("div", { style: S.page, children: [
139
- /* @__PURE__ */ jsxs("div", { style: { marginBottom: 20 }, children: [
140
- /* @__PURE__ */ jsx("h1", { style: { fontSize: 22, fontWeight: 700, margin: 0, color: "var(--theme-text)" }, children: t("crm.title") }),
141
- /* @__PURE__ */ jsx("div", { style: { fontSize: 13, color: "var(--theme-elevation-500)", marginTop: 4 }, children: t("crm.subtitle") })
142
- ] }),
143
- /* @__PURE__ */ jsxs("div", { style: S.grid, children: [
144
- /* @__PURE__ */ jsxs("div", { style: S.sidebar, children: [
145
- /* @__PURE__ */ jsx("input", { type: "text", placeholder: t("crm.searchPlaceholder"), value: search, onChange: (e) => setSearch(e.target.value), style: S.searchInput }),
146
- /* @__PURE__ */ jsx("div", { children: loading ? /* @__PURE__ */ jsx("div", { style: { padding: 20, textAlign: "center", color: "#94a3b8" }, children: t("common.loading") }) : clients.length === 0 ? /* @__PURE__ */ jsx("div", { style: { padding: 20, textAlign: "center", color: "#94a3b8" }, children: t("crm.noClientFound") }) : clients.map((c) => /* @__PURE__ */ jsxs("div", { onClick: () => selectClient(c.id), style: { ...S.clientItem, ...selectedId === c.id ? S.clientItemActive : {} }, children: [
147
- /* @__PURE__ */ jsx("div", { style: { fontWeight: 600, fontSize: 13 }, children: c.company }),
148
- /* @__PURE__ */ jsxs("div", { style: { fontSize: 12, color: "var(--theme-elevation-500)" }, children: [
149
- c.firstName,
150
- " ",
151
- c.lastName
152
- ] }),
153
- /* @__PURE__ */ jsx("div", { style: { fontSize: 11, color: "var(--theme-elevation-400)" }, children: c.email })
154
- ] }, c.id)) })
155
- ] }),
156
- /* @__PURE__ */ jsx("div", { children: !selectedId ? /* @__PURE__ */ jsx("div", { style: { padding: 60, textAlign: "center", color: "#94a3b8" }, children: t("crm.selectClient") }) : detailLoading ? /* @__PURE__ */ jsx("div", { style: { padding: 60, textAlign: "center", color: "#94a3b8" }, children: t("common.loading") }) : detail ? /* @__PURE__ */ jsxs("div", { children: [
157
- /* @__PURE__ */ jsxs("div", { style: { display: "flex", justifyContent: "space-between", marginBottom: 16 }, children: [
158
- /* @__PURE__ */ jsxs("div", { children: [
159
- /* @__PURE__ */ jsx("h2", { style: { fontSize: 20, fontWeight: 700, margin: 0 }, children: detail.client.company }),
160
- /* @__PURE__ */ jsxs("div", { style: { fontSize: 13, color: "var(--theme-elevation-500)" }, children: [
161
- detail.client.firstName,
162
- " ",
163
- detail.client.lastName
164
- ] }),
165
- /* @__PURE__ */ jsxs("div", { style: { fontSize: 12, color: "var(--theme-elevation-400)" }, children: [
166
- detail.client.email,
167
- " ",
168
- detail.client.phone && `-- ${detail.client.phone}`
169
- ] }),
170
- detail.client.notes && /* @__PURE__ */ jsx("div", { style: { fontSize: 12, color: "var(--theme-elevation-500)", marginTop: 4, fontStyle: "italic" }, children: detail.client.notes })
171
- ] }),
172
- /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8 }, children: [
173
- /* @__PURE__ */ jsx("a", { href: `/admin/collections/support-clients/${detail.client.id}`, style: { padding: "6px 14px", borderRadius: 6, background: "#2563eb", color: "#fff", fontSize: 12, fontWeight: 600, textDecoration: "none" }, children: t("crm.editButton") }),
174
- /* @__PURE__ */ jsx("button", { onClick: () => {
175
- setShowMerge(!showMerge);
176
- setMergeSearch("");
177
- setMergeResults([]);
178
- }, style: { padding: "6px 14px", borderRadius: 6, border: "1px solid #d97706", background: "none", color: "#d97706", fontSize: 12, fontWeight: 600, cursor: "pointer" }, children: t("crm.mergeButton") })
179
- ] })
180
- ] }),
181
- mergeSuccess && /* @__PURE__ */ jsx("div", { style: { padding: "8px 14px", borderRadius: 6, background: "#dcfce7", color: "#166534", fontSize: 13, marginBottom: 12 }, children: mergeSuccess }),
182
- showMerge && /* @__PURE__ */ jsxs("div", { style: { padding: 16, borderRadius: 8, border: "1px solid #fde68a", background: "#fefce8", marginBottom: 16 }, children: [
183
- /* @__PURE__ */ jsx("h4", { style: { margin: "0 0 8px", fontSize: 14 }, children: t("crm.mergeTitle") }),
184
- /* @__PURE__ */ jsx("input", { type: "text", value: mergeSearch, onChange: (e) => setMergeSearch(e.target.value), placeholder: t("crm.mergeSearchPlaceholder"), style: S.searchInput }),
185
- mergeResults.map((c) => /* @__PURE__ */ jsxs("button", { onClick: () => handleMerge(c.id), disabled: merging, 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: [
186
- /* @__PURE__ */ jsx("strong", { children: c.company }),
187
- " -- ",
188
- c.firstName,
189
- " ",
190
- c.lastName,
191
- " ",
192
- /* @__PURE__ */ jsx("span", { style: { color: "var(--theme-elevation-400)", fontSize: 11 }, children: c.email })
193
- ] }, c.id))
194
- ] }),
195
- /* @__PURE__ */ jsx("div", { style: S.statsGrid, children: [
196
- { label: t("crm.stats.totalTickets"), value: String(detail.stats.totalTickets) },
197
- { label: t("crm.stats.openTickets"), value: String(detail.stats.openTickets) },
198
- { label: t("crm.stats.resolvedTickets"), value: String(detail.stats.resolvedTickets) },
199
- { label: t("crm.stats.timeSpent"), value: formatDuration(detail.stats.totalTimeMinutes) },
200
- { label: t("crm.stats.lastActivity"), value: detail.stats.lastActivity ? timeAgo(detail.stats.lastActivity) : "-" }
201
- ].map((stat) => /* @__PURE__ */ jsxs("div", { style: S.statCard, children: [
202
- /* @__PURE__ */ jsx("div", { style: { fontSize: 11, color: "var(--theme-elevation-500)", marginBottom: 2 }, children: stat.label }),
203
- /* @__PURE__ */ jsx("div", { style: { fontSize: 18, fontWeight: 700, color: "var(--theme-text)" }, children: stat.value })
204
- ] }, stat.label)) }),
205
- /* @__PURE__ */ jsxs("div", { style: { padding: 16, borderRadius: 10, border: "1px solid var(--theme-elevation-150)", marginBottom: 16 }, children: [
206
- /* @__PURE__ */ jsxs("h3", { style: { fontSize: 14, fontWeight: 700, margin: "0 0 8px" }, children: [
207
- t("crm.sections.tickets"),
208
- " (",
209
- detail.tickets.length,
210
- ")"
211
- ] }),
212
- detail.tickets.length === 0 ? /* @__PURE__ */ jsx("div", { style: { color: "#94a3b8", fontSize: 13 }, children: t("crm.noTickets") }) : /* @__PURE__ */ jsxs("table", { style: S.table, children: [
213
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
214
- /* @__PURE__ */ jsx("th", { style: S.th, children: t("crm.tableHeaders.number") }),
215
- /* @__PURE__ */ jsx("th", { style: S.th, children: t("crm.tableHeaders.subject") }),
216
- /* @__PURE__ */ jsx("th", { style: S.th, children: t("crm.tableHeaders.status") }),
217
- /* @__PURE__ */ jsx("th", { style: S.th, children: t("crm.tableHeaders.date") })
218
- ] }) }),
219
- /* @__PURE__ */ jsx("tbody", { children: detail.tickets.map((tk) => /* @__PURE__ */ jsxs("tr", { children: [
220
- /* @__PURE__ */ jsx("td", { style: S.td, children: /* @__PURE__ */ jsx("a", { href: `/admin/support/ticket?id=${tk.id}`, style: { color: "#2563eb", fontWeight: 600, textDecoration: "none" }, children: tk.ticketNumber }) }),
221
- /* @__PURE__ */ jsx("td", { style: S.td, children: tk.subject }),
222
- /* @__PURE__ */ jsx("td", { style: S.td, children: /* @__PURE__ */ jsx("span", { style: { ...S.badge, background: `${statusColors[tk.status] || "#94a3b8"}20`, color: statusColors[tk.status] || "#94a3b8" }, children: statusLabelKeys[tk.status] ? t(statusLabelKeys[tk.status]) : tk.status }) }),
223
- /* @__PURE__ */ jsx("td", { style: { ...S.td, fontSize: 12, color: "var(--theme-elevation-400)" }, children: timeAgo(tk.createdAt) })
224
- ] }, tk.id)) })
225
- ] })
226
- ] })
227
- ] }) : null })
228
- ] })
229
- ] });
230
- };
231
-
232
- export { CrmClient };
@@ -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 { CrmClient } from './client';
6
-
7
- const CrmView = ({ 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: "CrmView", children: /* @__PURE__ */ jsx(CrmClient, {}) })
24
- }
25
- );
26
- };
27
- var CrmView_default = CrmView;
28
-
29
- export { CrmView, CrmView_default as default };