@escalated-dev/escalated 0.7.0 → 0.8.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.
Files changed (181) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +36 -1
  3. package/package.json +16 -7
  4. package/src/components/ActiveChatsPanel.vue +246 -0
  5. package/src/components/ActivityTimeline.stories.js +55 -55
  6. package/src/components/ActivityTimeline.vue +83 -83
  7. package/src/components/AdminDashboard.stories.js +1423 -1095
  8. package/src/components/AgentLoadIndicator.stories.js +37 -37
  9. package/src/components/AgentLoadIndicator.vue +49 -49
  10. package/src/components/AgentPerformanceCard.vue +44 -44
  11. package/src/components/ArticleEditor.vue +82 -82
  12. package/src/components/AssigneeSelect.vue +37 -37
  13. package/src/components/AttachmentList.vue +13 -1
  14. package/src/components/AuditLogEntry.vue +95 -95
  15. package/src/components/BulkActionBar.vue +166 -166
  16. package/src/components/CategoryTree.vue +89 -89
  17. package/src/components/ChartWidget.vue +46 -46
  18. package/src/components/ChatActionBar.vue +226 -0
  19. package/src/components/ChatBubble.vue +162 -0
  20. package/src/components/ChatComposer.vue +308 -0
  21. package/src/components/ChatQueue.vue +222 -0
  22. package/src/components/ChatThread.vue +197 -0
  23. package/src/components/CollisionWarning.stories.js +30 -30
  24. package/src/components/CollisionWarning.vue +68 -68
  25. package/src/components/ConditionalFieldRules.vue +135 -135
  26. package/src/components/ContextPanel.vue +66 -66
  27. package/src/components/ContextPanelSection.vue +65 -65
  28. package/src/components/CustomFieldRenderer.vue +159 -159
  29. package/src/components/EscalatedLayout.vue +35 -6
  30. package/src/components/FileDropzone.vue +57 -57
  31. package/src/components/FollowButton.stories.js +30 -30
  32. package/src/components/FollowButton.vue +88 -88
  33. package/src/components/KeyboardShortcutHelp.vue +213 -213
  34. package/src/components/KnowledgePanel.vue +122 -122
  35. package/src/components/KpiCard.stories.js +32 -32
  36. package/src/components/KpiCard.vue +88 -88
  37. package/src/components/MacroDropdown.vue +150 -150
  38. package/src/components/MentionDropdown.vue +154 -0
  39. package/src/components/MetricComparison.vue +89 -0
  40. package/src/components/PercentileChart.vue +67 -0
  41. package/src/components/PeriodSelector.vue +98 -0
  42. package/src/components/PermissionMatrix.vue +107 -107
  43. package/src/components/PinnedNotes.vue +129 -129
  44. package/src/components/PluginSlot.vue +68 -62
  45. package/src/components/PresenceIndicator.vue +46 -2
  46. package/src/components/PriorityBadge.stories.js +33 -33
  47. package/src/components/PriorityBadge.vue +46 -46
  48. package/src/components/ReplyComposer.vue +81 -18
  49. package/src/components/ReplyThread.vue +40 -2
  50. package/src/components/ReportChart.vue +395 -0
  51. package/src/components/ReportExportButton.vue +108 -0
  52. package/src/components/SatisfactionRating.vue +180 -180
  53. package/src/components/SaveViewDialog.vue +172 -0
  54. package/src/components/SavedViewSidebar.vue +208 -0
  55. package/src/components/ScheduleEditor.vue +104 -104
  56. package/src/components/SideConversation.vue +165 -165
  57. package/src/components/SideConversationList.vue +147 -147
  58. package/src/components/SkillTagManager.vue +83 -79
  59. package/src/components/SlaComplianceChart.vue +46 -53
  60. package/src/components/SlaTimer.stories.js +35 -35
  61. package/src/components/SlaTimer.vue +62 -62
  62. package/src/components/SnoozeButton.vue +247 -0
  63. package/src/components/StatsCard.stories.js +24 -24
  64. package/src/components/StatsCard.vue +58 -58
  65. package/src/components/StatusBadge.stories.js +53 -53
  66. package/src/components/StatusBadge.vue +78 -78
  67. package/src/components/TagSelect.vue +84 -84
  68. package/src/components/TicketFilters.vue +270 -225
  69. package/src/components/TicketLinkPanel.vue +193 -193
  70. package/src/components/TicketList.vue +655 -594
  71. package/src/components/TicketMergeDialog.vue +157 -157
  72. package/src/components/TicketSplitDialog.vue +98 -0
  73. package/src/components/TotpInput.stories.js +9 -9
  74. package/src/components/TotpInput.vue +81 -81
  75. package/src/components/TwoFactorSetup.vue +113 -113
  76. package/src/components/VariableTokenInput.vue +111 -0
  77. package/src/components/WorkflowActionConfig.vue +287 -0
  78. package/src/components/WorkflowActionList.vue +350 -0
  79. package/src/components/WorkflowConditionBuilder.vue +265 -0
  80. package/src/components/WorkflowTriggerSelector.vue +125 -0
  81. package/src/composables/useChat.js +187 -0
  82. package/src/composables/useI18n.js +30 -8
  83. package/src/composables/useKeyboardShortcuts.js +46 -46
  84. package/src/composables/useMentions.js +134 -0
  85. package/src/composables/usePluginExtensions.js +159 -159
  86. package/src/composables/usePluginHooks.js +65 -65
  87. package/src/composables/useRealtime.js +182 -0
  88. package/src/defineEscalatedPlugin.js +76 -76
  89. package/src/index.js +84 -72
  90. package/src/locales/README.md +13 -0
  91. package/src/locales/ar.json +727 -0
  92. package/src/locales/de.json +678 -430
  93. package/src/locales/en.json +717 -455
  94. package/src/locales/es.json +679 -430
  95. package/src/locales/fr.json +680 -431
  96. package/src/locales/index.js +12 -2
  97. package/src/locales/it.json +727 -0
  98. package/src/locales/ja.json +727 -0
  99. package/src/locales/ko.json +727 -0
  100. package/src/locales/nl.json +727 -0
  101. package/src/locales/pl.json +727 -0
  102. package/src/locales/pt-BR.json +727 -0
  103. package/src/locales/ru.json +727 -0
  104. package/src/locales/tr.json +727 -0
  105. package/src/locales/zh-CN.json +727 -0
  106. package/src/pages/Admin/ApiTokens/Index.vue +381 -381
  107. package/src/pages/Admin/AuditLog/Index.vue +154 -154
  108. package/src/pages/Admin/BusinessHours/Form.vue +172 -172
  109. package/src/pages/Admin/BusinessHours/Index.vue +113 -113
  110. package/src/pages/Admin/CannedResponses/Index.vue +127 -127
  111. package/src/pages/Admin/Capacity/Index.vue +134 -134
  112. package/src/pages/Admin/CustomFields/Form.vue +195 -195
  113. package/src/pages/Admin/CustomFields/Index.vue +134 -134
  114. package/src/pages/Admin/CustomObjects/Form.vue +202 -202
  115. package/src/pages/Admin/CustomObjects/Index.vue +127 -127
  116. package/src/pages/Admin/CustomObjects/Records.vue +228 -228
  117. package/src/pages/Admin/Departments/Form.vue +75 -75
  118. package/src/pages/Admin/Departments/Index.vue +110 -109
  119. package/src/pages/Admin/EscalationRules/Form.vue +157 -157
  120. package/src/pages/Admin/EscalationRules/Index.vue +178 -178
  121. package/src/pages/Admin/Import/Connect.vue +0 -1
  122. package/src/pages/Admin/Import/Index.vue +1 -1
  123. package/src/pages/Admin/Import/Progress.vue +1 -1
  124. package/src/pages/Admin/KnowledgeBase/Articles/Form.vue +142 -142
  125. package/src/pages/Admin/KnowledgeBase/Articles/Index.vue +195 -195
  126. package/src/pages/Admin/KnowledgeBase/Categories/Index.vue +193 -193
  127. package/src/pages/Admin/Macros/Index.vue +448 -448
  128. package/src/pages/Admin/Plugins/Index.vue +327 -327
  129. package/src/pages/Admin/Reports/AgentDetail.vue +132 -0
  130. package/src/pages/Admin/Reports/AgentMetrics.vue +115 -115
  131. package/src/pages/Admin/Reports/AgentRanking.vue +246 -0
  132. package/src/pages/Admin/Reports/Cohorts.vue +180 -0
  133. package/src/pages/Admin/Reports/Comparison.vue +141 -0
  134. package/src/pages/Admin/Reports/CsatReport.vue +127 -127
  135. package/src/pages/Admin/Reports/Dashboard.vue +36 -21
  136. package/src/pages/Admin/Reports/ResolutionTimes.vue +164 -0
  137. package/src/pages/Admin/Reports/ResponseTimes.vue +164 -0
  138. package/src/pages/Admin/Reports/SlaReport.vue +162 -166
  139. package/src/pages/Admin/Reports/SlaTrends.vue +183 -0
  140. package/src/pages/Admin/Reports.vue +206 -206
  141. package/src/pages/Admin/Roles/Form.vue +71 -71
  142. package/src/pages/Admin/Roles/Index.vue +122 -122
  143. package/src/pages/Admin/Settings/CsatSettings.vue +165 -165
  144. package/src/pages/Admin/Settings/DataRetention.vue +182 -182
  145. package/src/pages/Admin/Settings/EmailSettings.vue +243 -243
  146. package/src/pages/Admin/Settings/Sandbox.vue +135 -135
  147. package/src/pages/Admin/Settings/SsoSettings.vue +218 -218
  148. package/src/pages/Admin/Settings/TwoFactor.vue +110 -110
  149. package/src/pages/Admin/Settings.vue +1008 -468
  150. package/src/pages/Admin/Skills/Form.vue +193 -53
  151. package/src/pages/Admin/Skills/Index.vue +105 -94
  152. package/src/pages/Admin/SlaPolicies/Form.vue +118 -118
  153. package/src/pages/Admin/SlaPolicies/Index.vue +121 -120
  154. package/src/pages/Admin/Statuses/Form.vue +114 -114
  155. package/src/pages/Admin/Statuses/Index.vue +153 -153
  156. package/src/pages/Admin/Tags/Index.vue +191 -191
  157. package/src/pages/Admin/Tickets/Index.vue +126 -91
  158. package/src/pages/Admin/Tickets/Show.vue +29 -0
  159. package/src/pages/Admin/Users/Index.vue +145 -0
  160. package/src/pages/Admin/Webhooks/DeliveryLog.vue +120 -120
  161. package/src/pages/Admin/Webhooks/Form.vue +110 -110
  162. package/src/pages/Admin/Webhooks/Index.vue +136 -136
  163. package/src/pages/Admin/Workflows/Builder.vue +207 -0
  164. package/src/pages/Admin/Workflows/Index.vue +235 -0
  165. package/src/pages/Admin/Workflows/Logs.vue +286 -0
  166. package/src/pages/Agent/TicketIndex.vue +112 -88
  167. package/src/pages/Agent/TicketShow.vue +192 -60
  168. package/src/pages/Customer/Create.vue +1 -1
  169. package/src/pages/Customer/Index.vue +26 -1
  170. package/src/pages/Customer/KnowledgeBase/Article.vue +4 -2
  171. package/src/pages/Customer/KnowledgeBase/Index.vue +151 -151
  172. package/src/pages/Customer/Show.vue +69 -63
  173. package/src/pages/Guest/Create.vue +40 -15
  174. package/src/pages/Guest/Show.vue +124 -93
  175. package/src/plugin.js +26 -1
  176. package/src/utils/mentionHighlight.js +24 -0
  177. package/src/utils/sanitizeHtml.js +78 -64
  178. package/src/widget/EscalatedWidget.vue +804 -0
  179. package/src/widget/index.js +254 -0
  180. package/src/pages/Admin/Automations/Form.vue +0 -184
  181. package/src/pages/Admin/Automations/Index.vue +0 -129
@@ -0,0 +1,308 @@
1
+ <script setup>
2
+ import { ref, computed, inject } from 'vue';
3
+ import { useI18n } from '../composables/useI18n';
4
+ import MentionDropdown from './MentionDropdown.vue';
5
+ import { useMentions } from '../composables/useMentions';
6
+
7
+ const props = defineProps({
8
+ sessionId: { type: [String, Number], default: null },
9
+ disabled: { type: Boolean, default: false },
10
+ allowNotes: { type: Boolean, default: false },
11
+ allowAttachments: { type: Boolean, default: true },
12
+ sendEndpoint: { type: String, default: '' },
13
+ typingEndpoint: { type: String, default: '' },
14
+ });
15
+
16
+ const emit = defineEmits(['send', 'typing']);
17
+
18
+ const escDark = inject(
19
+ 'esc-dark',
20
+ computed(() => false),
21
+ );
22
+ const { t } = useI18n();
23
+
24
+ const body = ref('');
25
+ const isNote = ref(false);
26
+ const files = ref([]);
27
+ const submitting = ref(false);
28
+ const textareaRef = ref(null);
29
+ const mentionDropdownRef = ref(null);
30
+
31
+ const {
32
+ suggestions,
33
+ isActive: mentionActive,
34
+ loading: mentionLoading,
35
+ onTextChange,
36
+ insertMention,
37
+ close: closeMentions,
38
+ } = useMentions();
39
+
40
+ function onMentionInput() {
41
+ if (textareaRef.value) {
42
+ onTextChange(textareaRef.value, body.value);
43
+ }
44
+ }
45
+
46
+ function handleMentionSelect(agent) {
47
+ body.value = insertMention(body.value, agent);
48
+ textareaRef.value?.focus();
49
+ }
50
+
51
+ // Typing indicator: debounced POST every 3 seconds while typing
52
+ let lastTypingSent = 0;
53
+ let typingTimer = null;
54
+
55
+ function onInput() {
56
+ emit('typing');
57
+ if (!props.typingEndpoint) return;
58
+ const now = Date.now();
59
+ if (now - lastTypingSent < 3000) return;
60
+ lastTypingSent = now;
61
+ sendTypingIndicator();
62
+
63
+ window.clearTimeout(typingTimer);
64
+ typingTimer = window.setTimeout(() => {
65
+ lastTypingSent = 0;
66
+ }, 4000);
67
+ }
68
+
69
+ async function sendTypingIndicator() {
70
+ try {
71
+ await fetch(props.typingEndpoint, {
72
+ method: 'POST',
73
+ headers: {
74
+ Accept: 'application/json',
75
+ 'Content-Type': 'application/json',
76
+ 'X-Requested-With': 'XMLHttpRequest',
77
+ 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content || '',
78
+ },
79
+ });
80
+ } catch {
81
+ // silently ignore
82
+ }
83
+ }
84
+
85
+ function handleKeydown(e) {
86
+ // Let mention dropdown handle keys first
87
+ if (mentionActive.value && mentionDropdownRef.value) {
88
+ const handled = mentionDropdownRef.value.onKeydown(e);
89
+ if (handled) return;
90
+ }
91
+
92
+ if (e.key === 'Enter' && !e.shiftKey) {
93
+ e.preventDefault();
94
+ submit();
95
+ }
96
+ }
97
+
98
+ function triggerFileInput() {
99
+ const input = document.createElement('input');
100
+ input.type = 'file';
101
+ input.multiple = true;
102
+ input.addEventListener('change', () => {
103
+ if (input.files) {
104
+ files.value = [...files.value, ...Array.from(input.files)];
105
+ }
106
+ });
107
+ input.click();
108
+ }
109
+
110
+ function removeFile(index) {
111
+ files.value.splice(index, 1);
112
+ }
113
+
114
+ async function submit() {
115
+ if (!body.value.trim() || submitting.value || props.disabled) return;
116
+ submitting.value = true;
117
+ window.clearTimeout(typingTimer);
118
+ lastTypingSent = 0;
119
+
120
+ const payload = {
121
+ body: body.value,
122
+ is_internal_note: isNote.value,
123
+ attachments: files.value,
124
+ };
125
+
126
+ emit('send', payload);
127
+
128
+ if (props.sendEndpoint) {
129
+ try {
130
+ await fetch(props.sendEndpoint, {
131
+ method: 'POST',
132
+ headers: {
133
+ Accept: 'application/json',
134
+ 'Content-Type': 'application/json',
135
+ 'X-Requested-With': 'XMLHttpRequest',
136
+ 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content || '',
137
+ },
138
+ body: JSON.stringify(payload),
139
+ });
140
+ } catch {
141
+ // error handling delegated to caller
142
+ }
143
+ }
144
+
145
+ body.value = '';
146
+ files.value = [];
147
+ isNote.value = false;
148
+ submitting.value = false;
149
+
150
+ // Re-focus textarea
151
+ textareaRef.value?.focus();
152
+ }
153
+ </script>
154
+
155
+ <template>
156
+ <div
157
+ :class="[
158
+ 'border-t',
159
+ isNote
160
+ ? escDark
161
+ ? 'border-amber-500/20 bg-amber-500/5'
162
+ : 'border-yellow-200 bg-yellow-50'
163
+ : escDark
164
+ ? 'border-white/[0.06] bg-neutral-900/60'
165
+ : 'border-gray-200 bg-white',
166
+ ]"
167
+ >
168
+ <!-- Note/Reply toggle -->
169
+ <div v-if="allowNotes" class="flex gap-1 px-3 pt-2">
170
+ <button
171
+ :class="[
172
+ 'rounded px-2 py-0.5 text-xs font-medium transition-colors',
173
+ !isNote
174
+ ? escDark
175
+ ? 'bg-cyan-500/15 text-white'
176
+ : 'bg-blue-100 text-blue-700'
177
+ : escDark
178
+ ? 'text-neutral-500 hover:text-neutral-300'
179
+ : 'text-gray-400 hover:text-gray-600',
180
+ ]"
181
+ @click="isNote = false"
182
+ >
183
+ {{ t('reply.reply') }}
184
+ </button>
185
+ <button
186
+ :class="[
187
+ 'rounded px-2 py-0.5 text-xs font-medium transition-colors',
188
+ isNote
189
+ ? escDark
190
+ ? 'bg-amber-500/15 text-amber-400'
191
+ : 'bg-yellow-100 text-yellow-700'
192
+ : escDark
193
+ ? 'text-neutral-500 hover:text-neutral-300'
194
+ : 'text-gray-400 hover:text-gray-600',
195
+ ]"
196
+ aria-label="Internal note"
197
+ @click="isNote = true"
198
+ >
199
+ {{ t('chat.note') }}
200
+ </button>
201
+ </div>
202
+
203
+ <!-- File list -->
204
+ <div v-if="files.length" class="flex flex-wrap gap-2 px-3 pt-2">
205
+ <span
206
+ v-for="(file, i) in files"
207
+ :key="i"
208
+ :class="[
209
+ 'inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs',
210
+ escDark ? 'bg-neutral-800 text-neutral-400' : 'bg-gray-100 text-gray-600',
211
+ ]"
212
+ >
213
+ {{ file.name }}
214
+ <button
215
+ aria-label="Remove attachment"
216
+ :class="[escDark ? 'text-rose-400 hover:text-rose-300' : 'text-red-500 hover:text-red-700']"
217
+ @click="removeFile(i)"
218
+ >
219
+ &times;
220
+ </button>
221
+ </span>
222
+ </div>
223
+
224
+ <!-- Input row -->
225
+ <div class="flex items-end gap-2 p-3">
226
+ <!-- Attachment button -->
227
+ <button
228
+ v-if="allowAttachments"
229
+ :disabled="disabled"
230
+ :class="[
231
+ 'flex-shrink-0 rounded-lg p-2 transition-colors',
232
+ disabled
233
+ ? 'cursor-not-allowed opacity-40'
234
+ : escDark
235
+ ? 'text-neutral-500 hover:bg-white/[0.04] hover:text-neutral-300'
236
+ : 'text-gray-400 hover:bg-gray-100 hover:text-gray-600',
237
+ ]"
238
+ aria-label="Attach file"
239
+ @click="triggerFileInput"
240
+ >
241
+ <svg class="h-5 w-5" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24">
242
+ <path
243
+ stroke-linecap="round"
244
+ stroke-linejoin="round"
245
+ d="M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"
246
+ />
247
+ </svg>
248
+ </button>
249
+
250
+ <!-- Text input -->
251
+ <div class="relative flex-1">
252
+ <textarea
253
+ ref="textareaRef"
254
+ v-model="body"
255
+ :disabled="disabled"
256
+ rows="1"
257
+ :placeholder="isNote ? t('reply.write_internal_note') : t('chat.placeholder')"
258
+ :class="[
259
+ 'w-full resize-none rounded-xl border px-4 py-2 text-sm focus:outline-none focus:ring-1',
260
+ disabled && 'cursor-not-allowed opacity-50',
261
+ escDark
262
+ ? 'border-white/10 bg-neutral-950 text-neutral-200 placeholder-neutral-600 focus:border-white/20 focus:ring-white/10'
263
+ : 'border-gray-300 bg-white text-gray-900 placeholder-gray-400 focus:border-blue-500 focus:ring-blue-500',
264
+ ]"
265
+ aria-label="Chat message"
266
+ @input="
267
+ onInput();
268
+ onMentionInput();
269
+ "
270
+ @keydown="handleKeydown"
271
+ ></textarea>
272
+ <MentionDropdown
273
+ ref="mentionDropdownRef"
274
+ :suggestions="suggestions"
275
+ :visible="mentionActive"
276
+ :loading="mentionLoading"
277
+ class="bottom-0 left-0 translate-y-full"
278
+ @select="handleMentionSelect"
279
+ @close="closeMentions"
280
+ />
281
+ </div>
282
+
283
+ <!-- Send button -->
284
+ <button
285
+ :disabled="!body.trim() || submitting || disabled"
286
+ :class="[
287
+ 'flex-shrink-0 rounded-xl p-2 transition-all',
288
+ !body.trim() || submitting || disabled ? 'cursor-not-allowed opacity-40' : '',
289
+ isNote
290
+ ? 'bg-amber-500 text-white hover:bg-amber-400'
291
+ : escDark
292
+ ? 'bg-gradient-to-r from-cyan-500 to-violet-500 text-white hover:from-cyan-400 hover:to-violet-400'
293
+ : 'bg-blue-600 text-white hover:bg-blue-500',
294
+ ]"
295
+ aria-label="Send message"
296
+ @click="submit"
297
+ >
298
+ <svg class="h-5 w-5" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
299
+ <path
300
+ stroke-linecap="round"
301
+ stroke-linejoin="round"
302
+ d="M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"
303
+ />
304
+ </svg>
305
+ </button>
306
+ </div>
307
+ </div>
308
+ </template>
@@ -0,0 +1,222 @@
1
+ <script setup>
2
+ import { ref, computed, inject, onMounted, onUnmounted } from 'vue';
3
+ import { usePage } from '@inertiajs/vue3';
4
+ import { useI18n } from '../composables/useI18n';
5
+ import { useChat } from '../composables/useChat';
6
+
7
+ const props = defineProps({
8
+ sessions: { type: Array, default: () => [] },
9
+ acceptEndpoint: { type: String, default: '' },
10
+ });
11
+
12
+ const emit = defineEmits(['accept', 'refresh']);
13
+
14
+ const escDark = inject(
15
+ 'esc-dark',
16
+ computed(() => false),
17
+ );
18
+ const { t } = useI18n();
19
+
20
+ // Live elapsed timers
21
+ const now = ref(Date.now());
22
+ let timerInterval = null;
23
+
24
+ onMounted(() => {
25
+ timerInterval = setInterval(() => {
26
+ now.value = Date.now();
27
+ }, 1000);
28
+ });
29
+
30
+ onUnmounted(() => {
31
+ clearInterval(timerInterval);
32
+ });
33
+
34
+ function waitTime(createdAt) {
35
+ if (!createdAt) return '0s';
36
+ const diffMs = now.value - new Date(createdAt).getTime();
37
+ const totalSecs = Math.max(0, Math.floor(diffMs / 1000));
38
+ if (totalSecs < 60) return `${totalSecs}s`;
39
+ const mins = Math.floor(totalSecs / 60);
40
+ if (mins < 60) return `${mins}m ${totalSecs % 60}s`;
41
+ const hrs = Math.floor(mins / 60);
42
+ return `${hrs}h ${mins % 60}m`;
43
+ }
44
+
45
+ const sortedSessions = computed(() => {
46
+ return [...props.sessions].sort((a, b) => {
47
+ return new Date(a.created_at) - new Date(b.created_at);
48
+ });
49
+ });
50
+
51
+ async function acceptChat(session) {
52
+ emit('accept', session);
53
+ if (props.acceptEndpoint) {
54
+ try {
55
+ await fetch(props.acceptEndpoint.replace(':id', session.id), {
56
+ method: 'POST',
57
+ headers: {
58
+ Accept: 'application/json',
59
+ 'Content-Type': 'application/json',
60
+ 'X-Requested-With': 'XMLHttpRequest',
61
+ 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]')?.content || '',
62
+ },
63
+ });
64
+ } catch {
65
+ // handled by caller
66
+ }
67
+ }
68
+ }
69
+
70
+ // Subscribe to queue for real-time updates. Read the host framework's
71
+ // route prefix from Inertia page props so chat API calls resolve
72
+ // correctly on NestJS backends ('/escalated/widget') as well as every
73
+ // other framework ('/support/widget').
74
+ const page = usePage();
75
+ const routePrefix = page.props.escalated?.prefix || 'support';
76
+ const { subscribeToChatQueue } = useChat({ widgetPath: `/${routePrefix}/widget` });
77
+
78
+ onMounted(() => {
79
+ subscribeToChatQueue({
80
+ onNewChat() {
81
+ emit('refresh');
82
+ },
83
+ onChatAccepted() {
84
+ emit('refresh');
85
+ },
86
+ });
87
+ });
88
+ </script>
89
+
90
+ <template>
91
+ <div>
92
+ <!-- Empty state -->
93
+ <div
94
+ v-if="!sortedSessions.length"
95
+ :class="[
96
+ 'rounded-xl border p-8 text-center',
97
+ escDark ? 'border-white/[0.06] bg-neutral-900/60' : 'border-gray-200 bg-white',
98
+ ]"
99
+ >
100
+ <svg
101
+ :class="['mx-auto mb-3 h-10 w-10', escDark ? 'text-neutral-700' : 'text-gray-300']"
102
+ fill="none"
103
+ stroke="currentColor"
104
+ stroke-width="1.5"
105
+ viewBox="0 0 24 24"
106
+ >
107
+ <path
108
+ stroke-linecap="round"
109
+ stroke-linejoin="round"
110
+ d="M8.625 12a.375.375 0 11-.75 0 .375.375 0 01.75 0zm0 0H8.25m4.125 0a.375.375 0 11-.75 0 .375.375 0 01.75 0zm0 0H12m4.125 0a.375.375 0 11-.75 0 .375.375 0 01.75 0zm0 0h-.375M21 12c0 4.556-4.03 8.25-9 8.25a9.764 9.764 0 01-2.555-.337A5.972 5.972 0 015.41 20.97a5.969 5.969 0 01-.474-.065 4.48 4.48 0 00.978-2.025c.09-.457-.133-.901-.467-1.226C3.93 16.178 3 14.189 3 12c0-4.556 4.03-8.25 9-8.25s9 3.694 9 8.25z"
111
+ />
112
+ </svg>
113
+ <p :class="['text-sm', escDark ? 'text-neutral-600' : 'text-gray-400']">
114
+ {{ t('chat.no_chats_waiting') }}
115
+ </p>
116
+ </div>
117
+
118
+ <!-- Queue list -->
119
+ <div
120
+ v-else
121
+ :class="[
122
+ 'overflow-hidden rounded-xl border',
123
+ escDark ? 'border-white/[0.06] bg-neutral-900/60' : 'border-gray-200 bg-white',
124
+ ]"
125
+ >
126
+ <table class="min-w-full">
127
+ <thead>
128
+ <tr :class="escDark ? 'bg-white/[0.02]' : 'bg-gray-50'">
129
+ <th
130
+ :class="[
131
+ 'px-4 py-3 text-left text-[11px] font-semibold uppercase tracking-wider',
132
+ escDark ? 'text-neutral-500' : 'text-gray-500',
133
+ ]"
134
+ >
135
+ {{ t('chat.customer') }}
136
+ </th>
137
+ <th
138
+ :class="[
139
+ 'px-4 py-3 text-left text-[11px] font-semibold uppercase tracking-wider',
140
+ escDark ? 'text-neutral-500' : 'text-gray-500',
141
+ ]"
142
+ >
143
+ {{ t('chat.department') }}
144
+ </th>
145
+ <th
146
+ :class="[
147
+ 'px-4 py-3 text-left text-[11px] font-semibold uppercase tracking-wider',
148
+ escDark ? 'text-neutral-500' : 'text-gray-500',
149
+ ]"
150
+ >
151
+ {{ t('chat.first_message') }}
152
+ </th>
153
+ <th
154
+ :class="[
155
+ 'px-4 py-3 text-left text-[11px] font-semibold uppercase tracking-wider',
156
+ escDark ? 'text-neutral-500' : 'text-gray-500',
157
+ ]"
158
+ >
159
+ {{ t('chat.wait_time') }}
160
+ </th>
161
+ <th
162
+ :class="[
163
+ 'px-4 py-3 text-right text-[11px] font-semibold uppercase tracking-wider',
164
+ escDark ? 'text-neutral-500' : 'text-gray-500',
165
+ ]"
166
+ ></th>
167
+ </tr>
168
+ </thead>
169
+ <tbody :class="escDark ? 'divide-y divide-white/[0.04]' : 'divide-y divide-gray-100'">
170
+ <tr
171
+ v-for="session in sortedSessions"
172
+ :key="session.id"
173
+ :class="['transition-colors', escDark ? 'hover:bg-white/[0.03]' : 'hover:bg-gray-50']"
174
+ >
175
+ <td class="px-4 py-3">
176
+ <div :class="['text-sm font-medium', escDark ? 'text-neutral-200' : 'text-gray-900']">
177
+ {{ session.customer_name || t('ticket.unknown') }}
178
+ </div>
179
+ <div :class="['text-xs', escDark ? 'text-neutral-600' : 'text-gray-400']">
180
+ {{ session.customer_email || '' }}
181
+ </div>
182
+ </td>
183
+ <td :class="['px-4 py-3 text-sm', escDark ? 'text-neutral-400' : 'text-gray-500']">
184
+ {{ session.department?.name || '---' }}
185
+ </td>
186
+ <td
187
+ :class="[
188
+ 'max-w-[200px] truncate px-4 py-3 text-sm',
189
+ escDark ? 'text-neutral-400' : 'text-gray-600',
190
+ ]"
191
+ >
192
+ {{ session.first_message || '...' }}
193
+ </td>
194
+ <td class="px-4 py-3">
195
+ <span
196
+ :class="[
197
+ 'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
198
+ escDark ? 'bg-amber-500/10 text-amber-400' : 'bg-amber-50 text-amber-700',
199
+ ]"
200
+ >
201
+ {{ waitTime(session.created_at) }}
202
+ </span>
203
+ </td>
204
+ <td class="px-4 py-3 text-right">
205
+ <button
206
+ :class="[
207
+ 'rounded-lg px-3 py-1.5 text-sm font-medium text-white transition-all',
208
+ escDark
209
+ ? 'bg-gradient-to-r from-cyan-500 to-violet-500 hover:from-cyan-400 hover:to-violet-400'
210
+ : 'bg-blue-600 hover:bg-blue-500',
211
+ ]"
212
+ @click="acceptChat(session)"
213
+ >
214
+ {{ t('chat.accept') }}
215
+ </button>
216
+ </td>
217
+ </tr>
218
+ </tbody>
219
+ </table>
220
+ </div>
221
+ </div>
222
+ </template>