@dev.smartpricing/message-composer-layer 4.3.2-fix.1 → 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 (119) hide show
  1. package/README.md +357 -46
  2. package/app/api/automations.ts +74 -0
  3. package/app/api/brands.ts +20 -13
  4. package/app/api/client.ts +15 -6
  5. package/app/api/compilation.ts +13 -3
  6. package/app/api/dynamicValues.ts +6 -2
  7. package/app/api/index.ts +1 -0
  8. package/app/api/media.ts +6 -3
  9. package/app/api/messageGroups.ts +34 -15
  10. package/app/api/meta.ts +62 -4
  11. package/app/api/organization.ts +10 -1
  12. package/app/api/tracking.ts +2 -2
  13. package/app/app.config.ts +10 -0
  14. package/app/components/Automations/ActionCard.vue +174 -0
  15. package/app/components/Automations/ActionEditor.vue +398 -0
  16. package/app/components/Automations/Actions.vue +158 -0
  17. package/app/components/Automations/CloneModal.vue +78 -0
  18. package/app/components/Automations/Conditions.vue +155 -0
  19. package/app/components/Automations/Create.vue +114 -0
  20. package/app/components/Automations/Data.vue +46 -0
  21. package/app/components/Automations/DeleteModal.vue +80 -0
  22. package/app/components/Automations/Edit.vue +145 -0
  23. package/app/components/Automations/Form.vue +282 -0
  24. package/app/components/Automations/List.vue +370 -0
  25. package/app/components/Automations/PageGate.vue +50 -0
  26. package/app/components/Automations/SaveProblems.vue +54 -0
  27. package/app/components/Automations/Unavailable.vue +71 -0
  28. package/app/components/Automations/UnavailableBadge.vue +35 -0
  29. package/app/components/Common/AppContextErrors.vue +30 -0
  30. package/app/components/Common/HtmlPreviewIframe.vue +17 -3
  31. package/app/components/Common/MessageGroupSelect.vue +193 -26
  32. package/app/components/Common/MessagePreviewSlideover.vue +3 -0
  33. package/app/components/Common/OrganizationGate.vue +51 -0
  34. package/app/components/Common/OrganizationSelect.vue +27 -0
  35. package/app/components/Common/WhatsappNotConfigured.vue +20 -0
  36. package/app/components/Composer/EmailComposer.vue +9 -1
  37. package/app/components/Composer/MessageLibrary.vue +25 -7
  38. package/app/components/Composer/WabaSelectModal.vue +73 -0
  39. package/app/components/Composer/WhatsappComposer.vue +83 -4
  40. package/app/components/Editor/RichTextEditor.vue +14 -2
  41. package/app/components/Filters/DateInput.vue +57 -0
  42. package/app/components/Filters/Editor.vue +163 -0
  43. package/app/components/Filters/Row.vue +119 -0
  44. package/app/components/Filters/Summary.vue +215 -0
  45. package/app/components/Filters/UnavailableRow.vue +74 -0
  46. package/app/components/Filters/ValueInput.vue +215 -0
  47. package/app/components/Layout/BasePage.vue +2 -0
  48. package/app/components/MessageSendFlow/EmailPreview.vue +81 -0
  49. package/app/components/MessageSendFlow/LanguageSelect.vue +39 -0
  50. package/app/components/MessageSendFlow/MessageSendFlow.vue +265 -0
  51. package/app/components/MessageSendFlow/ParametersForm.vue +51 -0
  52. package/app/components/MetaImport/Button.vue +50 -0
  53. package/app/components/MetaImport/Dialog.vue +261 -0
  54. package/app/components/MetaImport/Outcome.vue +136 -0
  55. package/app/components/MetaImport/ProposalList.vue +192 -0
  56. package/app/components/TemplateList/BaseTable.vue +177 -108
  57. package/app/components/Whatsapp/Preview.vue +17 -16
  58. package/app/components/Whatsapp/PreviewPanel.vue +7 -1
  59. package/app/components/Whatsapp/Translator/Header.vue +4 -19
  60. package/app/composables/apiErrorMessages.ts +1 -0
  61. package/app/composables/automationsContext.ts +42 -0
  62. package/app/composables/composerContext.ts +9 -7
  63. package/app/composables/useAutomationClone.ts +33 -0
  64. package/app/composables/useAutomationEditorTrip.ts +77 -0
  65. package/app/composables/useAutomationSaveProblems.ts +82 -0
  66. package/app/composables/useAutomationUnavailable.ts +98 -0
  67. package/app/composables/useAutomationsGate.ts +68 -0
  68. package/app/composables/useBuiltInOptionLists.ts +44 -0
  69. package/app/composables/useEditorTripBack.ts +15 -0
  70. package/app/composables/useEffectiveOrganization.ts +34 -0
  71. package/app/composables/useMessageGroupList.ts +186 -0
  72. package/app/composables/useMessageGroupWaba.ts +76 -0
  73. package/app/composables/useMessageSendFlow.ts +284 -0
  74. package/app/composables/usePagedMessageGroups.ts +78 -0
  75. package/app/composables/useTemplateOperations.ts +31 -7
  76. package/app/composables/useTracking.ts +14 -5
  77. package/app/composables/useWhatsappConfiguration.ts +32 -0
  78. package/app/layouts/default.vue +5 -1
  79. package/app/middleware/automations-enabled.ts +12 -0
  80. package/app/pages/automations/[id].vue +87 -0
  81. package/app/pages/automations/index.vue +28 -0
  82. package/app/pages/automations/new.vue +53 -0
  83. package/app/pages/brands.vue +1 -0
  84. package/app/pages/images.vue +4 -0
  85. package/app/pages/index.vue +6 -1
  86. package/app/pages/preview/[id].vue +2 -0
  87. package/app/pages/template/email/[id].vue +5 -0
  88. package/app/pages/template/email/create.vue +5 -0
  89. package/app/pages/template/whatsapp/[id].vue +6 -0
  90. package/app/pages/template/whatsapp/create.vue +5 -0
  91. package/app/queries/automations.ts +206 -0
  92. package/app/queries/brands.ts +27 -7
  93. package/app/queries/compilation.ts +16 -3
  94. package/app/queries/dynamicValues.ts +19 -2
  95. package/app/queries/index.ts +1 -0
  96. package/app/queries/media.ts +8 -3
  97. package/app/queries/messageGroups.ts +84 -36
  98. package/app/queries/meta.ts +100 -5
  99. package/app/stores/appContext.ts +18 -48
  100. package/app/stores/editorTrip.ts +67 -0
  101. package/app/stores/effectiveOrganization.ts +128 -0
  102. package/app/stores/emailEditor.ts +5 -1
  103. package/app/stores/metaSubmission.ts +7 -17
  104. package/app/types/app-config.d.ts +3 -0
  105. package/app/types/tracking.ts +50 -0
  106. package/app/utils/automations/form.ts +389 -0
  107. package/app/utils/automations/metadata.ts +71 -0
  108. package/app/utils/automations/unavailable.ts +90 -0
  109. package/app/utils/filters/data/countries.json +998 -0
  110. package/app/utils/filters/data/languages.json +754 -0
  111. package/app/utils/filters/rows.ts +367 -0
  112. package/app/utils/testIds.const.ts +137 -0
  113. package/i18n/locales/de.ts +419 -2
  114. package/i18n/locales/en.ts +398 -2
  115. package/i18n/locales/es.ts +403 -2
  116. package/i18n/locales/fr.ts +410 -2
  117. package/i18n/locales/it.ts +409 -2
  118. package/package.json +4 -4
  119. package/app.config.ts +0 -5
@@ -1,16 +1,37 @@
1
1
  <script setup lang="ts">
2
2
  import {
3
3
  MESSAGE_GROUP_CATEGORIES,
4
+ MESSAGE_GROUP_LIST_VISIBILITY,
5
+ MESSAGE_GROUP_PRODUCTS,
4
6
  MESSAGE_STATUS,
7
+ type MessageGroupListSort,
8
+ type MessageGroupProduct,
5
9
  type MessageGroupWithMessageSummary,
10
+ type PaginationMeta,
6
11
  type RenderType,
7
12
  } from '@dev.smartpricing/message-composer-utils/types'
8
13
  import StatusCell from '@/components/TemplateList/StatusCell.vue'
9
14
  import { useI18n } from 'vue-i18n'
10
- import { ref, watch } from 'vue'
15
+ import { computed, ref, watch } from 'vue'
11
16
  import { formatDate } from '@dev.smartpricing/message-composer-utils/utils'
12
17
  import type { TableColumn } from '#ui/types'
13
18
  import type { TrackingEventMap } from '@/types/tracking'
19
+ import {
20
+ ALL_FILTER,
21
+ type MessageGroupListFilters,
22
+ type MessageGroupListSorting,
23
+ } from '@/composables/useMessageGroupList'
24
+
25
+ const props = defineProps<{
26
+ messageGroups: MessageGroupWithMessageSummary[]
27
+ /** Envelope meta of the current page; undefined until the first page arrives. */
28
+ meta?: PaginationMeta
29
+ loading: boolean
30
+ renderType: RenderType
31
+ filters: MessageGroupListFilters
32
+ sorting: MessageGroupListSorting
33
+ page: number
34
+ }>()
14
35
 
15
36
  const emit = defineEmits<{
16
37
  edit: [MessageGroupWithMessageSummary]
@@ -18,6 +39,9 @@ const emit = defineEmits<{
18
39
  duplicate: [MessageGroupWithMessageSummary]
19
40
  publish: [MessageGroupWithMessageSummary]
20
41
  unpublish: [MessageGroupWithMessageSummary]
42
+ 'update:filters': [Partial<MessageGroupListFilters>]
43
+ 'update:sorting': [MessageGroupListSorting]
44
+ 'update:page': [number]
21
45
  }>()
22
46
 
23
47
  const appContext = useAppContextStore()
@@ -86,49 +110,40 @@ function rowActions(row: MessageGroupWithMessageSummary) {
86
110
  ]
87
111
  }
88
112
 
113
+ // Column ids of sortable columns are the server's `sort` values (ADR 0012);
114
+ // preview and status are aggregates and stay unsortable.
89
115
  const columns: TableColumn<MessageGroupWithMessageSummary>[] = [
90
116
  {
91
- id: 'name',
117
+ id: 'name' satisfies MessageGroupListSort,
92
118
  accessorKey: 'name',
93
119
  header: (ctx) => getSortableHeader(ctx, t('pages.message_library.headers.name')),
94
120
  },
95
121
  {
96
- id: 'category',
122
+ id: 'category' satisfies MessageGroupListSort,
97
123
  accessorKey: 'category',
98
124
  header: (ctx) => getSortableHeader(ctx, t('pages.message_library.headers.category')),
99
- filterFn: (row, columnId, filterValue) => {
100
- if (filterValue === 'all') return true
101
- return row.original.category.toLowerCase().includes(filterValue.toLowerCase())
102
- },
125
+ },
126
+ {
127
+ id: 'product',
128
+ accessorKey: 'product',
129
+ enableSorting: false,
130
+ header: () => t('pages.message_library.headers.product'),
103
131
  },
104
132
  {
105
133
  id: 'preview',
106
134
  accessorFn: (row) => getLocalizedMessage(row)?.preview,
107
- header: (ctx) => getSortableHeader(ctx, t('pages.message_library.headers.preview')),
135
+ enableSorting: false,
136
+ header: () => t('pages.message_library.headers.preview'),
108
137
  },
109
138
  {
110
139
  id: 'status',
111
140
  accessorFn: (row) => row.messages.map((m) => m.status).join(', '),
112
- header: (ctx) => getSortableHeader(ctx, t('pages.message_library.headers.status')),
113
- filterFn: (row, columnId, filterValue) => {
114
- if (filterValue === 'all') return true
115
- return row.original.messages.some((m) => m.status === filterValue)
116
- },
141
+ enableSorting: false,
142
+ header: () => t('pages.message_library.headers.status'),
117
143
  },
118
- // {
119
- // id: 'tags',
120
- // accessorFn: (row) => row.tags?.join(', ') || '',
121
- // header: (ctx) => getSortableHeader(ctx, t('pages.message_library.headers.tags')),
122
- // filterFn: (row, _columnId, filterValue: string[]) => {
123
- // if (!filterValue || filterValue.length === 0) return true
124
- // const rowTags = row.original.tags || []
125
- // return filterValue.some((tag) => rowTags.includes(tag))
126
- // },
127
- // },
128
144
  {
129
- id: 'updated_at',
145
+ id: 'updated_at' satisfies MessageGroupListSort,
130
146
  accessorFn: (row) => formatDate(row.updated_at),
131
- // header: () => t('pages.message_library.headers.updated_at'),
132
147
  header: (ctx) => getSortableHeader(ctx, t('pages.message_library.headers.updated_at')),
133
148
  },
134
149
  {
@@ -144,77 +159,79 @@ const columns: TableColumn<MessageGroupWithMessageSummary>[] = [
144
159
  },
145
160
  ]
146
161
 
147
- const sorting = ref([
148
- {
149
- id: 'updated_at',
150
- desc: true,
151
- },
152
- ])
162
+ // The table's sorting model mirrors the server sort; TanStack never sorts locally (manualSorting).
163
+ function toTableSorting(sorting: MessageGroupListSorting) {
164
+ return [{ id: sorting.sort, desc: sorting.order === 'desc' }]
165
+ }
153
166
 
154
- const props = defineProps<{
155
- messageGroups: MessageGroupWithMessageSummary[]
156
- loading: boolean
157
- renderType: RenderType
158
- }>()
167
+ const sorting = ref(toTableSorting(props.sorting))
159
168
 
160
- const filteredMessageGroups = computed(() => {
161
- if (appContext.isAdmin) return props.messageGroups
162
- return props.messageGroups.filter((mg) => mg.visibility !== 'internal')
163
- })
169
+ watch(
170
+ () => props.sorting,
171
+ (value) => {
172
+ sorting.value = toTableSorting(value)
173
+ },
174
+ )
164
175
 
165
- const categoryItems = computed(() => {
166
- return [
167
- {
168
- label: t('common.all'),
169
- value: 'all',
170
- },
171
- ...MESSAGE_GROUP_CATEGORIES.map((category) => ({
172
- label: t(`categories.${category}`),
173
- value: category,
174
- })),
175
- ]
176
+ watch(sorting, (val) => {
177
+ const [first] = val
178
+ if (!first) return
179
+ const next: MessageGroupListSorting = {
180
+ sort: first.id as MessageGroupListSort,
181
+ order: first.desc ? 'desc' : 'asc',
182
+ }
183
+ if (next.sort === props.sorting.sort && next.order === props.sorting.order) return
184
+ emit('update:sorting', next)
185
+ trackEvent('table_sorting', {
186
+ messages_kind: messagesKind.value,
187
+ sort_column: next.sort,
188
+ })
176
189
  })
177
190
 
178
- const statusItems = computed(() => {
191
+ // Select items: the "all" entry first, then one translated entry per enum value.
192
+ function toSelectItems<T extends string>(
193
+ values: readonly T[],
194
+ keyPrefix: string,
195
+ allLabel: string,
196
+ ) {
179
197
  return [
180
- {
181
- label: t('common.all'),
182
- value: 'all',
183
- },
184
-
185
- ...MESSAGE_STATUS.map((status) => ({
186
- label: t(`status.${status}`),
187
- value: status,
188
- })),
198
+ { label: allLabel, value: ALL_FILTER },
199
+ ...values.map((value) => ({ label: t(`${keyPrefix}.${value}`), value })),
189
200
  ]
190
- })
191
-
192
- // const tagItems = computed(() => {
193
- // const allTags = new Set<string>()
194
- // messageGroups.forEach((mg) => mg.tags?.forEach((tag) => allTags.add(tag)))
195
- // return [...allTags].sort()
196
- // })
197
-
198
- // const selectedTags = ref<string[]>([])
201
+ }
199
202
 
200
- const table = useTemplateRef('table')
203
+ const categoryItems = computed(() =>
204
+ toSelectItems(MESSAGE_GROUP_CATEGORIES, 'categories', t('common.all')),
205
+ )
206
+ const statusItems = computed(() => toSelectItems(MESSAGE_STATUS, 'status', t('common.all')))
207
+ // Only the Products that have Message Groups today. The Host's own Product
208
+ // is always offered, since the filter starts on it.
209
+ const PRODUCTS_WITH_MESSAGES: readonly MessageGroupProduct[] = ['connect', 'chat']
210
+ const productItems = computed(() =>
211
+ toSelectItems(
212
+ MESSAGE_GROUP_PRODUCTS.filter(
213
+ (product) => PRODUCTS_WITH_MESSAGES.includes(product) || product === appContext.product,
214
+ ),
215
+ 'products',
216
+ t('pages.message_library.all_products'),
217
+ ),
218
+ )
219
+
220
+ const visibilityItems = computed(() =>
221
+ MESSAGE_GROUP_LIST_VISIBILITY.map((visibility) => ({
222
+ label: t(`pages.message_library.visibility.${visibility}`),
223
+ value: visibility,
224
+ })),
225
+ )
201
226
 
202
227
  const messagesKind = computed(() => (props.renderType === 'email_v1' ? 'email' : 'whatsapp'))
203
228
 
204
- watch(sorting, (val) => {
205
- if (val[0]) {
206
- trackEvent('table_sorting', {
207
- messages_kind: messagesKind.value,
208
- sort_column: val[0].id,
209
- })
210
- }
211
- })
212
-
213
229
  function trackFilters(overrides: Partial<TrackingEventMap['change_filters']> = {}) {
214
230
  trackEvent('change_filters', {
215
- search_term: (table.value?.tableApi?.getColumn('name')?.getFilterValue() as string) || '',
216
- category: (table.value?.tableApi?.getColumn('category')?.getFilterValue() as string) || '',
217
- status: (table.value?.tableApi?.getColumn('status')?.getFilterValue() as string) || '',
231
+ search_term: props.filters.search,
232
+ category: props.filters.category,
233
+ status: props.filters.status,
234
+ product: props.filters.product,
218
235
  messages_kind: messagesKind.value,
219
236
  ...overrides,
220
237
  })
@@ -225,19 +242,24 @@ const trackSearchFilter = useDebounceFn((value: string) => {
225
242
  }, 500)
226
243
 
227
244
  function onSearchInput(value: string) {
228
- table.value?.tableApi?.getColumn('name')?.setFilterValue(value)
245
+ emit('update:filters', { search: value })
229
246
  trackSearchFilter(value)
230
247
  }
231
248
 
232
- function onCategoryFilter(value: string) {
233
- table.value?.tableApi?.getColumn('category')?.setFilterValue(value)
234
- trackFilters({ category: value })
249
+ // USelect emits the option value as a plain string; the items are built from the typed enums.
250
+ function onFilter(key: Exclude<keyof MessageGroupListFilters, 'search'>, value: string) {
251
+ emit('update:filters', { [key]: value } as Partial<MessageGroupListFilters>)
252
+ if (key !== 'visibility') trackFilters({ [key]: value })
235
253
  }
236
254
 
237
- function onStatusFilter(value: string) {
238
- table.value?.tableApi?.getColumn('status')?.setFilterValue(value)
239
- trackFilters({ status: value })
240
- }
255
+ const paginationSummary = computed(() => {
256
+ if (!props.meta || props.meta.from === null || props.meta.to === null) return ''
257
+ return t('pages.message_library.pagination_summary', {
258
+ from: props.meta.from,
259
+ to: props.meta.to,
260
+ total: props.meta.total,
261
+ })
262
+ })
241
263
  </script>
242
264
 
243
265
  <template>
@@ -247,38 +269,46 @@ function onStatusFilter(value: string) {
247
269
  >
248
270
  <div class="flex gap-2">
249
271
  <UInput
250
- :model-value="table?.tableApi?.getColumn('name')?.getFilterValue() as string"
272
+ :model-value="filters.search"
251
273
  class="max-w-xs"
252
274
  leading-icon="ph:magnifying-glass-bold"
253
275
  :placeholder="t('pages.message_library.search_placeholder')"
254
276
  :data-testid="templateListTableTestIds.searchInput"
255
- @update:model-value="onSearchInput($event)"
277
+ @update:model-value="onSearchInput(String($event))"
256
278
  />
257
279
  <USelect
258
- :model-value="table?.tableApi?.getColumn('category')?.getFilterValue() as string"
280
+ :model-value="filters.category"
259
281
  class="max-w-48"
260
282
  :placeholder="t('pages.message_library.category_placeholder')"
261
283
  :items="categoryItems"
262
284
  :data-testid="templateListTableTestIds.categorySelect"
263
- @update:model-value="onCategoryFilter($event)"
285
+ @update:model-value="onFilter('category', $event)"
264
286
  />
265
287
  <USelect
266
- :model-value="table?.tableApi?.getColumn('status')?.getFilterValue() as string"
288
+ :model-value="filters.status"
267
289
  class="max-w-48"
268
290
  :placeholder="t('pages.message_library.status_placeholder')"
269
291
  :items="statusItems"
270
292
  :data-testid="templateListTableTestIds.statusSelect"
271
- @update:model-value="onStatusFilter($event)"
293
+ @update:model-value="onFilter('status', $event)"
294
+ />
295
+ <USelect
296
+ :model-value="filters.product"
297
+ class="max-w-48"
298
+ :placeholder="t('pages.message_library.product_placeholder')"
299
+ :items="productItems"
300
+ :data-testid="templateListTableTestIds.productSelect"
301
+ @update:model-value="onFilter('product', $event)"
302
+ />
303
+ <USelect
304
+ v-if="appContext.isAdmin"
305
+ :model-value="filters.visibility"
306
+ class="max-w-48"
307
+ :placeholder="t('pages.message_library.visibility_placeholder')"
308
+ :items="visibilityItems"
309
+ :data-testid="templateListTableTestIds.visibilitySelect"
310
+ @update:model-value="onFilter('visibility', $event)"
272
311
  />
273
- <!-- <USelectMenu
274
- v-if="tagItems.length > 0"
275
- v-model="selectedTags"
276
- :items="tagItems"
277
- multiple
278
- class="max-w-48"
279
- :placeholder="t('pages.message_library.tags_placeholder')"
280
- @update:model-value="table?.tableApi?.getColumn('tags')?.setFilterValue($event)"
281
- /> -->
282
312
  </div>
283
313
 
284
314
  <UCard
@@ -295,13 +325,24 @@ function onStatusFilter(value: string) {
295
325
  tr: 'hover:bg-muted',
296
326
  root: 'overflow-visible static',
297
327
  }"
298
- :data="filteredMessageGroups"
328
+ :data="messageGroups"
299
329
  :columns="columns"
330
+ :sorting-options="{ manualSorting: true, enableSortingRemoval: false }"
300
331
  sticky
301
- ref="table"
302
332
  v-model:sorting="sorting"
303
333
  :data-testid="templateListTableTestIds.table"
304
334
  >
335
+ <!-- Shown instead of the "no data" row while a list with no rows is loading. -->
336
+ <template #loading>
337
+ <div
338
+ class="flex items-center justify-center gap-2 text-muted"
339
+ :data-testid="templateListTableTestIds.loading"
340
+ >
341
+ <UIcon name="ph:circle-notch-bold" class="size-4 animate-spin" />
342
+ <span>{{ t('pages.message_library.loading') }}</span>
343
+ </div>
344
+ </template>
345
+
305
346
  <template #name-cell="{ row }">
306
347
  <div
307
348
  class="flex items-center gap-2"
@@ -329,6 +370,16 @@ function onStatusFilter(value: string) {
329
370
  />
330
371
  </template>
331
372
 
373
+ <template #product-cell="{ row }">
374
+ <UBadge
375
+ :label="t(`products.${row.original.product}`)"
376
+ size="md"
377
+ color="neutral"
378
+ variant="outline"
379
+ :data-testid="`${templateListTableTestIds.rowProductBadge}-${row.original.id}`"
380
+ />
381
+ </template>
382
+
332
383
  <template #status-cell="{ row }">
333
384
  <StatusCell :items="row.original.messages" />
334
385
  </template>
@@ -349,6 +400,24 @@ function onStatusFilter(value: string) {
349
400
  />
350
401
  </template>
351
402
  </UTable>
403
+
404
+ <template v-if="meta" #footer>
405
+ <div class="flex items-center justify-between gap-4">
406
+ <span
407
+ class="text-sm text-muted"
408
+ :data-testid="templateListTableTestIds.paginationSummary"
409
+ >
410
+ {{ paginationSummary }}
411
+ </span>
412
+ <UPagination
413
+ :page="page"
414
+ :total="meta.total"
415
+ :items-per-page="meta.per_page"
416
+ :data-testid="templateListTableTestIds.pagination"
417
+ @update:page="emit('update:page', $event)"
418
+ />
419
+ </div>
420
+ </template>
352
421
  </UCard>
353
422
  </div>
354
423
  </template>
@@ -4,12 +4,10 @@ import type {
4
4
  WaButtonTypeV1,
5
5
  WhatsappMessage,
6
6
  } from '@dev.smartpricing/message-composer-utils/types'
7
- import { generateHTML } from '@tiptap/vue-3'
8
7
  import { computed } from 'vue'
9
8
  import {
9
+ convertToWhatsappHeaderText,
10
10
  generateWhatsappHtml,
11
- getTipTapExtensions,
12
- sanitizeContent,
13
11
  } from '@dev.smartpricing/message-composer-utils/utils'
14
12
  import { useResolvedParametersQuery } from '~/queries/compilation'
15
13
 
@@ -20,6 +18,13 @@ defineOptions({
20
18
  const props = defineProps<{
21
19
  message: PostEntity<WhatsappMessage>
22
20
  messageGroupId: string
21
+ /**
22
+ * Parameter values that override the resolved (organization-level) ones,
23
+ * e.g. what an operator typed in a Message Send Flow. Non-empty values win,
24
+ * keys not in the map keep the resolved value, an empty string shows the raw
25
+ * `{{key}}` placeholder (as an empty resolved value always did).
26
+ */
27
+ parameters?: Record<string, string>
23
28
  }>()
24
29
 
25
30
  const { data: resolvedParams } = useResolvedParametersQuery(
@@ -28,13 +33,14 @@ const { data: resolvedParams } = useResolvedParametersQuery(
28
33
  )
29
34
 
30
35
  function replaceMentionsWithValues(html: string): string {
31
- const dynamicData = resolvedParams.value?.parameters
32
- if (!dynamicData) return html
36
+ const dynamicData = { ...resolvedParams.value?.parameters, ...props.parameters }
33
37
 
34
38
  let replacedHtml = html
35
39
  for (const [key, value] of Object.entries(dynamicData)) {
36
- const mentionRegex = new RegExp(`{{${key}}}`, 'g')
37
- replacedHtml = replacedHtml.replace(mentionRegex, value || `{{${key}}}`)
40
+ // Literal match and a replacer function: keys and operator-typed values
41
+ // must never be read as regex or `$` replacement patterns.
42
+ const placeholder = `{{${key}}}`
43
+ replacedHtml = replacedHtml.replaceAll(placeholder, () => value || placeholder)
38
44
  }
39
45
 
40
46
  return replacedHtml
@@ -49,15 +55,10 @@ const bodyHtml = computed(() => {
49
55
  return replaceMentionsWithValues(html)
50
56
  })
51
57
 
52
- const headerHtml = computed(() => {
58
+ // Plain text, exactly as Meta receives it
59
+ const headerText = computed(() => {
53
60
  if (props.message.body.header.type !== 'text') return ''
54
- if (!props.message.body.header.content) return ''
55
- const extensions = getTipTapExtensions({ preset: 'whatsapp-header' })
56
- const html = generateHTML(
57
- sanitizeContent(props.message.body.header.content, extensions),
58
- extensions,
59
- ).replaceAll('<p></p>', '<p>&nbsp;</p>')
60
- return replaceMentionsWithValues(html)
61
+ return replaceMentionsWithValues(convertToWhatsappHeaderText(props.message.body.header.content))
61
62
  })
62
63
 
63
64
  const currentTime = computed(() => {
@@ -123,7 +124,7 @@ const getIcon = (type: WaButtonTypeV1) => {
123
124
  v-if="message.body.header.type === 'text'"
124
125
  class="text-sm text-primary-950 break-all"
125
126
  >
126
- <p v-html="headerHtml" />
127
+ <p>{{ headerText }}</p>
127
128
  </div>
128
129
  <div v-else-if="message.body.header.type === 'image'" class="mb-2">
129
130
  <img
@@ -9,6 +9,8 @@ defineOptions({
9
9
  defineProps<{
10
10
  message: PostEntity<WhatsappMessage>
11
11
  messageGroupId: string
12
+ /** Forwarded to `WhatsappPreview`: operator-typed values overriding the resolved ones. */
13
+ parameters?: Record<string, string>
12
14
  }>()
13
15
  </script>
14
16
 
@@ -19,6 +21,10 @@ defineProps<{
19
21
  <h3 class="label-lg">{{ $t('common.preview') }}</h3>
20
22
  </div>
21
23
 
22
- <WhatsappPreview :message="message" :message-group-id="messageGroupId" />
24
+ <WhatsappPreview
25
+ :message="message"
26
+ :message-group-id="messageGroupId"
27
+ :parameters="parameters"
28
+ />
23
29
  </div>
24
30
  </template>
@@ -1,10 +1,6 @@
1
1
  <script setup lang="ts">
2
2
  import type { JSONContent } from '@tiptap/vue-3'
3
- import { generateHTML } from '@tiptap/vue-3'
4
- import {
5
- getTipTapExtensions,
6
- sanitizeContent,
7
- } from '@dev.smartpricing/message-composer-utils/utils'
3
+ import { convertToWhatsappHeaderText } from '@dev.smartpricing/message-composer-utils/utils'
8
4
  import RichTextEditor from '@/components/Editor/RichTextEditor.vue'
9
5
  import { useAppContextStore } from '@/stores/appContext'
10
6
  import { WA_HEADER_TEXT_MAX_LENGTH } from '@dev.smartpricing/message-composer-utils/types'
@@ -22,26 +18,15 @@ const targetContent = defineModel<JSONContent | undefined>({
22
18
  })
23
19
 
24
20
  const appContext = useAppContextStore()
25
-
26
- // Generate HTML for preview of base language with rich text support
27
- function generatePreviewHtml(content: JSONContent | undefined): string {
28
- if (!content) return ''
29
- const extensions = getTipTapExtensions({ preset: 'whatsapp-header' })
30
- return generateHTML(sanitizeContent(content, extensions), extensions).replaceAll(
31
- '<p></p>',
32
- '<p>&nbsp;</p>',
33
- )
34
- }
35
21
  </script>
36
22
 
37
23
  <template>
38
24
  <div class="flex gap-8 items-start" :data-testid="whatsappTranslatorHeaderTestIds.container">
39
25
  <!-- Base language preview (read-only) -->
40
26
  <div class="flex-1 min-w-0" :data-testid="whatsappTranslatorHeaderTestIds.basePreview">
41
- <div
42
- class="paragraph-sm text-primary-700 break-words"
43
- v-html="generatePreviewHtml(baseContent)"
44
- />
27
+ <div class="paragraph-sm text-primary-700 break-words">
28
+ {{ convertToWhatsappHeaderText(baseContent) }}
29
+ </div>
45
30
  </div>
46
31
 
47
32
  <!-- Translation editor (editable) -->
@@ -1,6 +1,7 @@
1
1
  const CODE_TO_KEY: Record<string, string> = {
2
2
  'session.missing': 'common.errors.session_expired',
3
3
  'session.expired': 'common.errors.session_expired',
4
+ AUTOMATION_ENGINE_REJECTED: 'automations.toast.engine_rejected',
4
5
  }
5
6
 
6
7
  function descriptionKeyByStatus(status: number): string {
@@ -0,0 +1,42 @@
1
+ import type { InjectionKey, Ref } from 'vue'
2
+
3
+ /** A value is what a Condition stores: a number where the Product's data holds one. */
4
+ export interface AutomationOption {
5
+ value: string | number
6
+ label: string
7
+ }
8
+
9
+ /**
10
+ * What a Host supplies to the Automation pages (ADR 0017), apart from
11
+ * `ComposerContext`. The Host fetches the lists and keeps them current.
12
+ */
13
+ export interface AutomationsContext {
14
+ /**
15
+ * The option lists, by the name the Automation Catalog gives them
16
+ * (`option_list` of a Condition Field). A list that is not there shows as
17
+ * empty.
18
+ */
19
+ optionLists: Ref<Record<string, AutomationOption[]>>
20
+ /** ISO code of the currency `price` fields show; EUR when absent. */
21
+ currency?: Ref<string | undefined>
22
+ }
23
+
24
+ export const AUTOMATIONS_CONTEXT_KEY: InjectionKey<AutomationsContext> = Symbol.for(
25
+ 'composer-automations-context',
26
+ )
27
+
28
+ /** Must be called in parent's app.vue or plugin before an Automation page renders. */
29
+ export function defineAutomationsContext(context: AutomationsContext): void {
30
+ // App-level provide, as `defineComposerContext`.
31
+ useNuxtApp().vueApp.provide(AUTOMATIONS_CONTEXT_KEY, context)
32
+ }
33
+
34
+ /**
35
+ * `undefined` when the Host provided none: an Automation page shows that as
36
+ * an error of its own (ADR 0019), so this does not throw.
37
+ */
38
+ export function useAutomationsContext(): AutomationsContext | undefined {
39
+ if (import.meta.server) return undefined
40
+
41
+ return useNuxtApp().vueApp.runWithContext(() => inject(AUTOMATIONS_CONTEXT_KEY, undefined))
42
+ }
@@ -9,18 +9,19 @@ export interface OrganizationData {
9
9
  }
10
10
 
11
11
  export interface ComposerContext {
12
- /** @deprecated No longer used — auth is cookie-based via platform layer */
13
- authenticationToken?: Ref<string>
14
12
  organization_id?: Ref<string>
15
- product?: Ref<AppContextConfig['product']>
16
- strategy?: Ref<AppContextConfig['strategy']>
13
+ /** The Product the host embeds the composer in (ADR 0011). Required. */
14
+ product: Ref<AppContextConfig['product']>
17
15
  channels?: Ref<AppContextConfig['channels']>
18
16
  languages?: Ref<string[]>
19
17
  mainLanguage?: Ref<string>
20
- dinamicValues?: Ref<Array<{ value: string; label: string }>>
21
18
  default_tags?: Ref<string[]>
19
+ /**
20
+ * The WABA the Host works on. A new Message Group is submitted to it and
21
+ * the user is not asked, as long as it is one of the Organization's
22
+ * (ADR 0015). Without it the user picks when there are several.
23
+ */
22
24
  metaWabaId?: Ref<string>
23
- metaAccessToken?: Ref<string>
24
25
  isAdmin?: Ref<boolean>
25
26
  organizationData?: Ref<OrganizationData>
26
27
  }
@@ -33,7 +34,8 @@ export function defineComposerContext(context: ComposerContext): void {
33
34
  useNuxtApp().vueApp.provide(COMPOSER_CONTEXT_KEY, context)
34
35
  }
35
36
 
36
- const SERVER_FALLBACK: ComposerContext = {}
37
+ // Server render never reads the context; the store reads every field defensively.
38
+ const SERVER_FALLBACK = {} as ComposerContext
37
39
 
38
40
  export function useComposerContext(): ComposerContext {
39
41
  if (import.meta.server) return SERVER_FALLBACK
@@ -0,0 +1,33 @@
1
+ import type { Automation } from '@dev.smartpricing/message-composer-utils/types'
2
+ import AutomationsCloneModal from '~/components/Automations/CloneModal.vue'
3
+ import { useCloneAutomationMutation } from '~/queries'
4
+
5
+ /**
6
+ * Duplicating an Automation, from wherever it is offered: the modal that asks
7
+ * the name of the copy, the clone, and the copy opened on its edit page.
8
+ * Called once, in the setup of the component that offers it.
9
+ */
10
+ export function useAutomationClone() {
11
+ const { t } = useI18n()
12
+ const toast = useToast()
13
+ const { trackEvent } = useTracking()
14
+ const cloneModal = useOverlay().create(AutomationsCloneModal, { destroyOnClose: true })
15
+ const { mutateAsync: cloneAutomation } = useCloneAutomationMutation()
16
+
17
+ /** Asks the name of the copy, then makes it from the Automation as stored. */
18
+ function askClone(automation: Pick<Automation, 'id' | 'name'>) {
19
+ cloneModal.open({
20
+ defaultName: t('common.copy_of', { name: automation.name }),
21
+ action: async (name) => {
22
+ const copy = await cloneAutomation({ id: automation.id, name })
23
+ trackEvent('automation.clone', { automation_name: name, source_id: automation.id })
24
+ toast.add({ title: t('automations.toast.cloned'), color: 'success' })
25
+
26
+ // In demo mode the answer is not an Automation: there is no copy to open.
27
+ if (copy?.id) await navigateTo({ name: 'automation-edit', params: { id: copy.id } })
28
+ },
29
+ })
30
+ }
31
+
32
+ return { askClone }
33
+ }