@consilioweb/payload-support 0.16.0 → 1.1.0
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/README.md +357 -435
- package/dist/components/TicketConversation/RewriteDropdown.cjs +98 -0
- package/dist/components/TicketConversation/RewriteDropdown.js +93 -0
- package/dist/components/TicketConversation/SkeletonText.cjs +21 -0
- package/dist/components/TicketConversation/SkeletonText.js +20 -0
- package/dist/components/TicketConversation/constants.cjs +27 -0
- package/dist/components/TicketConversation/constants.js +26 -1
- package/dist/components/TicketConversation/hooks/useDocumentIdFromUrl.cjs +20 -0
- package/dist/components/TicketConversation/hooks/useDocumentIdFromUrl.js +19 -0
- package/dist/components/TicketConversation/index.cjs +10 -147
- package/dist/components/TicketConversation/index.js +4 -141
- package/dist/index.cjs +1763 -677
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1760 -677
- package/dist/views/BillingView/client.cjs +40 -54
- package/dist/views/BillingView/client.js +40 -54
- package/dist/views/ChatView/client.cjs +4 -3
- package/dist/views/ChatView/client.js +4 -3
- package/dist/views/CrmView/client.cjs +7 -7
- package/dist/views/CrmView/client.js +7 -7
- package/dist/views/EmailTrackingView/client.cjs +6 -5
- package/dist/views/EmailTrackingView/client.js +6 -5
- package/dist/views/ImportConversationView/client.cjs +4 -4
- package/dist/views/ImportConversationView/client.js +4 -4
- package/dist/views/LogsView/client.cjs +3 -2
- package/dist/views/LogsView/client.js +3 -2
- package/dist/views/NewTicketView/client.cjs +1 -1
- package/dist/views/NewTicketView/client.js +1 -1
- package/dist/views/PendingEmailsView/client.cjs +7 -6
- package/dist/views/PendingEmailsView/client.js +7 -6
- package/dist/views/SupportDashboardView/client.cjs +19 -22
- package/dist/views/SupportDashboardView/client.js +19 -22
- package/dist/views/TicketDetailView/NextActionItem.cjs +40 -0
- package/dist/views/TicketDetailView/NextActionItem.js +34 -0
- package/dist/views/TicketDetailView/RewriteDropdown.cjs +80 -0
- package/dist/views/TicketDetailView/RewriteDropdown.js +78 -0
- package/dist/views/TicketDetailView/client.cjs +59 -190
- package/dist/views/TicketDetailView/client.js +52 -183
- package/dist/views/TicketDetailView/constants.cjs +20 -0
- package/dist/views/TicketDetailView/constants.js +16 -0
- package/dist/views/TicketDetailView/helpers.cjs +23 -0
- package/dist/views/TicketDetailView/helpers.js +20 -0
- package/dist/views/TicketDetailView/types.cjs +2 -0
- package/dist/views/TicketDetailView/types.js +1 -0
- package/dist/views/TicketInboxView/client.cjs +14 -10
- package/dist/views/TicketInboxView/client.js +14 -10
- package/dist/views/TicketingSettingsView/client.cjs +101 -96
- package/dist/views/TicketingSettingsView/client.js +92 -88
- package/dist/views/TimeDashboardView/client.cjs +2 -2
- package/dist/views/TimeDashboardView/client.js +2 -2
- package/dist/views/shared/StatusPill.cjs +23 -12
- package/dist/views/shared/StatusPill.js +23 -12
- package/dist/views/shared/dateLocale.cjs +5 -0
- package/dist/views/shared/dateLocale.js +3 -0
- package/package.json +28 -15
- package/src/__tests__/generateTrackingToken.test.ts +53 -0
- package/src/__tests__/integration/ai-agent.test.ts +46 -0
- package/src/__tests__/integration/auth.test.ts +43 -0
- package/src/__tests__/integration/automation-rules.test.ts +68 -0
- package/src/__tests__/integration/buildTestPayload.ts +52 -0
- package/src/__tests__/integration/channels.test.ts +52 -0
- package/src/__tests__/integration/core-behaviors.test.ts +58 -0
- package/src/__tests__/integration/dashboard-volume.test.ts +31 -0
- package/src/__tests__/integration/digest.test.ts +48 -0
- package/src/__tests__/integration/invoice-pdf.test.ts +30 -0
- package/src/__tests__/integration/isolation.test.ts +81 -0
- package/src/__tests__/integration/mentions-invoice.test.ts +50 -0
- package/src/__tests__/integration/nps.test.ts +37 -0
- package/src/__tests__/integration/per-team-sla.test.ts +44 -0
- package/src/__tests__/integration/push.test.ts +75 -0
- package/src/__tests__/integration/sanitization.test.ts +35 -0
- package/src/__tests__/integration/sla-pause.test.ts +39 -0
- package/src/__tests__/integration/smoke.test.ts +26 -0
- package/src/__tests__/integration/snooze.test.ts +68 -0
- package/src/__tests__/integration/teams.test.ts +38 -0
- package/src/__tests__/rateLimiter.test.ts +89 -0
- package/src/__tests__/sanitizeHtml.test.ts +165 -0
- package/src/__tests__/sla.test.ts +258 -0
- package/src/collections/AutomationRules.ts +66 -0
- package/src/collections/NotificationQueue.ts +30 -0
- package/src/collections/PushSubscription.ts +28 -0
- package/src/collections/SatisfactionSurveys.ts +11 -2
- package/src/collections/SlaPolicies.ts +10 -0
- package/src/collections/SupportClients.ts +58 -1
- package/src/collections/SupportTeam.ts +27 -0
- package/src/collections/TicketActivityLog.ts +9 -4
- package/src/collections/TicketMessages.ts +140 -31
- package/src/collections/Tickets.ts +31 -73
- package/src/collections/index.ts +4 -0
- package/src/components/TicketConversation/RewriteDropdown.tsx +86 -0
- package/src/components/TicketConversation/SkeletonText.tsx +23 -0
- package/src/components/TicketConversation/constants.ts +29 -0
- package/src/components/TicketConversation/hooks/useDocumentIdFromUrl.ts +21 -0
- package/src/components/TicketConversation/index.tsx +4 -152
- package/src/endpoints/admin-chat-stream.ts +3 -4
- package/src/endpoints/admin-chat.ts +11 -20
- package/src/endpoints/admin-stats.ts +77 -35
- package/src/endpoints/ai-agent.ts +36 -0
- package/src/endpoints/apply-macro.ts +8 -14
- package/src/endpoints/auth-2fa.ts +12 -12
- package/src/endpoints/auto-close.ts +6 -10
- package/src/endpoints/billing.ts +17 -4
- package/src/endpoints/bulk-action.ts +7 -12
- package/src/endpoints/channels.ts +89 -0
- package/src/endpoints/chat-stream.ts +3 -4
- package/src/endpoints/chat.ts +7 -12
- package/src/endpoints/chatbot.ts +2 -2
- package/src/endpoints/client-intelligence.ts +4 -4
- package/src/endpoints/delete-account.ts +9 -16
- package/src/endpoints/email-stats.ts +2 -2
- package/src/endpoints/escalate.ts +2 -2
- package/src/endpoints/export-csv.ts +2 -2
- package/src/endpoints/export-data.ts +5 -8
- package/src/endpoints/import-conversation.ts +6 -10
- package/src/endpoints/index.ts +22 -1
- package/src/endpoints/invite-collaborator.ts +30 -15
- package/src/endpoints/invoice.ts +127 -0
- package/src/endpoints/kb-search.ts +2 -2
- package/src/endpoints/login.ts +12 -4
- package/src/endpoints/merge-clients.ts +14 -19
- package/src/endpoints/merge-tickets.ts +11 -18
- package/src/endpoints/oauth-google.ts +86 -39
- package/src/endpoints/pending-emails-process.ts +15 -25
- package/src/endpoints/process-digests.ts +93 -0
- package/src/endpoints/process-scheduled.ts +6 -10
- package/src/endpoints/process-snooze.ts +78 -0
- package/src/endpoints/purge-logs.ts +2 -2
- package/src/endpoints/push.ts +49 -0
- package/src/endpoints/resend-notification.ts +3 -4
- package/src/endpoints/round-robin-config.ts +3 -4
- package/src/endpoints/satisfaction.ts +21 -14
- package/src/endpoints/search.ts +5 -8
- package/src/endpoints/seed-kb.ts +3 -4
- package/src/endpoints/send-reminder.ts +6 -9
- package/src/endpoints/settings.ts +5 -2
- package/src/endpoints/signature.ts +3 -4
- package/src/endpoints/sla-check.ts +2 -2
- package/src/endpoints/split-ticket.ts +7 -12
- package/src/endpoints/statuses.ts +2 -2
- package/src/endpoints/ticket-feedback.ts +4 -6
- package/src/endpoints/ticket-synthesis.ts +2 -2
- package/src/endpoints/track-open.ts +16 -28
- package/src/endpoints/transfer-ticket.ts +21 -9
- package/src/endpoints/user-prefs.ts +3 -4
- package/src/hooks/automationRules.ts +84 -0
- package/src/hooks/checkSLA.ts +63 -17
- package/src/plugin.ts +8 -0
- package/src/portal/LiveChat.tsx +2 -63
- package/src/portal/auth/tickets/detail/CloseTicketButton.tsx +10 -0
- package/src/portal/auth/tickets/detail/MarkSolutionButton.tsx +14 -2
- package/src/portal/auth/tickets/detail/MessageActions.tsx +37 -18
- package/src/portal/auth/tickets/detail/ReopenTicketButton.tsx +10 -0
- package/src/portal/auth/tickets/detail/TransferAndInviteActions.tsx +3 -2
- package/src/portal/auth/tickets/detail/page.tsx +2 -2
- package/src/portal/helpers.ts +46 -0
- package/src/portal/login/page.tsx +3 -8
- package/src/portal/types.ts +15 -0
- package/src/types/lucide-react.d.ts +34 -0
- package/src/types/payload-config.d.ts +10 -0
- package/src/utils/adminNotification.ts +2 -2
- package/src/utils/aiAgent.ts +147 -0
- package/src/utils/auth.ts +5 -4
- package/src/utils/channels.ts +36 -0
- package/src/utils/db.ts +73 -0
- package/src/utils/emailTemplate.ts +8 -1
- package/src/utils/fireWebhooks.ts +4 -6
- package/src/utils/generateTicketSynthesis.ts +7 -12
- package/src/utils/invoicePdf.ts +88 -0
- package/src/utils/notificationQueue.ts +36 -0
- package/src/utils/push.ts +63 -0
- package/src/utils/readSettings.ts +22 -6
- package/src/utils/sanitizeHtml.ts +57 -0
- package/src/utils/slugs.ts +8 -0
- package/src/utils/teamAccess.ts +27 -0
- package/src/utils/ticketAccess.ts +53 -0
- package/src/utils/webhookDispatcher.ts +4 -6
- package/src/views/BillingView/client.tsx +49 -37
- package/src/views/ChatView/client.tsx +4 -3
- package/src/views/CrmView/client.tsx +7 -7
- package/src/views/EmailTrackingView/client.tsx +7 -6
- package/src/views/ImportConversationView/client.tsx +4 -4
- package/src/views/LogsView/client.tsx +3 -2
- package/src/views/NewTicketView/client.tsx +1 -1
- package/src/views/PendingEmailsView/client.tsx +7 -6
- package/src/views/SupportDashboardView/client.tsx +21 -21
- package/src/views/TicketDetailView/NextActionItem.tsx +30 -0
- package/src/views/TicketDetailView/RewriteDropdown.tsx +63 -0
- package/src/views/TicketDetailView/client.tsx +54 -179
- package/src/views/TicketDetailView/constants.ts +23 -0
- package/src/views/TicketDetailView/helpers.ts +17 -0
- package/src/views/TicketDetailView/types.ts +10 -0
- package/src/views/TicketInboxView/client.tsx +16 -10
- package/src/views/TicketingSettingsView/client.tsx +90 -87
- package/src/views/TimeDashboardView/client.tsx +2 -2
- package/src/views/shared/StatusPill.tsx +24 -12
- package/src/views/shared/dateLocale.ts +5 -0
- package/src/views/shared/locales/en.json +708 -0
- package/src/views/shared/locales/fr.json +708 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React, { useState } from 'react'
|
|
4
|
+
import { REWRITE_STYLES, s } from './constants'
|
|
5
|
+
|
|
6
|
+
export const RewriteDropdown: React.FC<{
|
|
7
|
+
disabled: boolean
|
|
8
|
+
loading: boolean
|
|
9
|
+
onSelect: (style: string) => void
|
|
10
|
+
}> = ({ disabled, loading, onSelect }) => {
|
|
11
|
+
const [open, setOpen] = useState(false)
|
|
12
|
+
const ref = React.useRef<HTMLDivElement>(null)
|
|
13
|
+
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
if (!open) return
|
|
16
|
+
const close = (e: MouseEvent) => {
|
|
17
|
+
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false)
|
|
18
|
+
}
|
|
19
|
+
document.addEventListener('mousedown', close)
|
|
20
|
+
return () => document.removeEventListener('mousedown', close)
|
|
21
|
+
}, [open])
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div ref={ref} style={{ position: 'relative', display: 'inline-block' }}>
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
onClick={() => setOpen(!open)}
|
|
28
|
+
disabled={disabled}
|
|
29
|
+
style={{
|
|
30
|
+
...s.outlineBtn('#0891b2', disabled),
|
|
31
|
+
fontSize: '11px',
|
|
32
|
+
padding: '3px 10px',
|
|
33
|
+
borderRadius: '14px',
|
|
34
|
+
display: 'flex',
|
|
35
|
+
alignItems: 'center',
|
|
36
|
+
gap: '4px',
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
{loading ? 'Reformulation...' : '✏️ Reformuler'}
|
|
40
|
+
{!loading && <span style={{ fontSize: 9, opacity: 0.7 }}>▼</span>}
|
|
41
|
+
</button>
|
|
42
|
+
{open && !disabled && !loading && (
|
|
43
|
+
<div
|
|
44
|
+
style={{
|
|
45
|
+
position: 'absolute',
|
|
46
|
+
bottom: '100%',
|
|
47
|
+
left: 0,
|
|
48
|
+
marginBottom: 4,
|
|
49
|
+
background: 'var(--theme-elevation-0, #fff)',
|
|
50
|
+
border: '1px solid var(--theme-elevation-200, #e5e7eb)',
|
|
51
|
+
borderRadius: 8,
|
|
52
|
+
boxShadow: '0 4px 16px rgba(0,0,0,0.12)',
|
|
53
|
+
zIndex: 100,
|
|
54
|
+
minWidth: 180,
|
|
55
|
+
overflow: 'hidden',
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
{REWRITE_STYLES.map((style) => (
|
|
59
|
+
<button
|
|
60
|
+
key={style.id}
|
|
61
|
+
type="button"
|
|
62
|
+
onClick={() => { setOpen(false); onSelect(style.id) }}
|
|
63
|
+
style={{
|
|
64
|
+
display: 'flex',
|
|
65
|
+
flexDirection: 'column',
|
|
66
|
+
width: '100%',
|
|
67
|
+
padding: '8px 12px',
|
|
68
|
+
border: 'none',
|
|
69
|
+
background: 'transparent',
|
|
70
|
+
cursor: 'pointer',
|
|
71
|
+
textAlign: 'left',
|
|
72
|
+
borderBottom: '1px solid var(--theme-elevation-100, #f3f4f6)',
|
|
73
|
+
transition: 'background 120ms',
|
|
74
|
+
}}
|
|
75
|
+
onMouseEnter={(e) => { (e.target as HTMLElement).style.background = 'var(--theme-elevation-50, #f9fafb)' }}
|
|
76
|
+
onMouseLeave={(e) => { (e.target as HTMLElement).style.background = 'transparent' }}
|
|
77
|
+
>
|
|
78
|
+
<span style={{ fontSize: 12, fontWeight: 600, color: 'var(--theme-text, #111)' }}>{style.label}</span>
|
|
79
|
+
<span style={{ fontSize: 10, color: 'var(--theme-elevation-500, #6b7280)' }}>{style.desc}</span>
|
|
80
|
+
</button>
|
|
81
|
+
))}
|
|
82
|
+
</div>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
// Inline skeleton replacement (no external dependency)
|
|
6
|
+
export function SkeletonText({ lines = 3 }: { lines?: number }) {
|
|
7
|
+
return (
|
|
8
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px', padding: '12px 0' }}>
|
|
9
|
+
{Array.from({ length: lines }).map((_, i) => (
|
|
10
|
+
<div
|
|
11
|
+
key={i}
|
|
12
|
+
style={{
|
|
13
|
+
height: '14px',
|
|
14
|
+
borderRadius: '4px',
|
|
15
|
+
backgroundColor: '#e2e8f0',
|
|
16
|
+
width: i === lines - 1 ? '60%' : '100%',
|
|
17
|
+
animation: 'pulse 1.5s ease-in-out infinite',
|
|
18
|
+
}}
|
|
19
|
+
/>
|
|
20
|
+
))}
|
|
21
|
+
</div>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import type React from 'react'
|
|
2
2
|
|
|
3
|
+
// ── Rewrite style dropdown options ──────────────────────────────────────
|
|
4
|
+
export const REWRITE_STYLES = [
|
|
5
|
+
{ id: 'auto', label: '✏️ Auto', desc: 'Garde le ton actuel' },
|
|
6
|
+
{ id: 'tutoyer', label: '👋 Tutoyer', desc: 'Passe en tu' },
|
|
7
|
+
{ id: 'vouvoyer', label: '🎩 Vouvoyer', desc: 'Passe en vous' },
|
|
8
|
+
{ id: 'formel', label: '💼 Formel', desc: 'Ton professionnel' },
|
|
9
|
+
{ id: 'amical', label: '😊 Amical', desc: 'Ton chaleureux' },
|
|
10
|
+
{ id: 'court', label: '⚡ Court', desc: 'Version concise' },
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
// Inline layout styles
|
|
14
|
+
export const layoutStyles = {
|
|
15
|
+
root: { padding: '12px 0' } as React.CSSProperties,
|
|
16
|
+
twoColumns: {
|
|
17
|
+
display: 'grid',
|
|
18
|
+
gridTemplateColumns: '1fr 320px',
|
|
19
|
+
gap: '16px',
|
|
20
|
+
alignItems: 'start',
|
|
21
|
+
} as React.CSSProperties,
|
|
22
|
+
mainColumn: { minWidth: 0 } as React.CSSProperties,
|
|
23
|
+
sideColumn: {
|
|
24
|
+
display: 'flex',
|
|
25
|
+
flexDirection: 'column' as const,
|
|
26
|
+
gap: '12px',
|
|
27
|
+
position: 'sticky' as const,
|
|
28
|
+
top: '80px',
|
|
29
|
+
} as React.CSSProperties,
|
|
30
|
+
}
|
|
31
|
+
|
|
3
32
|
export const statusLabels: Record<string, { label: string; bg: string; color: string }> = {
|
|
4
33
|
open: { label: 'Ouvert', bg: '#dbeafe', color: '#1e40af' },
|
|
5
34
|
waiting_client: { label: 'Attente', bg: '#fef3c7', color: '#92400e' },
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
|
|
3
|
+
// Replacement for @payloadcms/ui's useDocumentInfo — avoids importing
|
|
4
|
+
// @payloadcms/ui (which has chunk splits that break webpack resolution
|
|
5
|
+
// when this bundle is consumed from node_modules).
|
|
6
|
+
// Extracts the document id from the admin URL pattern:
|
|
7
|
+
// /admin/collections/:slug/:id or /admin/globals/:slug
|
|
8
|
+
export function useDocumentIdFromUrl(): { id: string | number | undefined } {
|
|
9
|
+
const [id, setId] = useState<string | number | undefined>(undefined)
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const match = window.location.pathname.match(
|
|
12
|
+
/\/admin\/collections\/[^/]+\/([^/?#]+)/
|
|
13
|
+
)
|
|
14
|
+
if (match && match[1] !== 'create') {
|
|
15
|
+
const raw = match[1]
|
|
16
|
+
const num = Number(raw)
|
|
17
|
+
setId(Number.isFinite(num) && String(num) === raw ? num : raw)
|
|
18
|
+
}
|
|
19
|
+
}, [])
|
|
20
|
+
return { id }
|
|
21
|
+
}
|
|
@@ -1,29 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import React, { useState, useEffect, useCallback, useRef } from 'react'
|
|
4
|
-
|
|
5
|
-
// Replacement for @payloadcms/ui's useDocumentInfo — avoids importing
|
|
6
|
-
// @payloadcms/ui (which has chunk splits that break webpack resolution
|
|
7
|
-
// when this bundle is consumed from node_modules).
|
|
8
|
-
// Extracts the document id from the admin URL pattern:
|
|
9
|
-
// /admin/collections/:slug/:id or /admin/globals/:slug
|
|
10
|
-
function useDocumentIdFromUrl(): { id: string | number | undefined } {
|
|
11
|
-
const [id, setId] = useState<string | number | undefined>(undefined)
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const match = window.location.pathname.match(
|
|
14
|
-
/\/admin\/collections\/[^/]+\/([^/?#]+)/
|
|
15
|
-
)
|
|
16
|
-
if (match && match[1] !== 'create') {
|
|
17
|
-
const raw = match[1]
|
|
18
|
-
const num = Number(raw)
|
|
19
|
-
setId(Number.isFinite(num) && String(num) === raw ? num : raw)
|
|
20
|
-
}
|
|
21
|
-
}, [])
|
|
22
|
-
return { id }
|
|
23
|
-
}
|
|
24
4
|
import type { Message, TimeEntry, ClientInfo, CannedResponse, ActivityEntry, SatisfactionSurvey } from './types'
|
|
25
5
|
import type { RichTextEditorHandle } from './context'
|
|
26
|
-
import { C, s } from './constants'
|
|
6
|
+
import { C, s, layoutStyles } from './constants'
|
|
27
7
|
import { getDateLabel, formatMessageDate } from './utils'
|
|
28
8
|
import { CodeBlockRenderer, CodeBlockRendererHtml } from './components/CodeBlock'
|
|
29
9
|
import { CodeBlockInserter } from './components/CodeBlockInserter'
|
|
@@ -40,140 +20,12 @@ import { useMessageActions } from './hooks/useMessageActions'
|
|
|
40
20
|
import { useTicketActions } from './hooks/useTicketActions'
|
|
41
21
|
import { useReply } from './hooks/useReply'
|
|
42
22
|
import { useAI } from './hooks/useAI'
|
|
23
|
+
import { useDocumentIdFromUrl } from './hooks/useDocumentIdFromUrl'
|
|
43
24
|
import { getFeatures, type TicketingFeatures } from './config'
|
|
25
|
+
import { SkeletonText } from './SkeletonText'
|
|
26
|
+
import { RewriteDropdown } from './RewriteDropdown'
|
|
44
27
|
import '../../styles/theme.css'
|
|
45
28
|
|
|
46
|
-
// Inline skeleton replacement (no external dependency)
|
|
47
|
-
function SkeletonText({ lines = 3 }: { lines?: number }) {
|
|
48
|
-
return (
|
|
49
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px', padding: '12px 0' }}>
|
|
50
|
-
{Array.from({ length: lines }).map((_, i) => (
|
|
51
|
-
<div
|
|
52
|
-
key={i}
|
|
53
|
-
style={{
|
|
54
|
-
height: '14px',
|
|
55
|
-
borderRadius: '4px',
|
|
56
|
-
backgroundColor: '#e2e8f0',
|
|
57
|
-
width: i === lines - 1 ? '60%' : '100%',
|
|
58
|
-
animation: 'pulse 1.5s ease-in-out infinite',
|
|
59
|
-
}}
|
|
60
|
-
/>
|
|
61
|
-
))}
|
|
62
|
-
</div>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Inline layout styles (replacing Layout.module.scss)
|
|
67
|
-
const layoutStyles = {
|
|
68
|
-
root: { padding: '12px 0' } as React.CSSProperties,
|
|
69
|
-
twoColumns: {
|
|
70
|
-
display: 'grid',
|
|
71
|
-
gridTemplateColumns: '1fr 320px',
|
|
72
|
-
gap: '16px',
|
|
73
|
-
alignItems: 'start',
|
|
74
|
-
} as React.CSSProperties,
|
|
75
|
-
mainColumn: { minWidth: 0 } as React.CSSProperties,
|
|
76
|
-
sideColumn: {
|
|
77
|
-
display: 'flex',
|
|
78
|
-
flexDirection: 'column' as const,
|
|
79
|
-
gap: '12px',
|
|
80
|
-
position: 'sticky' as const,
|
|
81
|
-
top: '80px',
|
|
82
|
-
} as React.CSSProperties,
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// ── Rewrite style dropdown ──────────────────────────────────────────────
|
|
86
|
-
const REWRITE_STYLES = [
|
|
87
|
-
{ id: 'auto', label: '✏️ Auto', desc: 'Garde le ton actuel' },
|
|
88
|
-
{ id: 'tutoyer', label: '👋 Tutoyer', desc: 'Passe en tu' },
|
|
89
|
-
{ id: 'vouvoyer', label: '🎩 Vouvoyer', desc: 'Passe en vous' },
|
|
90
|
-
{ id: 'formel', label: '💼 Formel', desc: 'Ton professionnel' },
|
|
91
|
-
{ id: 'amical', label: '😊 Amical', desc: 'Ton chaleureux' },
|
|
92
|
-
{ id: 'court', label: '⚡ Court', desc: 'Version concise' },
|
|
93
|
-
]
|
|
94
|
-
|
|
95
|
-
const RewriteDropdown: React.FC<{
|
|
96
|
-
disabled: boolean
|
|
97
|
-
loading: boolean
|
|
98
|
-
onSelect: (style: string) => void
|
|
99
|
-
}> = ({ disabled, loading, onSelect }) => {
|
|
100
|
-
const [open, setOpen] = useState(false)
|
|
101
|
-
const ref = React.useRef<HTMLDivElement>(null)
|
|
102
|
-
|
|
103
|
-
React.useEffect(() => {
|
|
104
|
-
if (!open) return
|
|
105
|
-
const close = (e: MouseEvent) => {
|
|
106
|
-
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false)
|
|
107
|
-
}
|
|
108
|
-
document.addEventListener('mousedown', close)
|
|
109
|
-
return () => document.removeEventListener('mousedown', close)
|
|
110
|
-
}, [open])
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<div ref={ref} style={{ position: 'relative', display: 'inline-block' }}>
|
|
114
|
-
<button
|
|
115
|
-
type="button"
|
|
116
|
-
onClick={() => setOpen(!open)}
|
|
117
|
-
disabled={disabled}
|
|
118
|
-
style={{
|
|
119
|
-
...s.outlineBtn('#0891b2', disabled),
|
|
120
|
-
fontSize: '11px',
|
|
121
|
-
padding: '3px 10px',
|
|
122
|
-
borderRadius: '14px',
|
|
123
|
-
display: 'flex',
|
|
124
|
-
alignItems: 'center',
|
|
125
|
-
gap: '4px',
|
|
126
|
-
}}
|
|
127
|
-
>
|
|
128
|
-
{loading ? 'Reformulation...' : '✏️ Reformuler'}
|
|
129
|
-
{!loading && <span style={{ fontSize: 9, opacity: 0.7 }}>▼</span>}
|
|
130
|
-
</button>
|
|
131
|
-
{open && !disabled && !loading && (
|
|
132
|
-
<div
|
|
133
|
-
style={{
|
|
134
|
-
position: 'absolute',
|
|
135
|
-
bottom: '100%',
|
|
136
|
-
left: 0,
|
|
137
|
-
marginBottom: 4,
|
|
138
|
-
background: 'var(--theme-elevation-0, #fff)',
|
|
139
|
-
border: '1px solid var(--theme-elevation-200, #e5e7eb)',
|
|
140
|
-
borderRadius: 8,
|
|
141
|
-
boxShadow: '0 4px 16px rgba(0,0,0,0.12)',
|
|
142
|
-
zIndex: 100,
|
|
143
|
-
minWidth: 180,
|
|
144
|
-
overflow: 'hidden',
|
|
145
|
-
}}
|
|
146
|
-
>
|
|
147
|
-
{REWRITE_STYLES.map((style) => (
|
|
148
|
-
<button
|
|
149
|
-
key={style.id}
|
|
150
|
-
type="button"
|
|
151
|
-
onClick={() => { setOpen(false); onSelect(style.id) }}
|
|
152
|
-
style={{
|
|
153
|
-
display: 'flex',
|
|
154
|
-
flexDirection: 'column',
|
|
155
|
-
width: '100%',
|
|
156
|
-
padding: '8px 12px',
|
|
157
|
-
border: 'none',
|
|
158
|
-
background: 'transparent',
|
|
159
|
-
cursor: 'pointer',
|
|
160
|
-
textAlign: 'left',
|
|
161
|
-
borderBottom: '1px solid var(--theme-elevation-100, #f3f4f6)',
|
|
162
|
-
transition: 'background 120ms',
|
|
163
|
-
}}
|
|
164
|
-
onMouseEnter={(e) => { (e.target as HTMLElement).style.background = 'var(--theme-elevation-50, #f9fafb)' }}
|
|
165
|
-
onMouseLeave={(e) => { (e.target as HTMLElement).style.background = 'transparent' }}
|
|
166
|
-
>
|
|
167
|
-
<span style={{ fontSize: 12, fontWeight: 600, color: 'var(--theme-text, #111)' }}>{style.label}</span>
|
|
168
|
-
<span style={{ fontSize: 10, color: 'var(--theme-elevation-500, #6b7280)' }}>{style.desc}</span>
|
|
169
|
-
</button>
|
|
170
|
-
))}
|
|
171
|
-
</div>
|
|
172
|
-
)}
|
|
173
|
-
</div>
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
29
|
const TicketConversation: React.FC = () => {
|
|
178
30
|
const { id } = useDocumentIdFromUrl()
|
|
179
31
|
const [features] = useState<TicketingFeatures>(() => getFeatures())
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Endpoint } from 'payload'
|
|
2
2
|
import type { CollectionSlugs } from '../utils/slugs'
|
|
3
3
|
import { requireAdmin, handleAuthError } from '../utils/auth'
|
|
4
|
+
import { dbFind } from '../utils/db'
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* GET /api/support/admin-chat-stream?session=xxx
|
|
@@ -58,8 +59,7 @@ function createSessionStream(
|
|
|
58
59
|
// Poll DB every 2 seconds for new messages in this session
|
|
59
60
|
const interval = setInterval(async () => {
|
|
60
61
|
try {
|
|
61
|
-
const messages = await req.payload.
|
|
62
|
-
collection: slugs.chatMessages as any,
|
|
62
|
+
const messages = await dbFind(req.payload, slugs.chatMessages, {
|
|
63
63
|
where: {
|
|
64
64
|
session: { equals: sessionId },
|
|
65
65
|
createdAt: { greater_than: lastCheck },
|
|
@@ -140,8 +140,7 @@ function createSessionListStream(req: any, slugs: CollectionSlugs): Response {
|
|
|
140
140
|
|
|
141
141
|
const interval = setInterval(async () => {
|
|
142
142
|
try {
|
|
143
|
-
const recentMessages = await req.payload.
|
|
144
|
-
collection: slugs.chatMessages as any,
|
|
143
|
+
const recentMessages = await dbFind(req.payload, slugs.chatMessages, {
|
|
145
144
|
sort: '-createdAt',
|
|
146
145
|
limit: 50,
|
|
147
146
|
depth: 1,
|
|
@@ -3,6 +3,7 @@ import type { Where } from 'payload'
|
|
|
3
3
|
import type { CollectionSlugs } from '../utils/slugs'
|
|
4
4
|
import { RateLimiter } from '../utils/rateLimiter'
|
|
5
5
|
import { requireAdmin, handleAuthError } from '../utils/auth'
|
|
6
|
+
import { dbFind, dbCreate, dbUpdate } from '../utils/db'
|
|
6
7
|
|
|
7
8
|
const adminChatLimiter = new RateLimiter(60_000, 30) // 30 per minute
|
|
8
9
|
|
|
@@ -28,8 +29,7 @@ export function createAdminChatGetEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
28
29
|
const where: Where = { session: { equals: session } }
|
|
29
30
|
if (after) where.createdAt = { greater_than: after }
|
|
30
31
|
|
|
31
|
-
const messages = await payload.
|
|
32
|
-
collection: slugs.chatMessages as any,
|
|
32
|
+
const messages = await dbFind(payload, slugs.chatMessages, {
|
|
33
33
|
where,
|
|
34
34
|
sort: 'createdAt',
|
|
35
35
|
limit: 200,
|
|
@@ -46,8 +46,7 @@ export function createAdminChatGetEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// List recent sessions: fetch only recent messages, limit to 50
|
|
49
|
-
const recentMessages = await payload.
|
|
50
|
-
collection: slugs.chatMessages as any,
|
|
49
|
+
const recentMessages = await dbFind(payload, slugs.chatMessages, {
|
|
51
50
|
sort: '-createdAt',
|
|
52
51
|
limit: 50,
|
|
53
52
|
depth: 1,
|
|
@@ -134,8 +133,7 @@ export function createAdminChatPostEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
134
133
|
return Response.json({ error: 'Session requise' }, { status: 400 })
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
const sessionMsg = await payload.
|
|
138
|
-
collection: slugs.chatMessages as any,
|
|
136
|
+
const sessionMsg = await dbFind(payload, slugs.chatMessages, {
|
|
139
137
|
where: { session: { equals: session } },
|
|
140
138
|
limit: 1,
|
|
141
139
|
depth: 0,
|
|
@@ -161,8 +159,7 @@ export function createAdminChatPostEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
161
159
|
return Response.json({ error: 'Message invalide (1-2000 caractères).' }, { status: 400 })
|
|
162
160
|
}
|
|
163
161
|
|
|
164
|
-
const newMsg = await payload.
|
|
165
|
-
collection: slugs.chatMessages as any,
|
|
162
|
+
const newMsg = await dbCreate(payload, slugs.chatMessages, {
|
|
166
163
|
data: {
|
|
167
164
|
session,
|
|
168
165
|
client: clientId,
|
|
@@ -176,8 +173,7 @@ export function createAdminChatPostEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
176
173
|
|
|
177
174
|
// Try to link to ticket
|
|
178
175
|
try {
|
|
179
|
-
const linkedTicket = await payload.
|
|
180
|
-
collection: slugs.tickets as any,
|
|
176
|
+
const linkedTicket = await dbFind(payload, slugs.tickets, {
|
|
181
177
|
where: { chatSession: { equals: session } },
|
|
182
178
|
limit: 1,
|
|
183
179
|
depth: 0,
|
|
@@ -185,8 +181,7 @@ export function createAdminChatPostEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
185
181
|
})
|
|
186
182
|
if (linkedTicket.docs.length > 0) {
|
|
187
183
|
const ticketId = linkedTicket.docs[0].id
|
|
188
|
-
await payload.
|
|
189
|
-
collection: slugs.ticketMessages as any,
|
|
184
|
+
await dbCreate(payload, slugs.ticketMessages, {
|
|
190
185
|
data: {
|
|
191
186
|
ticket: ticketId,
|
|
192
187
|
body: trimmedMessage,
|
|
@@ -195,8 +190,7 @@ export function createAdminChatPostEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
195
190
|
},
|
|
196
191
|
overrideAccess: true,
|
|
197
192
|
})
|
|
198
|
-
await payload.
|
|
199
|
-
collection: slugs.chatMessages as any,
|
|
193
|
+
await dbUpdate(payload, slugs.chatMessages, {
|
|
200
194
|
id: newMsg.id,
|
|
201
195
|
data: { ticket: ticketId },
|
|
202
196
|
overrideAccess: true,
|
|
@@ -211,8 +205,7 @@ export function createAdminChatPostEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
211
205
|
|
|
212
206
|
// Admin closes session
|
|
213
207
|
if (action === 'close') {
|
|
214
|
-
await payload.
|
|
215
|
-
collection: slugs.chatMessages as any,
|
|
208
|
+
await dbCreate(payload, slugs.chatMessages, {
|
|
216
209
|
data: {
|
|
217
210
|
session,
|
|
218
211
|
client: clientId,
|
|
@@ -224,16 +217,14 @@ export function createAdminChatPostEndpoint(slugs: CollectionSlugs): Endpoint {
|
|
|
224
217
|
})
|
|
225
218
|
|
|
226
219
|
try {
|
|
227
|
-
const linkedTicket = await payload.
|
|
228
|
-
collection: slugs.tickets as any,
|
|
220
|
+
const linkedTicket = await dbFind(payload, slugs.tickets, {
|
|
229
221
|
where: { chatSession: { equals: session } },
|
|
230
222
|
limit: 1,
|
|
231
223
|
depth: 0,
|
|
232
224
|
overrideAccess: true,
|
|
233
225
|
})
|
|
234
226
|
if (linkedTicket.docs.length > 0) {
|
|
235
|
-
await payload.
|
|
236
|
-
collection: slugs.ticketMessages as any,
|
|
227
|
+
await dbCreate(payload, slugs.ticketMessages, {
|
|
237
228
|
data: {
|
|
238
229
|
ticket: linkedTicket.docs[0].id,
|
|
239
230
|
body: 'Session de chat terminée par un agent.',
|