@consilioweb/payload-support 0.6.2 → 0.6.4
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/components/TicketConversation/components/AISummaryPanel.cjs +77 -0
- package/dist/components/TicketConversation/components/AISummaryPanel.js +76 -0
- package/dist/components/TicketConversation/components/ActionPanels.cjs +121 -0
- package/dist/components/TicketConversation/components/ActionPanels.js +118 -0
- package/dist/components/TicketConversation/components/ActivityLog.cjs +24 -0
- package/dist/components/TicketConversation/components/ActivityLog.js +23 -0
- package/dist/components/TicketConversation/components/ClientBar.cjs +43 -0
- package/dist/components/TicketConversation/components/ClientBar.js +42 -0
- package/dist/components/TicketConversation/components/ClientHistory.cjs +138 -0
- package/dist/components/TicketConversation/components/ClientHistory.js +137 -0
- package/dist/components/TicketConversation/components/CodeBlock.cjs +154 -0
- package/dist/components/TicketConversation/components/CodeBlock.js +152 -0
- package/dist/components/TicketConversation/components/CodeBlockInserter.cjs +156 -0
- package/dist/components/TicketConversation/components/CodeBlockInserter.js +155 -0
- package/dist/components/TicketConversation/components/QuickActions.cjs +66 -0
- package/dist/components/TicketConversation/components/QuickActions.js +65 -0
- package/dist/components/TicketConversation/components/TicketHeader.cjs +93 -0
- package/dist/components/TicketConversation/components/TicketHeader.js +92 -0
- package/dist/components/TicketConversation/components/TimeTrackingPanel.cjs +134 -0
- package/dist/components/TicketConversation/components/TimeTrackingPanel.js +133 -0
- package/dist/components/TicketConversation/config.cjs +44 -0
- package/dist/components/TicketConversation/config.js +41 -0
- package/dist/components/TicketConversation/constants.cjs +100 -0
- package/dist/components/TicketConversation/constants.js +96 -0
- package/dist/components/TicketConversation/context.cjs +13 -0
- package/dist/components/TicketConversation/context.js +11 -0
- package/dist/components/TicketConversation/hooks/useAI.cjs +177 -0
- package/dist/components/TicketConversation/hooks/useAI.js +176 -0
- package/dist/components/TicketConversation/hooks/useMessageActions.cjs +136 -0
- package/dist/components/TicketConversation/hooks/useMessageActions.js +135 -0
- package/dist/components/TicketConversation/hooks/useReply.cjs +188 -0
- package/dist/components/TicketConversation/hooks/useReply.js +187 -0
- package/dist/components/TicketConversation/hooks/useTicketActions.cjs +231 -0
- package/dist/components/TicketConversation/hooks/useTicketActions.js +230 -0
- package/dist/components/TicketConversation/hooks/useTimeTracking.cjs +123 -0
- package/dist/components/TicketConversation/hooks/useTimeTracking.js +122 -0
- package/dist/components/TicketConversation/hooks/useTranslation.cjs +78 -0
- package/dist/components/TicketConversation/hooks/useTranslation.js +70 -0
- package/dist/components/TicketConversation/index.cjs +1128 -0
- package/dist/components/TicketConversation/index.js +1123 -0
- package/dist/components/TicketConversation/locales/en.json +878 -0
- package/dist/components/TicketConversation/locales/fr.json +878 -0
- package/dist/components/TicketConversation/types.cjs +2 -0
- package/dist/components/TicketConversation/types.js +2 -0
- package/dist/components/TicketConversation/utils.cjs +27 -0
- package/dist/components/TicketConversation/utils.js +25 -0
- package/dist/styles/BillingView.module.scss +311 -0
- package/dist/styles/ChatView.module.scss +438 -0
- package/dist/styles/CommandPalette.module.scss +160 -0
- package/dist/styles/CrmView.module.scss +554 -0
- package/dist/styles/EmailTracking.module.scss +238 -0
- package/dist/styles/ImportConversation.module.scss +267 -0
- package/dist/styles/Layout.module.scss +55 -0
- package/dist/styles/Logs.module.scss +164 -0
- package/dist/styles/NewTicket.module.scss +143 -0
- package/dist/styles/PendingEmails.module.scss +629 -0
- package/dist/styles/SupportDashboard.module.scss +649 -0
- package/dist/styles/TicketDetail.module.scss +1050 -0
- package/dist/styles/TicketInbox.module.scss +296 -0
- package/dist/styles/TicketingSettings.module.scss +358 -0
- package/dist/styles/TimeDashboard.module.scss +287 -0
- package/dist/styles/_tokens.scss +78 -0
- package/dist/{components/TicketConversation.css → styles/theme.css} +326 -13
- package/dist/views/BillingView/client.js +1 -1
- package/dist/views/BillingView/index.js +2 -2
- package/dist/views/ChatView/client.js +1 -1
- package/dist/views/ChatView/index.js +2 -2
- package/dist/views/CrmView/client.js +1 -1
- package/dist/views/CrmView/index.js +2 -2
- package/dist/views/EmailTrackingView/client.js +1 -1
- package/dist/views/EmailTrackingView/index.js +2 -2
- package/dist/views/ImportConversationView/client.js +1 -1
- package/dist/views/ImportConversationView/index.js +2 -2
- package/dist/views/LogsView/client.js +1 -1
- package/dist/views/LogsView/index.js +2 -2
- package/dist/views/NewTicketView/client.js +1 -1
- package/dist/views/NewTicketView/index.js +2 -2
- package/dist/views/PendingEmailsView/client.js +1 -1
- package/dist/views/PendingEmailsView/index.js +2 -2
- package/dist/views/SupportDashboardView/client.js +1 -1
- package/dist/views/SupportDashboardView/index.js +2 -2
- package/dist/views/TicketDetailView/client.js +2 -2
- package/dist/views/TicketDetailView/index.js +2 -2
- package/dist/views/TicketInboxView/client.js +1 -1
- package/dist/views/TicketInboxView/index.js +2 -2
- package/dist/views/TicketingSettingsView/client.js +3 -3
- package/dist/views/TicketingSettingsView/index.js +2 -2
- package/dist/views/TimeDashboardView/client.js +1 -1
- package/dist/views/TimeDashboardView/index.js +2 -2
- package/dist/views/shared/AdminViewHeader.js +1 -1
- package/dist/views/shared/index.js +5 -5
- package/dist/views.js +13 -13
- package/package.json +2 -2
- package/dist/components/TicketConversation.js +0 -3004
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
function useAI(messages, client, ticketSubject, replyBody, setReplyBody, setReplyHtml, replyEditorRef) {
|
|
6
|
+
const [clientSentiment, setClientSentiment] = react.useState(null);
|
|
7
|
+
const [aiReplying, setAiReplying] = react.useState(false);
|
|
8
|
+
const [aiRewriting, setAiRewriting] = react.useState(false);
|
|
9
|
+
const [showAiSummary, setShowAiSummary] = react.useState(false);
|
|
10
|
+
const [aiSummary, setAiSummary] = react.useState("");
|
|
11
|
+
const [aiGenerating, setAiGenerating] = react.useState(false);
|
|
12
|
+
const [aiSaving, setAiSaving] = react.useState(false);
|
|
13
|
+
const [aiSaved, setAiSaved] = react.useState(false);
|
|
14
|
+
react.useEffect(() => {
|
|
15
|
+
if (messages.length === 0) return;
|
|
16
|
+
const lastClientMsg = [...messages].reverse().find((m) => m.authorType === "client" || m.authorType === "email");
|
|
17
|
+
if (!lastClientMsg) return;
|
|
18
|
+
const analyze = async () => {
|
|
19
|
+
try {
|
|
20
|
+
const res = await fetch("/api/support/ai", {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: { "Content-Type": "application/json" },
|
|
23
|
+
credentials: "include",
|
|
24
|
+
body: JSON.stringify({ action: "sentiment", text: lastClientMsg.body.slice(0, 500) })
|
|
25
|
+
});
|
|
26
|
+
if (res.ok) {
|
|
27
|
+
const data = await res.json();
|
|
28
|
+
const raw = (data.sentiment || "").toLowerCase().trim();
|
|
29
|
+
const sentimentMap = {
|
|
30
|
+
"frustr\xE9": { emoji: "\u{1F624}", label: "Frustr\xE9", color: "#dc2626" },
|
|
31
|
+
"frustre": { emoji: "\u{1F624}", label: "Frustr\xE9", color: "#dc2626" },
|
|
32
|
+
"m\xE9content": { emoji: "\u{1F620}", label: "M\xE9content", color: "#ea580c" },
|
|
33
|
+
"mecontent": { emoji: "\u{1F620}", label: "M\xE9content", color: "#ea580c" },
|
|
34
|
+
"urgent": { emoji: "\u{1F525}", label: "Urgent", color: "#dc2626" },
|
|
35
|
+
"neutre": { emoji: "\u{1F610}", label: "Neutre", color: "#6b7280" },
|
|
36
|
+
"satisfait": { emoji: "\u{1F60A}", label: "Satisfait", color: "#16a34a" }
|
|
37
|
+
};
|
|
38
|
+
const match = Object.keys(sentimentMap).find((k) => raw.includes(k));
|
|
39
|
+
if (match) setClientSentiment(sentimentMap[match]);
|
|
40
|
+
else setClientSentiment({ emoji: "\u{1F610}", label: "Neutre", color: "#6b7280" });
|
|
41
|
+
}
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
analyze();
|
|
46
|
+
}, [messages.length]);
|
|
47
|
+
const handleAiSuggestReply = async () => {
|
|
48
|
+
if (messages.length === 0) return;
|
|
49
|
+
setAiReplying(true);
|
|
50
|
+
try {
|
|
51
|
+
const res = await fetch("/api/support/ai", {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { "Content-Type": "application/json" },
|
|
54
|
+
credentials: "include",
|
|
55
|
+
body: JSON.stringify({
|
|
56
|
+
action: "suggest_reply",
|
|
57
|
+
messages: messages.slice(-10).map((m) => ({ authorType: m.authorType, body: m.body })),
|
|
58
|
+
clientName: `${client?.firstName || ""} ${client?.lastName || ""}`.trim(),
|
|
59
|
+
clientCompany: client?.company
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
if (res.ok) {
|
|
63
|
+
const data = await res.json();
|
|
64
|
+
const suggestion = data.reply || "";
|
|
65
|
+
if (suggestion) {
|
|
66
|
+
setReplyBody(suggestion);
|
|
67
|
+
setReplyHtml(suggestion.replace(/\n/g, "<br/>"));
|
|
68
|
+
if (replyEditorRef.current?.setContent) {
|
|
69
|
+
replyEditorRef.current.setContent(suggestion.replace(/\n/g, "<br/>"));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch (err) {
|
|
74
|
+
console.error("AI suggest error:", err);
|
|
75
|
+
}
|
|
76
|
+
setAiReplying(false);
|
|
77
|
+
};
|
|
78
|
+
const handleAiRewrite = async () => {
|
|
79
|
+
if (!replyBody.trim()) return;
|
|
80
|
+
setAiRewriting(true);
|
|
81
|
+
try {
|
|
82
|
+
const res = await fetch("/api/support/ai", {
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: { "Content-Type": "application/json" },
|
|
85
|
+
credentials: "include",
|
|
86
|
+
body: JSON.stringify({ action: "rewrite", text: replyBody })
|
|
87
|
+
});
|
|
88
|
+
if (res.ok) {
|
|
89
|
+
const data = await res.json();
|
|
90
|
+
const rewritten = data.rewritten || "";
|
|
91
|
+
if (rewritten) {
|
|
92
|
+
setReplyBody(rewritten);
|
|
93
|
+
setReplyHtml(rewritten.replace(/\n/g, "<br/>"));
|
|
94
|
+
if (replyEditorRef.current?.setContent) {
|
|
95
|
+
replyEditorRef.current.setContent(rewritten.replace(/\n/g, "<br/>"));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (err) {
|
|
100
|
+
console.error("AI rewrite error:", err);
|
|
101
|
+
}
|
|
102
|
+
setAiRewriting(false);
|
|
103
|
+
};
|
|
104
|
+
const handleAiGenerate = async () => {
|
|
105
|
+
if (messages.length === 0) return;
|
|
106
|
+
setAiGenerating(true);
|
|
107
|
+
setAiSummary("");
|
|
108
|
+
setAiSaved(false);
|
|
109
|
+
try {
|
|
110
|
+
const res = await fetch("/api/support/ai", {
|
|
111
|
+
method: "POST",
|
|
112
|
+
headers: { "Content-Type": "application/json" },
|
|
113
|
+
credentials: "include",
|
|
114
|
+
body: JSON.stringify({
|
|
115
|
+
action: "synthesis",
|
|
116
|
+
messages: messages.map((m) => ({ authorType: m.authorType, body: m.body, createdAt: m.createdAt })),
|
|
117
|
+
ticketSubject,
|
|
118
|
+
clientName: `${client?.firstName || ""} ${client?.lastName || ""}`.trim(),
|
|
119
|
+
clientCompany: client?.company
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
if (res.ok) {
|
|
123
|
+
const data = await res.json();
|
|
124
|
+
setAiSummary(data.synthesis || "Aucune r\xE9ponse g\xE9n\xE9r\xE9e");
|
|
125
|
+
} else {
|
|
126
|
+
setAiSummary("Erreur lors de la g\xE9n\xE9ration de la synth\xE8se.");
|
|
127
|
+
}
|
|
128
|
+
} catch (err) {
|
|
129
|
+
setAiSummary(`Erreur de connexion : ${err instanceof Error ? err.message : "erreur inconnue"}`);
|
|
130
|
+
} finally {
|
|
131
|
+
setAiGenerating(false);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const handleAiSave = async (id, fetchAll) => {
|
|
135
|
+
if (!id || !aiSummary) return;
|
|
136
|
+
setAiSaving(true);
|
|
137
|
+
try {
|
|
138
|
+
const res = await fetch("/api/ticket-messages", {
|
|
139
|
+
method: "POST",
|
|
140
|
+
headers: { "Content-Type": "application/json" },
|
|
141
|
+
credentials: "include",
|
|
142
|
+
body: JSON.stringify({
|
|
143
|
+
ticket: id,
|
|
144
|
+
body: `\u{1F4CB} **Synth\xE8se IA (${(/* @__PURE__ */ new Date()).toLocaleDateString("fr-FR")})**
|
|
145
|
+
|
|
146
|
+
${aiSummary}`,
|
|
147
|
+
authorType: "admin",
|
|
148
|
+
isInternal: true
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
if (res.ok) {
|
|
152
|
+
setAiSaved(true);
|
|
153
|
+
fetchAll();
|
|
154
|
+
}
|
|
155
|
+
} catch {
|
|
156
|
+
} finally {
|
|
157
|
+
setAiSaving(false);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
clientSentiment,
|
|
162
|
+
aiReplying,
|
|
163
|
+
handleAiSuggestReply,
|
|
164
|
+
aiRewriting,
|
|
165
|
+
handleAiRewrite,
|
|
166
|
+
showAiSummary,
|
|
167
|
+
setShowAiSummary,
|
|
168
|
+
aiSummary,
|
|
169
|
+
aiGenerating,
|
|
170
|
+
handleAiGenerate,
|
|
171
|
+
aiSaving,
|
|
172
|
+
aiSaved,
|
|
173
|
+
handleAiSave
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
exports.useAI = useAI;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
function useAI(messages, client, ticketSubject, replyBody, setReplyBody, setReplyHtml, replyEditorRef) {
|
|
5
|
+
const [clientSentiment, setClientSentiment] = useState(null);
|
|
6
|
+
const [aiReplying, setAiReplying] = useState(false);
|
|
7
|
+
const [aiRewriting, setAiRewriting] = useState(false);
|
|
8
|
+
const [showAiSummary, setShowAiSummary] = useState(false);
|
|
9
|
+
const [aiSummary, setAiSummary] = useState("");
|
|
10
|
+
const [aiGenerating, setAiGenerating] = useState(false);
|
|
11
|
+
const [aiSaving, setAiSaving] = useState(false);
|
|
12
|
+
const [aiSaved, setAiSaved] = useState(false);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (messages.length === 0) return;
|
|
15
|
+
const lastClientMsg = [...messages].reverse().find((m) => m.authorType === "client" || m.authorType === "email");
|
|
16
|
+
if (!lastClientMsg) return;
|
|
17
|
+
const analyze = async () => {
|
|
18
|
+
try {
|
|
19
|
+
const res = await fetch("/api/support/ai", {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: { "Content-Type": "application/json" },
|
|
22
|
+
credentials: "include",
|
|
23
|
+
body: JSON.stringify({ action: "sentiment", text: lastClientMsg.body.slice(0, 500) })
|
|
24
|
+
});
|
|
25
|
+
if (res.ok) {
|
|
26
|
+
const data = await res.json();
|
|
27
|
+
const raw = (data.sentiment || "").toLowerCase().trim();
|
|
28
|
+
const sentimentMap = {
|
|
29
|
+
"frustr\xE9": { emoji: "\u{1F624}", label: "Frustr\xE9", color: "#dc2626" },
|
|
30
|
+
"frustre": { emoji: "\u{1F624}", label: "Frustr\xE9", color: "#dc2626" },
|
|
31
|
+
"m\xE9content": { emoji: "\u{1F620}", label: "M\xE9content", color: "#ea580c" },
|
|
32
|
+
"mecontent": { emoji: "\u{1F620}", label: "M\xE9content", color: "#ea580c" },
|
|
33
|
+
"urgent": { emoji: "\u{1F525}", label: "Urgent", color: "#dc2626" },
|
|
34
|
+
"neutre": { emoji: "\u{1F610}", label: "Neutre", color: "#6b7280" },
|
|
35
|
+
"satisfait": { emoji: "\u{1F60A}", label: "Satisfait", color: "#16a34a" }
|
|
36
|
+
};
|
|
37
|
+
const match = Object.keys(sentimentMap).find((k) => raw.includes(k));
|
|
38
|
+
if (match) setClientSentiment(sentimentMap[match]);
|
|
39
|
+
else setClientSentiment({ emoji: "\u{1F610}", label: "Neutre", color: "#6b7280" });
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
analyze();
|
|
45
|
+
}, [messages.length]);
|
|
46
|
+
const handleAiSuggestReply = async () => {
|
|
47
|
+
if (messages.length === 0) return;
|
|
48
|
+
setAiReplying(true);
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetch("/api/support/ai", {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: { "Content-Type": "application/json" },
|
|
53
|
+
credentials: "include",
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
action: "suggest_reply",
|
|
56
|
+
messages: messages.slice(-10).map((m) => ({ authorType: m.authorType, body: m.body })),
|
|
57
|
+
clientName: `${client?.firstName || ""} ${client?.lastName || ""}`.trim(),
|
|
58
|
+
clientCompany: client?.company
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
if (res.ok) {
|
|
62
|
+
const data = await res.json();
|
|
63
|
+
const suggestion = data.reply || "";
|
|
64
|
+
if (suggestion) {
|
|
65
|
+
setReplyBody(suggestion);
|
|
66
|
+
setReplyHtml(suggestion.replace(/\n/g, "<br/>"));
|
|
67
|
+
if (replyEditorRef.current?.setContent) {
|
|
68
|
+
replyEditorRef.current.setContent(suggestion.replace(/\n/g, "<br/>"));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.error("AI suggest error:", err);
|
|
74
|
+
}
|
|
75
|
+
setAiReplying(false);
|
|
76
|
+
};
|
|
77
|
+
const handleAiRewrite = async () => {
|
|
78
|
+
if (!replyBody.trim()) return;
|
|
79
|
+
setAiRewriting(true);
|
|
80
|
+
try {
|
|
81
|
+
const res = await fetch("/api/support/ai", {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
84
|
+
credentials: "include",
|
|
85
|
+
body: JSON.stringify({ action: "rewrite", text: replyBody })
|
|
86
|
+
});
|
|
87
|
+
if (res.ok) {
|
|
88
|
+
const data = await res.json();
|
|
89
|
+
const rewritten = data.rewritten || "";
|
|
90
|
+
if (rewritten) {
|
|
91
|
+
setReplyBody(rewritten);
|
|
92
|
+
setReplyHtml(rewritten.replace(/\n/g, "<br/>"));
|
|
93
|
+
if (replyEditorRef.current?.setContent) {
|
|
94
|
+
replyEditorRef.current.setContent(rewritten.replace(/\n/g, "<br/>"));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
console.error("AI rewrite error:", err);
|
|
100
|
+
}
|
|
101
|
+
setAiRewriting(false);
|
|
102
|
+
};
|
|
103
|
+
const handleAiGenerate = async () => {
|
|
104
|
+
if (messages.length === 0) return;
|
|
105
|
+
setAiGenerating(true);
|
|
106
|
+
setAiSummary("");
|
|
107
|
+
setAiSaved(false);
|
|
108
|
+
try {
|
|
109
|
+
const res = await fetch("/api/support/ai", {
|
|
110
|
+
method: "POST",
|
|
111
|
+
headers: { "Content-Type": "application/json" },
|
|
112
|
+
credentials: "include",
|
|
113
|
+
body: JSON.stringify({
|
|
114
|
+
action: "synthesis",
|
|
115
|
+
messages: messages.map((m) => ({ authorType: m.authorType, body: m.body, createdAt: m.createdAt })),
|
|
116
|
+
ticketSubject,
|
|
117
|
+
clientName: `${client?.firstName || ""} ${client?.lastName || ""}`.trim(),
|
|
118
|
+
clientCompany: client?.company
|
|
119
|
+
})
|
|
120
|
+
});
|
|
121
|
+
if (res.ok) {
|
|
122
|
+
const data = await res.json();
|
|
123
|
+
setAiSummary(data.synthesis || "Aucune r\xE9ponse g\xE9n\xE9r\xE9e");
|
|
124
|
+
} else {
|
|
125
|
+
setAiSummary("Erreur lors de la g\xE9n\xE9ration de la synth\xE8se.");
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
setAiSummary(`Erreur de connexion : ${err instanceof Error ? err.message : "erreur inconnue"}`);
|
|
129
|
+
} finally {
|
|
130
|
+
setAiGenerating(false);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const handleAiSave = async (id, fetchAll) => {
|
|
134
|
+
if (!id || !aiSummary) return;
|
|
135
|
+
setAiSaving(true);
|
|
136
|
+
try {
|
|
137
|
+
const res = await fetch("/api/ticket-messages", {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers: { "Content-Type": "application/json" },
|
|
140
|
+
credentials: "include",
|
|
141
|
+
body: JSON.stringify({
|
|
142
|
+
ticket: id,
|
|
143
|
+
body: `\u{1F4CB} **Synth\xE8se IA (${(/* @__PURE__ */ new Date()).toLocaleDateString("fr-FR")})**
|
|
144
|
+
|
|
145
|
+
${aiSummary}`,
|
|
146
|
+
authorType: "admin",
|
|
147
|
+
isInternal: true
|
|
148
|
+
})
|
|
149
|
+
});
|
|
150
|
+
if (res.ok) {
|
|
151
|
+
setAiSaved(true);
|
|
152
|
+
fetchAll();
|
|
153
|
+
}
|
|
154
|
+
} catch {
|
|
155
|
+
} finally {
|
|
156
|
+
setAiSaving(false);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
clientSentiment,
|
|
161
|
+
aiReplying,
|
|
162
|
+
handleAiSuggestReply,
|
|
163
|
+
aiRewriting,
|
|
164
|
+
handleAiRewrite,
|
|
165
|
+
showAiSummary,
|
|
166
|
+
setShowAiSummary,
|
|
167
|
+
aiSummary,
|
|
168
|
+
aiGenerating,
|
|
169
|
+
handleAiGenerate,
|
|
170
|
+
aiSaving,
|
|
171
|
+
aiSaved,
|
|
172
|
+
handleAiSave
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export { useAI };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
function useMessageActions(id, client, fetchAll) {
|
|
6
|
+
const [togglingAuthor, setTogglingAuthor] = react.useState(null);
|
|
7
|
+
const [editingMsg, setEditingMsg] = react.useState(null);
|
|
8
|
+
const [editBody, setEditBody] = react.useState("");
|
|
9
|
+
const [editHtml, setEditHtml] = react.useState("");
|
|
10
|
+
const [savingEdit, setSavingEdit] = react.useState(false);
|
|
11
|
+
const [deletingMsg, setDeletingMsg] = react.useState(null);
|
|
12
|
+
const [resendingMsg, setResendingMsg] = react.useState(null);
|
|
13
|
+
const [resendSuccess, setResendSuccess] = react.useState(null);
|
|
14
|
+
const handleEditStart = (msg) => {
|
|
15
|
+
setEditingMsg(msg.id);
|
|
16
|
+
setEditBody(msg.body);
|
|
17
|
+
setEditHtml(msg.bodyHtml || msg.body.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\n/g, "<br />"));
|
|
18
|
+
};
|
|
19
|
+
const handleEditSave = async (msgId) => {
|
|
20
|
+
if (!editBody.trim()) return;
|
|
21
|
+
setSavingEdit(true);
|
|
22
|
+
try {
|
|
23
|
+
const res = await fetch(`/api/ticket-messages/${msgId}`, {
|
|
24
|
+
method: "PATCH",
|
|
25
|
+
headers: { "Content-Type": "application/json" },
|
|
26
|
+
credentials: "include",
|
|
27
|
+
body: JSON.stringify({ body: editBody.trim(), ...editHtml ? { bodyHtml: editHtml } : {} })
|
|
28
|
+
});
|
|
29
|
+
if (res.ok) {
|
|
30
|
+
setEditingMsg(null);
|
|
31
|
+
setEditBody("");
|
|
32
|
+
fetchAll();
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
} finally {
|
|
36
|
+
setSavingEdit(false);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const handleEditCancel = () => {
|
|
40
|
+
setEditingMsg(null);
|
|
41
|
+
setEditBody("");
|
|
42
|
+
setEditHtml("");
|
|
43
|
+
};
|
|
44
|
+
const handleDelete = async (msgId) => {
|
|
45
|
+
if (!window.confirm("Supprimer ce message ?")) return;
|
|
46
|
+
setDeletingMsg(msgId);
|
|
47
|
+
try {
|
|
48
|
+
const res = await fetch(`/api/ticket-messages/${msgId}`, {
|
|
49
|
+
method: "DELETE",
|
|
50
|
+
credentials: "include"
|
|
51
|
+
});
|
|
52
|
+
if (res.ok) fetchAll();
|
|
53
|
+
} catch {
|
|
54
|
+
} finally {
|
|
55
|
+
setDeletingMsg(null);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const handleResend = async (msgId) => {
|
|
59
|
+
setResendingMsg(msgId);
|
|
60
|
+
setResendSuccess(null);
|
|
61
|
+
try {
|
|
62
|
+
const res = await fetch("/api/support/resend-notification", {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: { "Content-Type": "application/json" },
|
|
65
|
+
credentials: "include",
|
|
66
|
+
body: JSON.stringify({ messageId: msgId })
|
|
67
|
+
});
|
|
68
|
+
if (res.ok) {
|
|
69
|
+
setResendSuccess(msgId);
|
|
70
|
+
setTimeout(() => setResendSuccess(null), 3e3);
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
} finally {
|
|
74
|
+
setResendingMsg(null);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const handleToggleAuthor = async (msgId, currentType) => {
|
|
78
|
+
const newType = currentType === "admin" ? "client" : "admin";
|
|
79
|
+
setTogglingAuthor(msgId);
|
|
80
|
+
try {
|
|
81
|
+
const patchData = { authorType: newType };
|
|
82
|
+
if (newType === "client" && client) {
|
|
83
|
+
patchData.authorClient = client.id;
|
|
84
|
+
}
|
|
85
|
+
const res = await fetch(`/api/ticket-messages/${msgId}`, {
|
|
86
|
+
method: "PATCH",
|
|
87
|
+
headers: { "Content-Type": "application/json" },
|
|
88
|
+
credentials: "include",
|
|
89
|
+
body: JSON.stringify(patchData)
|
|
90
|
+
});
|
|
91
|
+
if (res.ok) fetchAll();
|
|
92
|
+
} catch {
|
|
93
|
+
} finally {
|
|
94
|
+
setTogglingAuthor(null);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const handleSplitMessage = async (msgId, ticketSubject) => {
|
|
98
|
+
const subject = prompt("Sujet du nouveau ticket :", `Split: ${ticketSubject}`);
|
|
99
|
+
if (!subject) return;
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch("/api/support/split-ticket", {
|
|
102
|
+
method: "POST",
|
|
103
|
+
headers: { "Content-Type": "application/json" },
|
|
104
|
+
credentials: "include",
|
|
105
|
+
body: JSON.stringify({ messageId: msgId, subject })
|
|
106
|
+
});
|
|
107
|
+
if (res.ok) {
|
|
108
|
+
const data = await res.json();
|
|
109
|
+
alert(`Ticket ${data.ticketNumber} cr\xE9\xE9`);
|
|
110
|
+
fetchAll();
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
togglingAuthor,
|
|
117
|
+
editingMsg,
|
|
118
|
+
editBody,
|
|
119
|
+
editHtml,
|
|
120
|
+
setEditHtml,
|
|
121
|
+
savingEdit,
|
|
122
|
+
handleEditStart,
|
|
123
|
+
handleEditSave,
|
|
124
|
+
handleEditCancel,
|
|
125
|
+
deletingMsg,
|
|
126
|
+
handleDelete,
|
|
127
|
+
resendingMsg,
|
|
128
|
+
resendSuccess,
|
|
129
|
+
handleResend,
|
|
130
|
+
handleToggleAuthor,
|
|
131
|
+
handleSplitMessage,
|
|
132
|
+
setEditBody
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
exports.useMessageActions = useMessageActions;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
function useMessageActions(id, client, fetchAll) {
|
|
5
|
+
const [togglingAuthor, setTogglingAuthor] = useState(null);
|
|
6
|
+
const [editingMsg, setEditingMsg] = useState(null);
|
|
7
|
+
const [editBody, setEditBody] = useState("");
|
|
8
|
+
const [editHtml, setEditHtml] = useState("");
|
|
9
|
+
const [savingEdit, setSavingEdit] = useState(false);
|
|
10
|
+
const [deletingMsg, setDeletingMsg] = useState(null);
|
|
11
|
+
const [resendingMsg, setResendingMsg] = useState(null);
|
|
12
|
+
const [resendSuccess, setResendSuccess] = useState(null);
|
|
13
|
+
const handleEditStart = (msg) => {
|
|
14
|
+
setEditingMsg(msg.id);
|
|
15
|
+
setEditBody(msg.body);
|
|
16
|
+
setEditHtml(msg.bodyHtml || msg.body.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\n/g, "<br />"));
|
|
17
|
+
};
|
|
18
|
+
const handleEditSave = async (msgId) => {
|
|
19
|
+
if (!editBody.trim()) return;
|
|
20
|
+
setSavingEdit(true);
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch(`/api/ticket-messages/${msgId}`, {
|
|
23
|
+
method: "PATCH",
|
|
24
|
+
headers: { "Content-Type": "application/json" },
|
|
25
|
+
credentials: "include",
|
|
26
|
+
body: JSON.stringify({ body: editBody.trim(), ...editHtml ? { bodyHtml: editHtml } : {} })
|
|
27
|
+
});
|
|
28
|
+
if (res.ok) {
|
|
29
|
+
setEditingMsg(null);
|
|
30
|
+
setEditBody("");
|
|
31
|
+
fetchAll();
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
} finally {
|
|
35
|
+
setSavingEdit(false);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const handleEditCancel = () => {
|
|
39
|
+
setEditingMsg(null);
|
|
40
|
+
setEditBody("");
|
|
41
|
+
setEditHtml("");
|
|
42
|
+
};
|
|
43
|
+
const handleDelete = async (msgId) => {
|
|
44
|
+
if (!window.confirm("Supprimer ce message ?")) return;
|
|
45
|
+
setDeletingMsg(msgId);
|
|
46
|
+
try {
|
|
47
|
+
const res = await fetch(`/api/ticket-messages/${msgId}`, {
|
|
48
|
+
method: "DELETE",
|
|
49
|
+
credentials: "include"
|
|
50
|
+
});
|
|
51
|
+
if (res.ok) fetchAll();
|
|
52
|
+
} catch {
|
|
53
|
+
} finally {
|
|
54
|
+
setDeletingMsg(null);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const handleResend = async (msgId) => {
|
|
58
|
+
setResendingMsg(msgId);
|
|
59
|
+
setResendSuccess(null);
|
|
60
|
+
try {
|
|
61
|
+
const res = await fetch("/api/support/resend-notification", {
|
|
62
|
+
method: "POST",
|
|
63
|
+
headers: { "Content-Type": "application/json" },
|
|
64
|
+
credentials: "include",
|
|
65
|
+
body: JSON.stringify({ messageId: msgId })
|
|
66
|
+
});
|
|
67
|
+
if (res.ok) {
|
|
68
|
+
setResendSuccess(msgId);
|
|
69
|
+
setTimeout(() => setResendSuccess(null), 3e3);
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
} finally {
|
|
73
|
+
setResendingMsg(null);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const handleToggleAuthor = async (msgId, currentType) => {
|
|
77
|
+
const newType = currentType === "admin" ? "client" : "admin";
|
|
78
|
+
setTogglingAuthor(msgId);
|
|
79
|
+
try {
|
|
80
|
+
const patchData = { authorType: newType };
|
|
81
|
+
if (newType === "client" && client) {
|
|
82
|
+
patchData.authorClient = client.id;
|
|
83
|
+
}
|
|
84
|
+
const res = await fetch(`/api/ticket-messages/${msgId}`, {
|
|
85
|
+
method: "PATCH",
|
|
86
|
+
headers: { "Content-Type": "application/json" },
|
|
87
|
+
credentials: "include",
|
|
88
|
+
body: JSON.stringify(patchData)
|
|
89
|
+
});
|
|
90
|
+
if (res.ok) fetchAll();
|
|
91
|
+
} catch {
|
|
92
|
+
} finally {
|
|
93
|
+
setTogglingAuthor(null);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const handleSplitMessage = async (msgId, ticketSubject) => {
|
|
97
|
+
const subject = prompt("Sujet du nouveau ticket :", `Split: ${ticketSubject}`);
|
|
98
|
+
if (!subject) return;
|
|
99
|
+
try {
|
|
100
|
+
const res = await fetch("/api/support/split-ticket", {
|
|
101
|
+
method: "POST",
|
|
102
|
+
headers: { "Content-Type": "application/json" },
|
|
103
|
+
credentials: "include",
|
|
104
|
+
body: JSON.stringify({ messageId: msgId, subject })
|
|
105
|
+
});
|
|
106
|
+
if (res.ok) {
|
|
107
|
+
const data = await res.json();
|
|
108
|
+
alert(`Ticket ${data.ticketNumber} cr\xE9\xE9`);
|
|
109
|
+
fetchAll();
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
togglingAuthor,
|
|
116
|
+
editingMsg,
|
|
117
|
+
editBody,
|
|
118
|
+
editHtml,
|
|
119
|
+
setEditHtml,
|
|
120
|
+
savingEdit,
|
|
121
|
+
handleEditStart,
|
|
122
|
+
handleEditSave,
|
|
123
|
+
handleEditCancel,
|
|
124
|
+
deletingMsg,
|
|
125
|
+
handleDelete,
|
|
126
|
+
resendingMsg,
|
|
127
|
+
resendSuccess,
|
|
128
|
+
handleResend,
|
|
129
|
+
handleToggleAuthor,
|
|
130
|
+
handleSplitMessage,
|
|
131
|
+
setEditBody
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { useMessageActions };
|