@escalated-dev/escalated 0.6.0 → 0.7.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 (187) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +125 -2
  3. package/package.json +40 -5
  4. package/src/components/ActiveChatsPanel.vue +246 -0
  5. package/src/components/ActivityTimeline.stories.js +55 -0
  6. package/src/components/ActivityTimeline.vue +83 -66
  7. package/src/components/AdminDashboard.stories.js +1423 -0
  8. package/src/components/AgentLoadIndicator.stories.js +37 -0
  9. package/src/components/AgentLoadIndicator.vue +49 -0
  10. package/src/components/AgentPerformanceCard.vue +44 -0
  11. package/src/components/ArticleEditor.vue +82 -0
  12. package/src/components/AssigneeSelect.vue +37 -23
  13. package/src/components/AttachmentList.vue +65 -37
  14. package/src/components/AuditLogEntry.vue +95 -0
  15. package/src/components/BulkActionBar.vue +166 -97
  16. package/src/components/CategoryTree.vue +89 -0
  17. package/src/components/ChartWidget.vue +46 -0
  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 -0
  24. package/src/components/CollisionWarning.vue +68 -0
  25. package/src/components/ConditionalFieldRules.vue +135 -0
  26. package/src/components/ContextPanel.vue +66 -0
  27. package/src/components/ContextPanelSection.vue +65 -0
  28. package/src/components/CustomFieldRenderer.vue +159 -0
  29. package/src/components/EscalatedLayout.vue +424 -70
  30. package/src/components/FileDropzone.vue +57 -41
  31. package/src/components/FollowButton.stories.js +30 -0
  32. package/src/components/FollowButton.vue +88 -63
  33. package/src/components/KeyboardShortcutHelp.vue +213 -123
  34. package/src/components/KnowledgePanel.vue +122 -0
  35. package/src/components/KpiCard.stories.js +32 -0
  36. package/src/components/KpiCard.vue +88 -0
  37. package/src/components/MacroDropdown.vue +150 -90
  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 -0
  43. package/src/components/PinnedNotes.vue +129 -90
  44. package/src/components/PluginSlot.vue +68 -62
  45. package/src/components/PresenceIndicator.vue +138 -28
  46. package/src/components/PriorityBadge.stories.js +33 -0
  47. package/src/components/PriorityBadge.vue +46 -39
  48. package/src/components/QuickFilters.vue +65 -49
  49. package/src/components/ReplyComposer.vue +207 -30
  50. package/src/components/ReplyThread.vue +111 -21
  51. package/src/components/ReportChart.vue +395 -0
  52. package/src/components/ReportExportButton.vue +108 -0
  53. package/src/components/SatisfactionRating.vue +180 -128
  54. package/src/components/SaveViewDialog.vue +172 -0
  55. package/src/components/SavedViewSidebar.vue +208 -0
  56. package/src/components/ScheduleEditor.vue +104 -0
  57. package/src/components/SideConversation.vue +165 -0
  58. package/src/components/SideConversationList.vue +147 -0
  59. package/src/components/SkillTagManager.vue +79 -0
  60. package/src/components/SlaComplianceChart.vue +46 -0
  61. package/src/components/SlaTimer.stories.js +35 -0
  62. package/src/components/SlaTimer.vue +62 -49
  63. package/src/components/SnoozeButton.vue +247 -0
  64. package/src/components/StatsCard.stories.js +24 -0
  65. package/src/components/StatsCard.vue +18 -6
  66. package/src/components/StatusBadge.stories.js +53 -0
  67. package/src/components/StatusBadge.vue +78 -46
  68. package/src/components/TagSelect.vue +84 -53
  69. package/src/components/TicketFilters.vue +247 -46
  70. package/src/components/TicketLinkPanel.vue +193 -0
  71. package/src/components/TicketList.vue +536 -74
  72. package/src/components/TicketMergeDialog.vue +157 -0
  73. package/src/components/TicketSidebar.vue +167 -99
  74. package/src/components/TicketSplitDialog.vue +98 -0
  75. package/src/components/TicketTypeSelector.vue +21 -0
  76. package/src/components/TotpInput.stories.js +9 -0
  77. package/src/components/TotpInput.vue +81 -0
  78. package/src/components/TwoFactorSetup.vue +113 -0
  79. package/src/components/VariableTokenInput.vue +111 -0
  80. package/src/components/WorkflowActionConfig.vue +287 -0
  81. package/src/components/WorkflowActionList.vue +350 -0
  82. package/src/components/WorkflowConditionBuilder.vue +265 -0
  83. package/src/components/WorkflowTriggerSelector.vue +125 -0
  84. package/src/composables/useChat.js +187 -0
  85. package/src/composables/useDebouncedSearch.js +38 -0
  86. package/src/composables/useI18n.js +80 -80
  87. package/src/composables/useKeyboardShortcuts.js +46 -46
  88. package/src/composables/useMentions.js +134 -0
  89. package/src/composables/usePluginExtensions.js +159 -67
  90. package/src/composables/usePluginHooks.js +65 -0
  91. package/src/composables/useRealtime.js +182 -0
  92. package/src/defineEscalatedPlugin.js +76 -50
  93. package/src/index.js +77 -28
  94. package/src/locales/ar.json +727 -0
  95. package/src/locales/de.json +678 -430
  96. package/src/locales/en.json +717 -430
  97. package/src/locales/es.json +679 -430
  98. package/src/locales/fr.json +680 -431
  99. package/src/locales/index.js +12 -2
  100. package/src/locales/it.json +727 -0
  101. package/src/locales/ja.json +727 -0
  102. package/src/locales/ko.json +727 -0
  103. package/src/locales/nl.json +727 -0
  104. package/src/locales/pl.json +727 -0
  105. package/src/locales/pt-BR.json +727 -0
  106. package/src/locales/ru.json +727 -0
  107. package/src/locales/tr.json +727 -0
  108. package/src/locales/zh-CN.json +727 -0
  109. package/src/pages/Admin/ApiTokens/Index.vue +381 -217
  110. package/src/pages/Admin/AuditLog/Index.vue +154 -0
  111. package/src/pages/Admin/BusinessHours/Form.vue +172 -0
  112. package/src/pages/Admin/BusinessHours/Index.vue +113 -0
  113. package/src/pages/Admin/CannedResponses/Index.vue +82 -25
  114. package/src/pages/Admin/Capacity/Index.vue +134 -0
  115. package/src/pages/Admin/CustomFields/Form.vue +195 -0
  116. package/src/pages/Admin/CustomFields/Index.vue +134 -0
  117. package/src/pages/Admin/CustomObjects/Form.vue +202 -0
  118. package/src/pages/Admin/CustomObjects/Index.vue +127 -0
  119. package/src/pages/Admin/CustomObjects/Records.vue +228 -0
  120. package/src/pages/Admin/Departments/Form.vue +35 -11
  121. package/src/pages/Admin/Departments/Index.vue +74 -21
  122. package/src/pages/Admin/EscalationRules/Form.vue +86 -25
  123. package/src/pages/Admin/EscalationRules/Index.vue +158 -37
  124. package/src/pages/Admin/Import/Connect.vue +95 -0
  125. package/src/pages/Admin/Import/Index.vue +102 -0
  126. package/src/pages/Admin/Import/Mapping.vue +110 -0
  127. package/src/pages/Admin/Import/Progress.vue +153 -0
  128. package/src/pages/Admin/Import/Review.vue +76 -0
  129. package/src/pages/Admin/KnowledgeBase/Articles/Form.vue +142 -0
  130. package/src/pages/Admin/KnowledgeBase/Articles/Index.vue +195 -0
  131. package/src/pages/Admin/KnowledgeBase/Categories/Index.vue +193 -0
  132. package/src/pages/Admin/Macros/Index.vue +448 -287
  133. package/src/pages/Admin/Plugins/Index.vue +327 -197
  134. package/src/pages/Admin/Reports/AgentDetail.vue +132 -0
  135. package/src/pages/Admin/Reports/AgentMetrics.vue +115 -0
  136. package/src/pages/Admin/Reports/AgentRanking.vue +246 -0
  137. package/src/pages/Admin/Reports/Cohorts.vue +180 -0
  138. package/src/pages/Admin/Reports/Comparison.vue +141 -0
  139. package/src/pages/Admin/Reports/CsatReport.vue +127 -0
  140. package/src/pages/Admin/Reports/Dashboard.vue +226 -0
  141. package/src/pages/Admin/Reports/ResolutionTimes.vue +164 -0
  142. package/src/pages/Admin/Reports/ResponseTimes.vue +164 -0
  143. package/src/pages/Admin/Reports/SlaReport.vue +162 -0
  144. package/src/pages/Admin/Reports/SlaTrends.vue +183 -0
  145. package/src/pages/Admin/Reports.vue +206 -101
  146. package/src/pages/Admin/Roles/Form.vue +71 -0
  147. package/src/pages/Admin/Roles/Index.vue +122 -0
  148. package/src/pages/Admin/Settings/CsatSettings.vue +165 -0
  149. package/src/pages/Admin/Settings/DataRetention.vue +182 -0
  150. package/src/pages/Admin/Settings/EmailSettings.vue +243 -0
  151. package/src/pages/Admin/Settings/Sandbox.vue +135 -0
  152. package/src/pages/Admin/Settings/SsoSettings.vue +218 -0
  153. package/src/pages/Admin/Settings/TwoFactor.vue +110 -0
  154. package/src/pages/Admin/Settings.vue +847 -99
  155. package/src/pages/Admin/Skills/Form.vue +53 -0
  156. package/src/pages/Admin/Skills/Index.vue +94 -0
  157. package/src/pages/Admin/SlaPolicies/Form.vue +62 -19
  158. package/src/pages/Admin/SlaPolicies/Index.vue +85 -23
  159. package/src/pages/Admin/Statuses/Form.vue +114 -0
  160. package/src/pages/Admin/Statuses/Index.vue +153 -0
  161. package/src/pages/Admin/Tags/Index.vue +121 -35
  162. package/src/pages/Admin/Tickets/Index.vue +96 -9
  163. package/src/pages/Admin/Tickets/Show.vue +130 -37
  164. package/src/pages/Admin/Webhooks/DeliveryLog.vue +120 -0
  165. package/src/pages/Admin/Webhooks/Form.vue +110 -0
  166. package/src/pages/Admin/Webhooks/Index.vue +136 -0
  167. package/src/pages/Admin/Workflows/Builder.vue +207 -0
  168. package/src/pages/Admin/Workflows/Index.vue +235 -0
  169. package/src/pages/Admin/Workflows/Logs.vue +286 -0
  170. package/src/pages/Agent/Dashboard.vue +311 -186
  171. package/src/pages/Agent/TicketIndex.vue +80 -6
  172. package/src/pages/Agent/TicketShow.vue +399 -60
  173. package/src/pages/Customer/Create.vue +37 -10
  174. package/src/pages/Customer/Index.vue +9 -2
  175. package/src/pages/Customer/KnowledgeBase/Article.vue +129 -0
  176. package/src/pages/Customer/KnowledgeBase/Index.vue +151 -0
  177. package/src/pages/Customer/Show.vue +69 -63
  178. package/src/pages/Guest/Create.vue +40 -15
  179. package/src/pages/Guest/Show.vue +124 -93
  180. package/src/plugin.js +111 -1
  181. package/src/utils/constants.js +30 -0
  182. package/src/utils/formatting.js +35 -0
  183. package/src/utils/mentionHighlight.js +24 -0
  184. package/src/utils/sanitizeHtml.js +78 -64
  185. package/src/widget/EscalatedWidget.vue +804 -0
  186. package/src/widget/index.js +254 -0
  187. package/src/pages/Admin/Plugins.vue +0 -129
@@ -0,0 +1,162 @@
1
+ <script setup>
2
+ import { computed, inject } from 'vue';
3
+ import { timeAgo } from '../utils/formatting';
4
+ import { highlightMentions } from '../utils/mentionHighlight';
5
+ import { sanitizeHtml } from '../utils/sanitizeHtml';
6
+
7
+ const props = defineProps({
8
+ message: { type: Object, required: true },
9
+ isAgent: { type: Boolean, default: false },
10
+ showAvatar: { type: Boolean, default: true },
11
+ showTimestamp: { type: Boolean, default: false },
12
+ });
13
+
14
+ const escDark = inject(
15
+ 'esc-dark',
16
+ computed(() => false),
17
+ );
18
+
19
+ function attachmentUrl(att) {
20
+ if (att.url) return att.url;
21
+ if (typeof window.route === 'function') {
22
+ try {
23
+ return window.route('escalated.attachments.download', att.id);
24
+ } catch {
25
+ // route not registered
26
+ }
27
+ }
28
+ return `/escalated/attachments/${att.id}/download`;
29
+ }
30
+
31
+ const initials = computed(() => {
32
+ const name = props.message.author?.name || 'U';
33
+ return name
34
+ .split(' ')
35
+ .map((w) => w[0])
36
+ .join('')
37
+ .toUpperCase()
38
+ .slice(0, 2);
39
+ });
40
+
41
+ const formattedTime = computed(() => {
42
+ if (!props.message.created_at) return '';
43
+ const date = new Date(props.message.created_at);
44
+ const diffMs = Date.now() - date.getTime();
45
+ // If less than 24h, show relative; otherwise show absolute
46
+ if (diffMs < 86400000) {
47
+ return timeAgo(props.message.created_at);
48
+ }
49
+ return date.toLocaleString(undefined, {
50
+ month: 'short',
51
+ day: 'numeric',
52
+ hour: '2-digit',
53
+ minute: '2-digit',
54
+ });
55
+ });
56
+
57
+ const isInternalNote = computed(() => props.message.is_internal_note);
58
+ </script>
59
+
60
+ <template>
61
+ <div
62
+ :class="[
63
+ 'flex gap-2',
64
+ isAgent ? 'flex-row-reverse' : 'flex-row',
65
+ !showAvatar && isAgent ? 'pr-10' : '',
66
+ !showAvatar && !isAgent ? 'pl-10' : '',
67
+ ]"
68
+ :data-message-id="message.id"
69
+ >
70
+ <!-- Avatar -->
71
+ <div v-if="showAvatar" class="flex-shrink-0">
72
+ <div v-if="message.author?.avatar" class="h-8 w-8 overflow-hidden rounded-full">
73
+ <img :src="message.author.avatar" :alt="message.author.name" class="h-full w-full object-cover" />
74
+ </div>
75
+ <div
76
+ v-else
77
+ :class="[
78
+ 'flex h-8 w-8 items-center justify-center rounded-full text-xs font-semibold',
79
+ isAgent
80
+ ? escDark
81
+ ? 'bg-cyan-500/20 text-cyan-400'
82
+ : 'bg-blue-100 text-blue-700'
83
+ : escDark
84
+ ? 'bg-neutral-700 text-neutral-300'
85
+ : 'bg-gray-200 text-gray-600',
86
+ ]"
87
+ >
88
+ {{ initials }}
89
+ </div>
90
+ </div>
91
+
92
+ <!-- Bubble -->
93
+ <div class="max-w-[75%]">
94
+ <div
95
+ :class="[
96
+ 'rounded-2xl px-4 py-2 text-sm',
97
+ isInternalNote
98
+ ? escDark
99
+ ? 'bg-amber-500/10 text-amber-300 ring-1 ring-amber-500/20'
100
+ : 'bg-yellow-50 text-yellow-800 ring-1 ring-yellow-200'
101
+ : isAgent
102
+ ? escDark
103
+ ? 'bg-cyan-500/15 text-neutral-200'
104
+ : 'bg-blue-600 text-white'
105
+ : escDark
106
+ ? 'bg-neutral-800 text-neutral-200'
107
+ : 'bg-gray-100 text-gray-900',
108
+ ]"
109
+ >
110
+ <span v-if="isInternalNote" class="mb-1 block text-[10px] font-semibold uppercase opacity-70">
111
+ Internal Note
112
+ </span>
113
+ <p
114
+ class="whitespace-pre-wrap break-words"
115
+ v-html="highlightMentions(sanitizeHtml(message.body || ''), escDark)"
116
+ ></p>
117
+
118
+ <!-- Attachments -->
119
+ <div v-if="message.attachments?.length" class="mt-2 space-y-1">
120
+ <a
121
+ v-for="att in message.attachments"
122
+ :key="att.id || att.url"
123
+ :href="attachmentUrl(att)"
124
+ target="_blank"
125
+ rel="noopener"
126
+ :class="[
127
+ 'flex items-center gap-1 text-xs underline',
128
+ isAgent && !isInternalNote
129
+ ? escDark
130
+ ? 'text-cyan-300'
131
+ : 'text-blue-200'
132
+ : escDark
133
+ ? 'text-cyan-400'
134
+ : 'text-blue-600',
135
+ ]"
136
+ >
137
+ <svg class="h-3 w-3" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
138
+ <path
139
+ stroke-linecap="round"
140
+ stroke-linejoin="round"
141
+ 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"
142
+ />
143
+ </svg>
144
+ {{ att.name || 'Attachment' }}
145
+ </a>
146
+ </div>
147
+ </div>
148
+
149
+ <!-- Timestamp -->
150
+ <div
151
+ v-if="showTimestamp"
152
+ :class="[
153
+ 'mt-1 text-[10px]',
154
+ isAgent ? 'text-right' : 'text-left',
155
+ escDark ? 'text-neutral-600' : 'text-gray-400',
156
+ ]"
157
+ >
158
+ {{ formattedTime }}
159
+ </div>
160
+ </div>
161
+ </div>
162
+ </template>
@@ -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>