@dev.smartpricing/message-composer-layer 4.4.1-next.0 → 4.5.1-automation.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 (112) hide show
  1. package/README.md +182 -7
  2. package/app/api/automations.ts +74 -0
  3. package/app/api/brands.ts +20 -13
  4. package/app/api/client.ts +3 -6
  5. package/app/api/dynamicValues.ts +2 -1
  6. package/app/api/index.ts +1 -0
  7. package/app/api/media.ts +6 -3
  8. package/app/api/messageGroups.ts +11 -3
  9. package/app/api/meta.ts +62 -4
  10. package/app/api/organization.ts +10 -1
  11. package/app/api/tracking.ts +2 -2
  12. package/app/app.config.ts +10 -0
  13. package/app/components/Automations/ActionCard.vue +174 -0
  14. package/app/components/Automations/ActionEditor.vue +398 -0
  15. package/app/components/Automations/Actions.vue +158 -0
  16. package/app/components/Automations/CloneModal.vue +78 -0
  17. package/app/components/Automations/Conditions.vue +155 -0
  18. package/app/components/Automations/Create.vue +114 -0
  19. package/app/components/Automations/Data.vue +46 -0
  20. package/app/components/Automations/DeleteModal.vue +80 -0
  21. package/app/components/Automations/Edit.vue +145 -0
  22. package/app/components/Automations/Form.vue +282 -0
  23. package/app/components/Automations/List.vue +370 -0
  24. package/app/components/Automations/PageGate.vue +50 -0
  25. package/app/components/Automations/SaveProblems.vue +54 -0
  26. package/app/components/Automations/Unavailable.vue +71 -0
  27. package/app/components/Automations/UnavailableBadge.vue +35 -0
  28. package/app/components/Common/AppContextErrors.vue +2 -2
  29. package/app/components/Common/MessageGroupSelect.vue +43 -3
  30. package/app/components/Common/OrganizationGate.vue +51 -0
  31. package/app/components/Common/OrganizationSelect.vue +27 -0
  32. package/app/components/Common/WhatsappNotConfigured.vue +20 -0
  33. package/app/components/Composer/EmailComposer.vue +9 -1
  34. package/app/components/Composer/MessageLibrary.vue +8 -0
  35. package/app/components/Composer/WabaSelectModal.vue +73 -0
  36. package/app/components/Composer/WhatsappComposer.vue +83 -4
  37. package/app/components/Editor/RichTextEditor.vue +14 -2
  38. package/app/components/Filters/DateInput.vue +57 -0
  39. package/app/components/Filters/Editor.vue +163 -0
  40. package/app/components/Filters/Row.vue +119 -0
  41. package/app/components/Filters/Summary.vue +215 -0
  42. package/app/components/Filters/UnavailableRow.vue +74 -0
  43. package/app/components/Filters/ValueInput.vue +215 -0
  44. package/app/components/Layout/BasePage.vue +2 -0
  45. package/app/components/MessageSendFlow/EmailPreview.vue +3 -0
  46. package/app/components/MessageSendFlow/MessageSendFlow.vue +15 -2
  47. package/app/components/MetaImport/Button.vue +50 -0
  48. package/app/components/MetaImport/Dialog.vue +261 -0
  49. package/app/components/MetaImport/Outcome.vue +136 -0
  50. package/app/components/MetaImport/ProposalList.vue +192 -0
  51. package/app/components/TemplateList/BaseTable.vue +22 -1
  52. package/app/components/Whatsapp/Preview.vue +5 -12
  53. package/app/components/Whatsapp/Translator/Header.vue +4 -19
  54. package/app/composables/apiErrorMessages.ts +1 -0
  55. package/app/composables/automationsContext.ts +42 -0
  56. package/app/composables/composerContext.ts +5 -5
  57. package/app/composables/useAutomationClone.ts +33 -0
  58. package/app/composables/useAutomationEditorTrip.ts +77 -0
  59. package/app/composables/useAutomationSaveProblems.ts +82 -0
  60. package/app/composables/useAutomationUnavailable.ts +98 -0
  61. package/app/composables/useAutomationsGate.ts +68 -0
  62. package/app/composables/useBuiltInOptionLists.ts +44 -0
  63. package/app/composables/useEditorTripBack.ts +15 -0
  64. package/app/composables/useEffectiveOrganization.ts +34 -0
  65. package/app/composables/useMessageGroupWaba.ts +76 -0
  66. package/app/composables/useMessageSendFlow.ts +46 -8
  67. package/app/composables/usePagedMessageGroups.ts +14 -2
  68. package/app/composables/useTemplateOperations.ts +18 -4
  69. package/app/composables/useTracking.ts +14 -5
  70. package/app/composables/useWhatsappConfiguration.ts +32 -0
  71. package/app/layouts/default.vue +4 -1
  72. package/app/middleware/automations-enabled.ts +12 -0
  73. package/app/pages/automations/[id].vue +87 -0
  74. package/app/pages/automations/index.vue +28 -0
  75. package/app/pages/automations/new.vue +53 -0
  76. package/app/pages/brands.vue +1 -0
  77. package/app/pages/images.vue +4 -0
  78. package/app/pages/index.vue +6 -1
  79. package/app/pages/preview/[id].vue +2 -0
  80. package/app/pages/template/email/[id].vue +5 -0
  81. package/app/pages/template/email/create.vue +5 -0
  82. package/app/pages/template/whatsapp/[id].vue +6 -0
  83. package/app/pages/template/whatsapp/create.vue +5 -0
  84. package/app/queries/automations.ts +206 -0
  85. package/app/queries/brands.ts +27 -7
  86. package/app/queries/compilation.ts +15 -2
  87. package/app/queries/dynamicValues.ts +13 -2
  88. package/app/queries/index.ts +1 -0
  89. package/app/queries/media.ts +8 -3
  90. package/app/queries/messageGroups.ts +60 -25
  91. package/app/queries/meta.ts +100 -5
  92. package/app/stores/appContext.ts +9 -45
  93. package/app/stores/editorTrip.ts +67 -0
  94. package/app/stores/effectiveOrganization.ts +128 -0
  95. package/app/stores/emailEditor.ts +5 -1
  96. package/app/stores/metaSubmission.ts +7 -17
  97. package/app/types/app-config.d.ts +3 -0
  98. package/app/types/tracking.ts +33 -0
  99. package/app/utils/automations/form.ts +389 -0
  100. package/app/utils/automations/metadata.ts +71 -0
  101. package/app/utils/automations/unavailable.ts +90 -0
  102. package/app/utils/filters/data/countries.json +998 -0
  103. package/app/utils/filters/data/languages.json +754 -0
  104. package/app/utils/filters/rows.ts +367 -0
  105. package/app/utils/testIds.const.ts +108 -0
  106. package/i18n/locales/de.ts +363 -0
  107. package/i18n/locales/en.ts +345 -0
  108. package/i18n/locales/es.ts +349 -0
  109. package/i18n/locales/fr.ts +357 -0
  110. package/i18n/locales/it.ts +354 -0
  111. package/package.json +4 -4
  112. package/app.config.ts +0 -5
@@ -0,0 +1,370 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ Automation,
4
+ AutomationCatalog,
5
+ AutomationChannel,
6
+ } from '@dev.smartpricing/message-composer-utils/types'
7
+ import { formatDate } from '@dev.smartpricing/message-composer-utils/utils'
8
+ import type { TableColumn } from '#ui/types'
9
+ import AutomationsDeleteModal from '~/components/Automations/DeleteModal.vue'
10
+ import { useAutomationsQuery, useDeleteAutomationMutation } from '~/queries'
11
+ import { isSystemAutomation } from '../../utils/automations/metadata'
12
+
13
+ /**
14
+ * The Automations of the Effective Organization for the Host's Product, with
15
+ * client-side search, filter and sort: the Automation Engine pages nothing
16
+ * (ADR 0016). Trigger labels come from the Automation Catalog. System
17
+ * Automations stay on top, whatever the sort.
18
+ */
19
+ const props = defineProps<{ catalog: AutomationCatalog }>()
20
+
21
+ const { t, te } = useI18n()
22
+ const { trackEvent } = useTracking()
23
+
24
+ const { data: automations, isPending } = useAutomationsQuery()
25
+
26
+ // A lookup still running or failed is not "no WABA": WhatsApp stays listed.
27
+ const { status: whatsappStatus } = useWhatsappConfiguration()
28
+ const whatsappOff = computed(
29
+ () => whatsappStatus.value === 'unavailable' || whatsappStatus.value === 'not_configured',
30
+ )
31
+ const { hasEmail } = useChannels()
32
+ /** A Channel the Host does not offer, or the Organization cannot use, is left out. */
33
+ function isShown(channel: string): boolean {
34
+ if (channel === 'whatsapp') return !whatsappOff.value
35
+ if (channel === 'email') return hasEmail.value
36
+ return true
37
+ }
38
+
39
+ const search = ref('')
40
+ const filterTrigger = ref('all')
41
+ const filterStatus = ref('all')
42
+ const filterChannel = ref('all')
43
+ // Column ids are the ones Smartconnect's list reports in `sort_changed`.
44
+ const sorting = ref([{ id: 'createdAt', desc: false }])
45
+
46
+ const filterState = computed(() => ({
47
+ search_term: search.value,
48
+ trigger_type: filterTrigger.value,
49
+ status: filterStatus.value,
50
+ channel: filterChannel.value,
51
+ }))
52
+ const debouncedFilterState = refDebounced(filterState, 1000)
53
+
54
+ watch(debouncedFilterState, (state) => {
55
+ trackEvent('automation_list.filter_changed', state)
56
+ })
57
+
58
+ watch(sorting, ([current]) => {
59
+ if (!current) return
60
+ trackEvent('automation_list.sort_changed', {
61
+ column: current.id,
62
+ direction: current.desc ? 'desc' : 'asc',
63
+ })
64
+ })
65
+
66
+ const triggerOptions = computed(() => [
67
+ { label: t('automations.list.allTriggers'), value: 'all' },
68
+ ...props.catalog.triggers.map((trigger) => ({ label: trigger.label, value: trigger.type })),
69
+ ])
70
+
71
+ const statusOptions = computed(() => [
72
+ { label: t('automations.list.allStatuses'), value: 'all' },
73
+ { label: t('automations.list.active'), value: 'active' },
74
+ { label: t('automations.list.inactive'), value: 'inactive' },
75
+ ])
76
+
77
+ const catalogChannels = computed<AutomationChannel[]>(() => [
78
+ ...new Set(props.catalog.triggers.flatMap((trigger) => trigger.channels.map((c) => c.channel))),
79
+ ])
80
+
81
+ const channelOptions = computed(() => [
82
+ { label: t('automations.list.allChannels'), value: 'all' },
83
+ ...catalogChannels.value
84
+ .filter(isShown)
85
+ .map((channel) => ({ label: getChannelLabel(channel), value: channel })),
86
+ ])
87
+
88
+ function getChannelLabel(channel: string): string {
89
+ const key = `automations.channels.${channel}`
90
+ return te(key) ? t(key) : channel
91
+ }
92
+
93
+ function getTriggerType(automation: Automation): string {
94
+ const { type } = automation.settings.trigger
95
+ return (Array.isArray(type) ? type[0] : type) ?? ''
96
+ }
97
+
98
+ function getTriggerLabel(automation: Automation): string {
99
+ const type = getTriggerType(automation)
100
+ // A Trigger the catalog no longer lists shows as its raw value.
101
+ return props.catalog.triggers.find((trigger) => trigger.type === type)?.label ?? type
102
+ }
103
+
104
+ const filteredAutomations = computed(() => {
105
+ const query = search.value.trim().toLowerCase()
106
+
107
+ return (automations.value ?? []).filter((automation) => {
108
+ const channels = automation.actions.map((action) => action.config.channel)
109
+ // Nothing of it can be sent while WhatsApp is not set up.
110
+ if (channels.length > 0 && !channels.some(isShown)) return false
111
+ if (query && !automation.name.toLowerCase().includes(query)) return false
112
+ if (filterTrigger.value !== 'all' && getTriggerType(automation) !== filterTrigger.value) {
113
+ return false
114
+ }
115
+ if (filterStatus.value !== 'all' && automation.active !== (filterStatus.value === 'active')) {
116
+ return false
117
+ }
118
+ if (filterChannel.value !== 'all' && !channels.includes(filterChannel.value)) return false
119
+ return true
120
+ })
121
+ })
122
+
123
+ /** System Automations are pinned on top, in the order they were read: the sort is of the rest. */
124
+ const rowPinning = computed(() => ({
125
+ top: filteredAutomations.value.filter(isSystemAutomation).map(({ id }) => id),
126
+ }))
127
+
128
+ /** "Email (2), WhatsApp (1)": the Actions of an Automation, by Channel. */
129
+ function getChannels(automation: Automation): string {
130
+ const counts = new Map<string, number>()
131
+ for (const { config } of automation.actions) {
132
+ if (isShown(config.channel)) counts.set(config.channel, (counts.get(config.channel) ?? 0) + 1)
133
+ }
134
+ return [...counts]
135
+ .sort(([a], [b]) => a.localeCompare(b))
136
+ .map(([channel, count]) => `${getChannelLabel(channel)} (${count})`)
137
+ .join(', ')
138
+ }
139
+
140
+ const columns: TableColumn<Automation>[] = [
141
+ {
142
+ accessorKey: 'name',
143
+ header: (ctx) => getSortableHeader(ctx, t('automations.list.headers.name')),
144
+ },
145
+ {
146
+ id: 'trigger',
147
+ accessorFn: getTriggerType,
148
+ header: (ctx) => getSortableHeader(ctx, t('automations.list.headers.trigger')),
149
+ cell: ({ row }) => getTriggerLabel(row.original),
150
+ },
151
+ {
152
+ id: 'enabled',
153
+ // Active first when ascending.
154
+ accessorFn: (automation) => (automation.active ? 0 : 1),
155
+ header: (ctx) => getSortableHeader(ctx, t('automations.list.headers.status')),
156
+ },
157
+ {
158
+ id: 'channel',
159
+ accessorFn: (automation) => automation.actions.length,
160
+ header: (ctx) => getSortableHeader(ctx, t('automations.list.headers.channels')),
161
+ },
162
+ {
163
+ id: 'audience',
164
+ accessorFn: (automation) => automation.settings.conditions.length,
165
+ header: (ctx) => getSortableHeader(ctx, t('automations.list.headers.audience')),
166
+ cell: ({ row }) =>
167
+ row.original.settings.conditions.length > 0
168
+ ? t('automations.audienceSpecific')
169
+ : t('automations.audienceAll'),
170
+ },
171
+ {
172
+ id: 'createdAt',
173
+ accessorKey: 'created_at',
174
+ header: (ctx) => getSortableHeader(ctx, t('automations.list.headers.createdAt')),
175
+ cell: ({ row }) => formatDate(row.original.created_at),
176
+ },
177
+ {
178
+ id: 'actions',
179
+ enableSorting: false,
180
+ header: '',
181
+ meta: {
182
+ class: {
183
+ th: 'w-[66px]',
184
+ td: 'w-[66px]',
185
+ },
186
+ },
187
+ },
188
+ ]
189
+
190
+ const columnPinning = ref({
191
+ right: ['actions'],
192
+ })
193
+
194
+ const toast = useToast()
195
+ const deleteModal = useOverlay().create(AutomationsDeleteModal, { destroyOnClose: true })
196
+ const { mutateAsync: deleteAutomation } = useDeleteAutomationMutation()
197
+
198
+ const listNames = (messageGroups: Array<{ name: string }>) =>
199
+ messageGroups.map(({ name }) => name).join(', ')
200
+
201
+ function askDelete(automation: Automation) {
202
+ deleteModal.open({
203
+ automation,
204
+ action: async (messageGroupIds) => {
205
+ const result = await deleteAutomation({ id: automation.id, messageGroupIds })
206
+ trackEvent('automation_list.delete', {
207
+ automation_name: automation.name,
208
+ automation_id: automation.id,
209
+ })
210
+
211
+ // Nothing is read off the answer without a check: with no selection
212
+ // it is empty, and in demo mode it is not a delete result at all.
213
+ const deleted = result?.deleted ?? []
214
+ const kept = result?.kept ?? []
215
+ const description = [
216
+ deleted.length > 0 &&
217
+ t('automations.toast.deleted_messages', { names: listNames(deleted) }),
218
+ kept.length > 0 && t('automations.toast.kept_messages', { names: listNames(kept) }),
219
+ ]
220
+ .filter(Boolean)
221
+ .join('\n')
222
+ toast.add({
223
+ title: t('automations.toast.deleted'),
224
+ ...(description && { description }),
225
+ color: kept.length > 0 ? 'warning' : 'success',
226
+ ui: { description: 'whitespace-pre-line' },
227
+ })
228
+ },
229
+ })
230
+ }
231
+
232
+ const { askClone } = useAutomationClone()
233
+
234
+ /** A System Automation cannot be deleted (ADR 0016): its row does not offer it. */
235
+ function getRowActions(automation: Automation) {
236
+ return [
237
+ {
238
+ label: t('common.actions.edit'),
239
+ icon: 'ph:pencil-simple',
240
+ 'data-testid': automationsTestIds.editAction,
241
+ onSelect: () => {
242
+ trackEvent('automation_list.edit', {
243
+ automation_name: automation.name,
244
+ automation_id: automation.id,
245
+ })
246
+ return navigateTo({ name: 'automation-edit', params: { id: automation.id } })
247
+ },
248
+ },
249
+ {
250
+ label: t('common.actions.duplicate'),
251
+ icon: 'ph:copy',
252
+ 'data-testid': automationsTestIds.duplicateAction,
253
+ onSelect: () => {
254
+ trackEvent('automation_list.duplicate', {
255
+ automation_name: automation.name,
256
+ automation_id: automation.id,
257
+ })
258
+ askClone(automation)
259
+ },
260
+ },
261
+ ...(isSystemAutomation(automation)
262
+ ? []
263
+ : [
264
+ {
265
+ label: t('common.actions.delete'),
266
+ icon: 'ph:trash',
267
+ color: 'error' as const,
268
+ 'data-testid': automationsTestIds.deleteAction,
269
+ onSelect: () => askDelete(automation),
270
+ },
271
+ ]),
272
+ ]
273
+ }
274
+ </script>
275
+
276
+ <template>
277
+ <div class="flex-1 space-y-2.5 relative min-h-0 flex flex-col">
278
+ <div class="grid grid-cols-4 items-center gap-3 shrink-0">
279
+ <UInput
280
+ v-model="search"
281
+ type="search"
282
+ leading-icon="ph:magnifying-glass-bold"
283
+ :placeholder="t('automations.list.search')"
284
+ :data-testid="automationsTestIds.searchInput"
285
+ />
286
+ <USelect
287
+ v-model="filterTrigger"
288
+ :items="triggerOptions"
289
+ :data-testid="automationsTestIds.filterTrigger"
290
+ />
291
+ <USelect
292
+ v-model="filterStatus"
293
+ :items="statusOptions"
294
+ :data-testid="automationsTestIds.filterStatus"
295
+ />
296
+ <USelect
297
+ v-model="filterChannel"
298
+ :items="channelOptions"
299
+ :data-testid="automationsTestIds.filterChannel"
300
+ />
301
+ </div>
302
+
303
+ <UCard
304
+ :ui="{
305
+ root: 'flex-1 min-h-0 flex flex-col',
306
+ body: 'overflow-auto relative flex-1 p-0 sm:p-0 relative',
307
+ }"
308
+ >
309
+ <UTable
310
+ v-model:column-pinning="columnPinning"
311
+ v-model:sorting="sorting"
312
+ :row-pinning="rowPinning"
313
+ :get-row-id="(automation: Automation) => automation.id"
314
+ :data="filteredAutomations"
315
+ :columns="columns"
316
+ :loading="isPending"
317
+ :empty="t('automations.list.empty')"
318
+ sticky
319
+ class="flex-1 bg-white"
320
+ :data-testid="automationsTestIds.table"
321
+ :ui="{
322
+ tr: 'hover:bg-muted',
323
+ root: 'overflow-visible static',
324
+ }"
325
+ >
326
+ <template #name-cell="{ row }">
327
+ <div class="flex items-center gap-2">
328
+ <span>{{ row.original.name }}</span>
329
+ <UTooltip
330
+ v-if="isSystemAutomation(row.original)"
331
+ :text="t('automations.system.tooltip')"
332
+ >
333
+ <UBadge
334
+ :label="t('automations.system.badge')"
335
+ color="info"
336
+ variant="subtle"
337
+ size="sm"
338
+ :data-testid="automationsTestIds.lockedBadge"
339
+ />
340
+ </UTooltip>
341
+ </div>
342
+ </template>
343
+
344
+ <template #enabled-cell="{ row }">
345
+ <UBadge
346
+ :label="
347
+ row.original.active ? t('automations.list.active') : t('automations.list.inactive')
348
+ "
349
+ :color="row.original.active ? 'success' : 'neutral'"
350
+ variant="soft"
351
+ :data-testid="automationsTestIds.statusCell"
352
+ />
353
+ </template>
354
+
355
+ <template #channel-cell="{ row }">
356
+ <span :data-testid="automationsTestIds.channelsCell">{{
357
+ getChannels(row.original) || '-'
358
+ }}</span>
359
+ </template>
360
+
361
+ <template #actions-cell="{ row }">
362
+ <SMoreActions
363
+ :actions="getRowActions(row.original)"
364
+ :button-props="{ 'data-testid': automationsTestIds.rowActionsButton }"
365
+ />
366
+ </template>
367
+ </UTable>
368
+ </UCard>
369
+ </div>
370
+ </template>
@@ -0,0 +1,50 @@
1
+ <script setup lang="ts">
2
+ import type { AutomationCatalog } from '@dev.smartpricing/message-composer-utils/types'
3
+ import type { AutomationsContext } from '~/composables/automationsContext'
4
+ import type { AutomationsGate } from '~/composables/useAutomationsGate'
5
+
6
+ /**
7
+ * Shows an Automation page's content once its gate is open, and until then
8
+ * the error alert of the Organization gate and nothing else (ADR 0019).
9
+ */
10
+ defineProps<{ gate: AutomationsGate }>()
11
+
12
+ defineSlots<{
13
+ default(props: { catalog: AutomationCatalog; context: AutomationsContext }): unknown
14
+ }>()
15
+
16
+ const { t } = useI18n()
17
+ </script>
18
+
19
+ <template>
20
+ <slot v-if="gate.state === 'ready'" :catalog="gate.catalog" :context="gate.context" />
21
+
22
+ <div
23
+ v-else-if="gate.state === 'loading'"
24
+ class="flex flex-1 flex-col items-center justify-center gap-3 py-12 text-muted"
25
+ role="status"
26
+ >
27
+ <UIcon name="i-heroicons-arrow-path" class="animate-spin h-8 w-8" />
28
+ </div>
29
+
30
+ <UAlert
31
+ v-else
32
+ color="error"
33
+ variant="subtle"
34
+ icon="i-lucide-alert-triangle"
35
+ :title="gate.title"
36
+ :description="gate.description"
37
+ :actions="
38
+ gate.retry
39
+ ? [
40
+ {
41
+ label: t('common.organization.retry'),
42
+ color: 'error',
43
+ variant: 'outline',
44
+ onClick: gate.retry,
45
+ },
46
+ ]
47
+ : undefined
48
+ "
49
+ />
50
+ </template>
@@ -0,0 +1,54 @@
1
+ <script setup lang="ts">
2
+ import type { AutomationProblemLine } from '~/composables/useAutomationSaveProblems'
3
+
4
+ /** The alert at the top of the Automation form: why the last save went nowhere. */
5
+ defineProps<{
6
+ /** What a refused save said, each line with the place it is about. */
7
+ lines: AutomationProblemLine[]
8
+ /** The form was submitted with something required missing. */
9
+ incomplete?: boolean
10
+ }>()
11
+
12
+ const { t } = useI18n()
13
+
14
+ function scrollTo(line: AutomationProblemLine) {
15
+ if (!line.target) return
16
+ document.getElementById(line.target)?.scrollIntoView({ behavior: 'smooth', block: 'center' })
17
+ }
18
+ </script>
19
+
20
+ <template>
21
+ <UAlert
22
+ v-if="lines.length > 0"
23
+ color="error"
24
+ variant="soft"
25
+ icon="ph:warning-circle-bold"
26
+ :title="t('automations.problems.title')"
27
+ :data-testid="automationsTestIds.errorAlert"
28
+ >
29
+ <template #description>
30
+ <ul class="space-y-1">
31
+ <li v-for="(line, index) in lines" :key="index" class="flex items-baseline gap-2">
32
+ <span>{{ line.text }}</span>
33
+ <UButton
34
+ v-if="line.target"
35
+ variant="link"
36
+ color="error"
37
+ size="sm"
38
+ class="p-0 underline"
39
+ :label="t('automations.problems.show')"
40
+ @click="scrollTo(line)"
41
+ />
42
+ </li>
43
+ </ul>
44
+ </template>
45
+ </UAlert>
46
+ <UAlert
47
+ v-else-if="incomplete"
48
+ color="error"
49
+ variant="soft"
50
+ icon="ph:warning-circle-bold"
51
+ :title="t('automations.form.error_banner')"
52
+ :data-testid="automationsTestIds.errorAlert"
53
+ />
54
+ </template>
@@ -0,0 +1,71 @@
1
+ <script setup lang="ts">
2
+ import type { AutomationUnavailableItem } from '../../utils/automations/unavailable'
3
+
4
+ /**
5
+ * The summary of what an Automation holds that is no longer available: what
6
+ * must be fixed before saving, and what is only kept. An error while
7
+ * something blocks the save, a warning otherwise, nothing when the list is
8
+ * empty. The Automation form shows it at its top, the filter editor and the
9
+ * Action editor at theirs.
10
+ */
11
+ const props = defineProps<{
12
+ items: AutomationUnavailableItem[]
13
+ /** Shown where the things are: no "Show" link. */
14
+ inPlace?: boolean
15
+ }>()
16
+
17
+ const emit = defineEmits<{ show: [item: AutomationUnavailableItem] }>()
18
+
19
+ const { t } = useI18n()
20
+
21
+ const groups = computed(() =>
22
+ [
23
+ {
24
+ title: t('automations.unavailable.to_fix'),
25
+ items: props.items.filter((item) => item.blocks),
26
+ },
27
+ {
28
+ title: t('automations.unavailable.kept'),
29
+ items: props.items.filter((item) => !item.blocks),
30
+ },
31
+ ].filter((group) => group.items.length > 0),
32
+ )
33
+
34
+ const blocked = computed(() => props.items.some((item) => item.blocks))
35
+ </script>
36
+
37
+ <template>
38
+ <UAlert
39
+ v-if="items.length > 0"
40
+ :color="blocked ? 'error' : 'warning'"
41
+ variant="soft"
42
+ :icon="blocked ? 'ph:warning-circle-bold' : 'ph:warning-bold'"
43
+ :title="
44
+ blocked ? t('automations.unavailable.title_blocked') : t('automations.unavailable.title_kept')
45
+ "
46
+ data-testid="automation-unavailable"
47
+ >
48
+ <template #description>
49
+ <div class="space-y-3">
50
+ <div v-for="group in groups" :key="group.title">
51
+ <p class="label-sm">{{ group.title }}</p>
52
+ <ul class="mt-1 space-y-1">
53
+ <li v-for="item in group.items" :key="item.key">
54
+ <span class="font-semibold">{{ item.where }}:</span>
55
+ {{ item.text }}
56
+ <UButton
57
+ v-if="!inPlace && item.target"
58
+ variant="link"
59
+ :color="blocked ? 'error' : 'warning'"
60
+ size="sm"
61
+ class="p-0 underline"
62
+ :label="t('automations.problems.show')"
63
+ @click="emit('show', item)"
64
+ />
65
+ </li>
66
+ </ul>
67
+ </div>
68
+ </div>
69
+ </template>
70
+ </UAlert>
71
+ </template>
@@ -0,0 +1,35 @@
1
+ <script setup lang="ts">
2
+ import type { AutomationUnavailableItem } from '../../utils/automations/unavailable'
3
+
4
+ /** An unavailable thing marked where it is: a small badge, its sentence in a tooltip. */
5
+ defineProps<{
6
+ item: AutomationUnavailableItem
7
+ }>()
8
+
9
+ const { t } = useI18n()
10
+
11
+ const LABEL_KEYS: Record<AutomationUnavailableItem['kind'], string> = {
12
+ trigger: 'unavailable',
13
+ date_reference: 'unavailable',
14
+ condition_unknown_field: 'unavailable',
15
+ condition_not_editable: 'unavailable',
16
+ option: 'unavailable',
17
+ channel: 'not_set_up',
18
+ message_group_inactive: 'not_approved',
19
+ message_group_active: 'not_approved',
20
+ }
21
+ </script>
22
+
23
+ <template>
24
+ <UTooltip :text="item.text">
25
+ <UBadge
26
+ :color="item.blocks ? 'error' : 'warning'"
27
+ variant="subtle"
28
+ size="sm"
29
+ class="shrink-0"
30
+ :data-testid="`automation-unavailable-badge-${item.kind}`"
31
+ >
32
+ {{ t(`automations.unavailable.badges.${LABEL_KEYS[item.kind]}`) }}
33
+ </UBadge>
34
+ </UTooltip>
35
+ </template>
@@ -3,8 +3,8 @@ import { useAppContextStore } from '~/stores/appContext'
3
3
 
4
4
  /**
5
5
  * Host-integration problems reported by the app-context store (missing
6
- * Product, missing Meta config, ...). Shown persistently: the host has to fix
7
- * its context, the user cannot.
6
+ * Product, ...). Shown persistently: the host has to fix its context, the
7
+ * user cannot.
8
8
  */
9
9
  const { validationErrors } = storeToRefs(useAppContextStore())
10
10
  const messages = computed(() => Object.values(validationErrors.value))
@@ -35,6 +35,8 @@ const ELIGIBILITY_RULES: Record<
35
35
  * menu's search input; pages of 100 load on demand through "Load more".
36
36
  * The selected group stays in the menu even when the loaded pages no longer
37
37
  * contain it (search cleared, paging reset, or preselected beyond page one).
38
+ * A selected group that cannot be picked is still shown, with its status and
39
+ * whatever the hide filter says: it was selected elsewhere, not offered here.
38
40
  */
39
41
  const props = withDefaults(
40
42
  defineProps<{
@@ -60,6 +62,10 @@ const props = withDefaults(
60
62
  * follow the mode.
61
63
  */
62
64
  eligibility?: MessageGroupEligibility
65
+ /** Lists this Organization's groups instead of the resolved Organization's. */
66
+ organizationId?: string
67
+ /** Lists only the WhatsApp groups on this WABA (ADR 0015); needs `renderType: 'whatsapp_v1'`. */
68
+ wabaId?: string
63
69
  }>(),
64
70
  {
65
71
  placeholder: 'Select a message group',
@@ -88,13 +94,18 @@ const appContext = useAppContextStore()
88
94
 
89
95
  // Server-side search: the menu's own client filter is off (`ignore-filter`),
90
96
  // the typed term reaches the list request once it settles. A new search,
91
- // render type or context Product starts over from page one.
97
+ // render type, context Product or WABA starts over from page one.
92
98
  const searchTerm = ref('')
93
99
  const page = ref(1)
94
100
 
95
101
  // Without a context Product the server would answer with every Product's
96
102
  // groups (ADR 0011): never ask. The host's missing Product is already reported
97
103
  // by the app-context validation.
104
+ // Only WhatsApp groups are on a WABA: with any other render type the filter would empty the list.
105
+ const wabaFilter = computed(() =>
106
+ props.renderType === 'whatsapp_v1' ? props.wabaId || undefined : undefined,
107
+ )
108
+
98
109
  const {
99
110
  query: { data: envelope, isPlaceholderData },
100
111
  loading,
@@ -106,9 +117,11 @@ const {
106
117
  filters: () => ({
107
118
  product: appContext.product,
108
119
  visibility: appContext.isAdmin ? 'all' : 'public',
120
+ waba_id: wabaFilter.value,
109
121
  }),
110
- resetOn: [() => appContext.product],
122
+ resetOn: [() => appContext.product, wabaFilter],
111
123
  enabled: () => appContext.product != null,
124
+ organizationId: () => props.organizationId,
112
125
  })
113
126
 
114
127
  // Pages loaded so far, indexed by page number: page one replaces everything,
@@ -175,7 +188,7 @@ const items = computed(() => {
175
188
  const externalReason = props.disabledGroupReasons?.[group.id]
176
189
  const eligible = rule.value.isEligible(group.messages)
177
190
  const disabled = !eligible || externalReason != null
178
- if (hideIneligible.value && disabled) return acc
191
+ if (hideIneligible.value && disabled && group.id !== modelValue.value) return acc
179
192
  // External reason wins over the mode's own tooltip when both apply.
180
193
  let tooltip: string | undefined
181
194
  if (externalReason != null) tooltip = externalReason
@@ -191,6 +204,21 @@ const items = computed(() => {
191
204
  }, [])
192
205
  })
193
206
 
207
+ // What keeps a group from being eligible, worst first.
208
+ const BLOCKING_STATUSES = ['rejected', 'pending', 'draft'] as const
209
+ const STATUS_COLORS = { rejected: 'error', pending: 'warning', draft: 'neutral' } as const
210
+
211
+ /** The selected group when it fails the mode's rule, with the status that says why. */
212
+ const selectedIneligible = computed(() => {
213
+ const group = messageGroups.value.find((g) => g.id === modelValue.value)
214
+ if (!group || rule.value.isEligible(group.messages)) return undefined
215
+ // A group with no Message has nothing past a draft.
216
+ const status =
217
+ BLOCKING_STATUSES.find((candidate) => group.messages.some((m) => m.status === candidate)) ??
218
+ 'draft'
219
+ return { name: group.name, status, color: STATUS_COLORS[status] }
220
+ })
221
+
194
222
  function handleUpdate(value: string) {
195
223
  modelValue.value = value
196
224
  const group = messageGroups.value.find((g) => g.id === value)
@@ -213,6 +241,18 @@ function handleUpdate(value: string) {
213
241
  :data-testid="messageGroupSelectTestIds.root"
214
242
  @update:model-value="handleUpdate"
215
243
  >
244
+ <template v-if="selectedIneligible" #default>
245
+ <span class="truncate">{{ selectedIneligible.name }}</span>
246
+ <UBadge
247
+ leading-icon="ph:circle-fill"
248
+ :label="t(`status.${selectedIneligible.status}`)"
249
+ size="sm"
250
+ :color="selectedIneligible.color"
251
+ variant="outline"
252
+ class="shrink-0"
253
+ />
254
+ </template>
255
+
216
256
  <template #item-label="{ item }">
217
257
  <UTooltip v-if="item.disabled" :text="item.tooltip">
218
258
  <span class="text-muted">{{ item.label }}</span>