@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,51 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Holds its content back until there is an Organization to work on, so no
4
+ * resource request leaves before it is resolved (ADR 0014).
5
+ */
6
+ const organization = useEffectiveOrganizationStore()
7
+ const { t } = useI18n()
8
+
9
+ const failure = computed(() =>
10
+ organization.status === 'none'
11
+ ? {
12
+ title: t('common.organization.none_title'),
13
+ description: t('common.organization.none_description'),
14
+ }
15
+ : {
16
+ title: t('common.organization.lookup_failed_title'),
17
+ description: t('common.organization.lookup_failed_description'),
18
+ },
19
+ )
20
+ </script>
21
+
22
+ <template>
23
+ <slot v-if="organization.status === 'resolved'" />
24
+
25
+ <div
26
+ v-else-if="organization.status === 'resolving'"
27
+ class="flex flex-1 flex-col items-center justify-center gap-3 py-12 text-muted"
28
+ role="status"
29
+ >
30
+ <UIcon name="i-heroicons-arrow-path" class="animate-spin h-8 w-8" />
31
+ <span class="text-sm">{{ t('common.organization.resolving') }}</span>
32
+ </div>
33
+
34
+ <div v-else class="p-4">
35
+ <UAlert
36
+ color="error"
37
+ variant="subtle"
38
+ icon="i-lucide-alert-triangle"
39
+ :title="failure.title"
40
+ :description="failure.description"
41
+ :actions="[
42
+ {
43
+ label: t('common.organization.retry'),
44
+ color: 'error',
45
+ variant: 'outline',
46
+ onClick: () => void organization.retry(),
47
+ },
48
+ ]"
49
+ />
50
+ </div>
51
+ </template>
@@ -0,0 +1,27 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Organization selector of the list pages (Message Groups, Brands, images):
4
+ * filters what is listed and decides where new resources are created. Renders
5
+ * nothing when the Host supplied the Organization or the user reaches only one.
6
+ */
7
+ const organization = useEffectiveOrganizationStore()
8
+ const { t } = useI18n()
9
+
10
+ const items = computed(() =>
11
+ organization.reachableOrganizations.map((o) => ({ label: o.name, value: o.id })),
12
+ )
13
+ </script>
14
+
15
+ <template>
16
+ <USelectMenu
17
+ v-if="organization.isSelectable"
18
+ :model-value="organization.resolvedOrganizationId ?? undefined"
19
+ :items="items"
20
+ value-key="value"
21
+ icon="ph:buildings"
22
+ :search-input="{ placeholder: t('common.organization.search_placeholder') }"
23
+ :aria-label="t('common.organization.label')"
24
+ class="w-56"
25
+ @update:model-value="organization.select($event)"
26
+ />
27
+ </template>
@@ -0,0 +1,20 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Tells the user that the Effective Organization has no WABA: its WhatsApp
4
+ * messages can be drafted but not submitted to Meta. Follows the Organization,
5
+ * so it comes and goes with the selector and with the resource on screen.
6
+ */
7
+ const { status } = useWhatsappConfiguration()
8
+ </script>
9
+
10
+ <template>
11
+ <UAlert
12
+ v-if="status === 'not_configured'"
13
+ color="warning"
14
+ variant="subtle"
15
+ icon="i-lucide-message-circle-off"
16
+ :title="$t('common.whatsapp_not_configured_title')"
17
+ :description="$t('common.whatsapp_not_configured_description')"
18
+ class="rounded-none"
19
+ />
20
+ </template>
@@ -39,6 +39,10 @@ const { data: messageGroupData, isPending: isFetching } =
39
39
  ? useMessageGroupQuery(props.messageGroupId)
40
40
  : { data: ref(null), isPending: ref(false) }
41
41
 
42
+ // The editor works on the Organization of the Message Group it loaded, not on
43
+ // the selector's. Claimed before the watcher below loads dependent data.
44
+ useResourceOrganization(() => messageGroupData.value?.organization_id)
45
+
42
46
  // Change tracking (edit mode only)
43
47
  const messageGroupIdRef = computed(() => store.messageGroupId ?? '')
44
48
  const changeTracking = props.mode === 'edit' ? useChangeTrackingEmail(messageGroupIdRef) : null
@@ -161,8 +165,12 @@ const { formState, draftSchema, validationErrors, validateDraft, validateFull, c
161
165
  // ── Template operations ───────────────────────────────────────────
162
166
  const successFlag = ref(false)
163
167
 
168
+ const editorTrip = useEditorTripStore()
169
+
164
170
  const { saving, createTemplate, updateTemplate } = useTemplateOperations({
165
- onSuccess: () => {
171
+ onSuccess: (saved) => {
172
+ // Recorded before the editor navigates: whoever opened it reads it on landing.
173
+ if (saved) editorTrip.recordSaved(saved)
166
174
  successFlag.value = true
167
175
  goBackOrFallback()
168
176
  },
@@ -19,6 +19,8 @@ const emit = defineEmits<{
19
19
  duplicated: [result: { id: string | number; sourceId: string | number; name: string }]
20
20
  published: [row: MessageGroupWithMessageSummary]
21
21
  unpublished: [row: MessageGroupWithMessageSummary]
22
+ /** Once, when the list has loaded for the first time. */
23
+ loaded: []
22
24
  }>()
23
25
 
24
26
  const { trackEvent } = useTracking()
@@ -36,6 +38,12 @@ const {
36
38
  refetch: execute,
37
39
  } = useMessageGroupList(renderType)
38
40
 
41
+ whenever(
42
+ () => !isFetching.value,
43
+ () => emit('loaded'),
44
+ { immediate: true, once: true },
45
+ )
46
+
39
47
  // Polling
40
48
  const interval = setInterval(() => execute(), 15000)
41
49
  onBeforeUnmount(() => clearInterval(interval))
@@ -0,0 +1,73 @@
1
+ <script setup lang="ts">
2
+ import type { OrganizationWaba } from '@dev.smartpricing/message-composer-utils/types'
3
+
4
+ /**
5
+ * Asks which WABA a Message Group is submitted to, at its first submission,
6
+ * when its Organization has several (ADR 0015). Opened through `useOverlay`:
7
+ * closes with the chosen WABA id, or with nothing when the user gives up.
8
+ */
9
+ const props = defineProps<{
10
+ wabas: OrganizationWaba[]
11
+ }>()
12
+
13
+ const emit = defineEmits<{ close: [wabaId?: string] }>()
14
+
15
+ const selected = ref<string>()
16
+
17
+ const items = computed(() =>
18
+ props.wabas.map((waba) => ({
19
+ value: waba.id,
20
+ label: waba.name || waba.id,
21
+ numbers: waba.phone_numbers.join(', '),
22
+ // Not `id`: the radio group gives each item one of its own.
23
+ wabaId: waba.id,
24
+ })),
25
+ )
26
+ </script>
27
+
28
+ <template>
29
+ <UModal
30
+ :title="$t('dialogs.select_waba.title')"
31
+ :description="$t('dialogs.select_waba.description')"
32
+ close-icon="ph:x"
33
+ :close="{ onClick: () => emit('close') }"
34
+ :dismissible="false"
35
+ data-testid="waba-select-modal"
36
+ >
37
+ <template #body>
38
+ <URadioGroup
39
+ v-model="selected"
40
+ :items="items"
41
+ variant="table"
42
+ class="w-full"
43
+ :ui="{ item: 'w-full' }"
44
+ data-testid="waba-select-options"
45
+ >
46
+ <template #description="{ item }">
47
+ <span class="flex flex-col">
48
+ <span>{{ item.numbers || $t('dialogs.select_waba.no_numbers') }}</span>
49
+ <span class="text-xs text-dimmed font-mono">{{ item.wabaId }}</span>
50
+ </span>
51
+ </template>
52
+ </URadioGroup>
53
+ </template>
54
+
55
+ <template #footer>
56
+ <div class="flex gap-2 justify-end w-full">
57
+ <UButton
58
+ variant="outline"
59
+ color="neutral"
60
+ :label="$t('common.actions.cancel')"
61
+ data-testid="waba-select-cancel"
62
+ @click="emit('close')"
63
+ />
64
+ <UButton
65
+ :label="$t('dialogs.select_waba.confirm')"
66
+ :disabled="!selected"
67
+ data-testid="waba-select-confirm"
68
+ @click="emit('close', selected)"
69
+ />
70
+ </div>
71
+ </template>
72
+ </UModal>
73
+ </template>
@@ -27,8 +27,33 @@ const { mainLanguage } = storeToRefs(useAppContextStore())
27
27
  const { trackEvent } = useTracking()
28
28
  const { goBackOrFallback } = useGoBack()
29
29
  const { submitToMeta, submitMessageToMeta } = useMetaSubmissionStore()
30
+ const { status: whatsappConfiguration } = useWhatsappConfiguration()
30
31
  const { confirm } = useConfirm()
31
32
  const { t } = useI18n()
33
+ const toast = useToast()
34
+
35
+ /**
36
+ * A submission needs a WABA of the Message Group's Organization: when it is
37
+ * known to have none, or the Message Group is on one the Organization no
38
+ * longer has, say so before anything is saved on the way to the submission.
39
+ * While that is not known (lookup running or failed) the submission goes
40
+ * ahead and the backend decides.
41
+ */
42
+ function canSubmitToMeta(): boolean {
43
+ const reason =
44
+ whatsappConfiguration.value === 'not_configured'
45
+ ? 'whatsapp_not_configured'
46
+ : isWabaDetached.value
47
+ ? 'whatsapp_waba_detached'
48
+ : null
49
+ if (!reason) return true
50
+ toast.add({
51
+ color: 'error',
52
+ title: t(`common.${reason}_title`),
53
+ description: t(`common.${reason}_description`),
54
+ })
55
+ return false
56
+ }
32
57
 
33
58
  // ── Init ──────────────────────────────────────────────────────────
34
59
  if (props.mode === 'create') {
@@ -41,6 +66,19 @@ const { data: messageGroupData, isPending: isFetching } =
41
66
  ? useMessageGroupQuery(props.messageGroupId)
42
67
  : { data: ref(null), isPending: ref(false) }
43
68
 
69
+ // The editor works on the Organization of the Message Group it loaded, not on
70
+ // the selector's. Claimed before the watcher below loads dependent data.
71
+ useResourceOrganization(() => messageGroupData.value?.organization_id)
72
+
73
+ // The WABA the Message Group is on, and the choice of one at its first
74
+ // submission (ADR 0015).
75
+ const {
76
+ waba: messageGroupWaba,
77
+ isDetached: isWabaDetached,
78
+ chooseWaba,
79
+ markSubmitted,
80
+ } = useMessageGroupWaba(() => messageGroupData.value?.waba_id)
81
+
44
82
  // ── Change tracking ───────────────────────────────────────────────
45
83
  const changeTracking = useChangeTracking(computed(() => store.changeTrackingId))
46
84
 
@@ -96,8 +134,12 @@ const { formState, draftSchema, validationErrors, validateDraft, validateFull, c
96
134
  // ── Template operations ───────────────────────────────────────────
97
135
  const successFlag = ref(false)
98
136
 
137
+ const editorTrip = useEditorTripStore()
138
+
99
139
  const { saving, createTemplate, updateTemplate } = useTemplateOperations({
100
- onSuccess: () => {
140
+ onSuccess: (saved) => {
141
+ // Recorded before the editor navigates: whoever opened it reads it on landing.
142
+ if (saved) editorTrip.recordSaved(saved)
101
143
  successFlag.value = true
102
144
  changeTracking.clearAllChanges()
103
145
  if (props.mode === 'create') {
@@ -238,6 +280,10 @@ async function saveAsNew() {
238
280
  }
239
281
 
240
282
  async function requestApproval() {
283
+ // Asked before anything is saved: giving up leaves the editor as it was.
284
+ const choice = await chooseWaba()
285
+ if (!choice) return
286
+
241
287
  track('request_approval', getWaDraftProps())
242
288
 
243
289
  if (props.mode === 'create') {
@@ -246,7 +292,7 @@ async function requestApproval() {
246
292
  'draft',
247
293
  )
248
294
  if (result) {
249
- await submitToMeta(result.id.toString())
295
+ await submitToMeta(result.id.toString(), choice.wabaId)
250
296
  emit('saved', { id: result.id, name: result.name })
251
297
  notifyParent('TEMPLATE_APPROVAL_REQUESTED', { id: result.id, name: result.name })
252
298
  }
@@ -256,7 +302,7 @@ async function requestApproval() {
256
302
  messageGroup: store.messageGroupUpdateData,
257
303
  messages: store.messages,
258
304
  })
259
- await submitToMeta(store.messageGroupId)
305
+ await submitToMeta(store.messageGroupId, choice.wabaId)
260
306
  emit('saved', { id: store.messageGroupId, name: store.name })
261
307
  notifyParent('TEMPLATE_APPROVAL_REQUESTED', { id: store.messageGroupId, name: store.name })
262
308
  goBackOrFallback()
@@ -267,6 +313,10 @@ async function requestApproval() {
267
313
  async function onRequestReview(languageId: string) {
268
314
  const message = store.messages[languageId] as (WhatsappMessage & { id?: string }) | undefined
269
315
  if (!message?.id) return
316
+ if (!canSubmitToMeta()) return
317
+
318
+ const choice = await chooseWaba()
319
+ if (!choice) return
270
320
 
271
321
  const languageName = languages.value?.find((l) => l.id === languageId)?.name ?? languageId
272
322
 
@@ -278,7 +328,8 @@ async function onRequestReview(languageId: string) {
278
328
  action: async () => {
279
329
  // Decision C: persist only this language's current edits, then submit it.
280
330
  await messagesApi.update(message.id!, message)
281
- await submitMessageToMeta(message.id!)
331
+ await submitMessageToMeta(message.id!, choice.wabaId)
332
+ markSubmitted(choice.wabaId)
282
333
  // Reflect pending locally instead of refetching the group, so unsaved
283
334
  // edits in other languages are preserved.
284
335
  store.messages[languageId] = { ...message, status: 'pending' }
@@ -312,6 +363,7 @@ async function handleSaveAsNew() {
312
363
  }
313
364
 
314
365
  async function handleRequestApproval() {
366
+ if (!canSubmitToMeta()) return
315
367
  if (!(await validateFull())) return
316
368
  if (hasIncompleteTranslations.value) {
317
369
  pendingAction.value = 'request_approval'
@@ -409,6 +461,7 @@ defineExpose({
409
461
  validationErrors,
410
462
  isPending: store.isPending,
411
463
  isApproved: store.isApproved,
464
+ isWabaDetached,
412
465
  })
413
466
  </script>
414
467
 
@@ -439,6 +492,32 @@ defineExpose({
439
492
  </UAlert>
440
493
  </div>
441
494
 
495
+ <UAlert
496
+ v-if="isWabaDetached"
497
+ color="warning"
498
+ variant="subtle"
499
+ icon="i-lucide-unplug"
500
+ :title="$t('common.whatsapp_waba_detached_title')"
501
+ :description="$t('common.whatsapp_waba_detached_description')"
502
+ class="rounded-none"
503
+ data-testid="whatsapp-waba-detached"
504
+ />
505
+ <div
506
+ v-if="messageGroupWaba"
507
+ class="flex items-center gap-2 px-6 py-2 text-sm text-muted border-b border-default"
508
+ data-testid="whatsapp-message-group-waba"
509
+ >
510
+ <UIcon name="i-lucide-building-2" class="size-4 shrink-0" />
511
+ <span>{{ $t('common.whatsapp_waba_label') }}</span>
512
+ <span v-if="messageGroupWaba.name" class="font-medium text-default">
513
+ {{ messageGroupWaba.name }}
514
+ </span>
515
+ <span v-if="messageGroupWaba.phone_numbers.length">
516
+ {{ messageGroupWaba.phone_numbers.join(', ') }}
517
+ </span>
518
+ <span class="text-xs text-dimmed font-mono">{{ messageGroupWaba.id }}</span>
519
+ </div>
520
+
442
521
  <ComposerWhatsappContent
443
522
  v-if="store.activeTab === 'content'"
444
523
  :mode="mode"
@@ -13,6 +13,7 @@ import {
13
13
  convertToWhatsappHeaderText,
14
14
  convertToWhatsappMarkdown,
15
15
  getTipTapExtensions,
16
+ isWhatsappHeaderMultiline,
16
17
  sanitizeContent,
17
18
  } from '@dev.smartpricing/message-composer-utils/utils'
18
19
  import EmojiPickerButton from '../Common/EmojiPickerButton.vue'
@@ -278,14 +279,21 @@ const toolbarItems = computed(() => {
278
279
  // WhatsApp markdown-aware character count
279
280
  // Meta counts the final markdown output (with *bold*, _italic_ marks),
280
281
  // so we must display that count instead of TipTap's document-model count.
281
- const isWhatsapp = computed(() => props.preset === 'whatsapp' || props.preset === 'whatsapp-header')
282
+ const isWhatsappHeader = computed(() => props.preset === 'whatsapp-header')
283
+ const isWhatsapp = computed(() => props.preset === 'whatsapp' || isWhatsappHeader.value)
282
284
  const whatsappCharCount = computed(() => {
283
285
  if (!isWhatsapp.value || !props.characterLimit || !text.value) return 0
284
- return props.preset === 'whatsapp-header'
286
+ return isWhatsappHeader.value
285
287
  ? convertToWhatsappHeaderText(text.value).length
286
288
  : convertToWhatsappMarkdown(text.value).length
287
289
  })
288
290
 
291
+ // A multi-line header is still saved (its lines are joined into one when
292
+ // sent to Meta), so the editor warns instead of raising a validation error.
293
+ const hasHeaderLineBreaks = computed(
294
+ () => isWhatsappHeader.value && isWhatsappHeaderMultiline(text.value),
295
+ )
296
+
289
297
  // Handlers
290
298
  function onSelectEmoji(emoji: EmojiExt) {
291
299
  editor.value?.commands.insertContent(emoji.i)
@@ -491,6 +499,10 @@ defineExpose({
491
499
  </span>
492
500
  </p>
493
501
 
502
+ <p v-if="hasHeaderLineBreaks" class="paragraph-xs text-warning-700 pt-1.5 px-1">
503
+ {{ $t('editor.validation.header_line_breaks') }}
504
+ </p>
505
+
494
506
  <!-- AI Generate slideover -->
495
507
  </div>
496
508
  </template>
@@ -0,0 +1,57 @@
1
+ <script setup lang="ts">
2
+ import { parseDate } from '@internationalized/date'
3
+
4
+ /** Internal to the filter components: one date, as `YYYY-MM-DD`. */
5
+ const props = defineProps<{
6
+ modelValue: string | undefined
7
+ testId: string
8
+ }>()
9
+
10
+ const emit = defineEmits<{ 'update:modelValue': [value: string | undefined] }>()
11
+
12
+ const date = computed(() => (props.modelValue ? parseDate(props.modelValue) : undefined))
13
+
14
+ // The inputs also speak ranges and lists; here they only ever hold one date.
15
+ function onUpdate(value: unknown) {
16
+ const isDate = typeof value === 'object' && value !== null && 'year' in value && 'day' in value
17
+ // A date with a time or a zone would still print its date first.
18
+ emit('update:modelValue', isDate ? String(value).slice(0, 10) : undefined)
19
+ }
20
+
21
+ const { t } = useI18n()
22
+
23
+ const inputDate = useTemplateRef('inputDate')
24
+ </script>
25
+
26
+ <template>
27
+ <UInputDate
28
+ ref="inputDate"
29
+ :model-value="date"
30
+ class="w-full"
31
+ :data-testid="`${testId}-date`"
32
+ @update:model-value="onUpdate"
33
+ >
34
+ <template #trailing>
35
+ <UPopover :reference="inputDate?.inputsRef[0]?.$el">
36
+ <UButton
37
+ color="neutral"
38
+ variant="link"
39
+ size="sm"
40
+ icon="ph:calendar-bold"
41
+ :aria-label="t('filters.actions.open_calendar')"
42
+ class="px-0"
43
+ :data-testid="`${testId}-calendar-button`"
44
+ />
45
+
46
+ <template #content>
47
+ <UCalendar
48
+ :model-value="date"
49
+ class="p-2"
50
+ :data-testid="`${testId}-calendar`"
51
+ @update:model-value="onUpdate"
52
+ />
53
+ </template>
54
+ </UPopover>
55
+ </template>
56
+ </UInputDate>
57
+ </template>
@@ -0,0 +1,163 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ Condition,
4
+ FilterField,
5
+ FiltersReport,
6
+ } from '@dev.smartpricing/message-composer-utils/types'
7
+ import {
8
+ conditionsToFilterRows,
9
+ filterCurrency,
10
+ filterRowsToConditions,
11
+ newFilterRow,
12
+ reportFilterRows,
13
+ type FilterEditableRow,
14
+ type FilterRow,
15
+ } from '../../utils/filters/rows'
16
+
17
+ /**
18
+ * Public (ADR 0018): the rows of a list of Conditions, and "add". Props-only:
19
+ * it reads neither the Automation Catalog nor the Host's context. A Condition
20
+ * it cannot edit is an unavailable row, kept as it is until the user removes
21
+ * it; a half-filled row is reported and never emitted.
22
+ */
23
+ const props = withDefaults(
24
+ defineProps<{
25
+ /** The fields a Condition can be on, in display order. */
26
+ fields: FilterField[]
27
+ /** ISO code of the currency `price` fields show; EUR when absent. */
28
+ currency?: string
29
+ title?: string
30
+ subtitle?: string
31
+ testIdPrefix?: string
32
+ }>(),
33
+ { currency: undefined, title: undefined, subtitle: undefined, testIdPrefix: undefined },
34
+ )
35
+
36
+ const model = defineModel<Condition[]>({ required: true })
37
+
38
+ const emit = defineEmits<{ report: [report: FiltersReport] }>()
39
+
40
+ const { t } = useI18n()
41
+
42
+ let lastId = 0
43
+ const nextId = () => ++lastId
44
+
45
+ const rows = ref<FilterRow[]>([])
46
+ /** What the rows were last worth, to tell the caller's changes from our own. */
47
+ let emitted: string | undefined
48
+
49
+ function readModel() {
50
+ rows.value = conditionsToFilterRows(model.value, props.fields, nextId)
51
+ emitted = JSON.stringify(model.value)
52
+ }
53
+
54
+ // Rows the user has not completed live only here: the rows are read again
55
+ // only when the Conditions change from outside, or the fields do.
56
+ watch(
57
+ model,
58
+ (conditions) => {
59
+ if (JSON.stringify(conditions) !== emitted) readModel()
60
+ },
61
+ { deep: true, immediate: true },
62
+ )
63
+ watch(() => props.fields.map((field) => `${field.key}:${field.type}`).join('|'), readModel)
64
+
65
+ function commit(next: FilterRow[]) {
66
+ const before = JSON.stringify(filterRowsToConditions(rows.value))
67
+ rows.value = next
68
+ const conditions = filterRowsToConditions(next)
69
+ const serialized = JSON.stringify(conditions)
70
+ // A row in progress changes no Condition: nothing to tell the caller.
71
+ if (serialized === before) return
72
+ emitted = serialized
73
+ model.value = conditions
74
+ }
75
+
76
+ const report = computed(() => reportFilterRows(rows.value, props.fields))
77
+ watch(report, (value) => emit('report', value), { immediate: true })
78
+
79
+ const shownCurrency = computed(() => filterCurrency(props.currency))
80
+
81
+ const fieldsByKey = computed(() => new Map(props.fields.map((field) => [field.key, field])))
82
+
83
+ function fieldOf(row: FilterRow): FilterField | undefined {
84
+ if (row.kind === 'blank') return undefined
85
+ return fieldsByKey.value.get(row.kind === 'editable' ? row.field : row.condition.field)
86
+ }
87
+
88
+ /** A field can be picked once: a field any row is on is taken. */
89
+ const freeFields = computed(() => {
90
+ const taken = new Set(rows.value.map((row) => fieldOf(row)?.key))
91
+ return props.fields.filter((field) => !taken.has(field.key))
92
+ })
93
+
94
+ function pickableFields(row: FilterRow): FilterField[] {
95
+ const own = fieldOf(row)
96
+ return props.fields.filter((field) => field === own || freeFields.value.includes(field))
97
+ }
98
+
99
+ const hasBlankRow = computed(() => rows.value.some((row) => row.kind === 'blank'))
100
+
101
+ function addRow() {
102
+ commit([...rows.value, { kind: 'blank', id: nextId() }])
103
+ }
104
+
105
+ function replaceRow(id: number, row: FilterEditableRow) {
106
+ commit(rows.value.map((current) => (current.id === id ? row : current)))
107
+ }
108
+
109
+ function pickField(id: number, fieldKey: string) {
110
+ const field = fieldsByKey.value.get(fieldKey)
111
+ if (field) replaceRow(id, newFilterRow(id, field))
112
+ }
113
+
114
+ function removeRow(id: number) {
115
+ commit(rows.value.filter((row) => row.id !== id))
116
+ }
117
+
118
+ const prefix = computed(() => (props.testIdPrefix ? `${props.testIdPrefix}-` : ''))
119
+
120
+ function rowTestId(row: FilterRow, index: number): string {
121
+ if (row.kind === 'editable') return `${prefix.value}filter-${row.field}`
122
+ return `${prefix.value}filter-${row.kind === 'blank' ? 'new' : `unavailable-${index}`}`
123
+ }
124
+ </script>
125
+
126
+ <template>
127
+ <div class="flex flex-col gap-3" :data-testid="`${prefix}filters`">
128
+ <p v-if="title" class="label-md">{{ title }}</p>
129
+ <p v-if="subtitle" class="label-sm">{{ subtitle }}</p>
130
+
131
+ <template v-for="(row, index) in rows" :key="row.id">
132
+ <FiltersUnavailableRow
133
+ v-if="row.kind === 'unavailable'"
134
+ :row="row"
135
+ :field="fieldOf(row)"
136
+ :test-id="rowTestId(row, index)"
137
+ @remove="removeRow(row.id)"
138
+ />
139
+ <FiltersRow
140
+ v-else
141
+ :row="row"
142
+ :field="fieldOf(row)"
143
+ :pickable-fields="pickableFields(row)"
144
+ :currency="shownCurrency"
145
+ :test-id="rowTestId(row, index)"
146
+ @pick="pickField(row.id, $event)"
147
+ @update="replaceRow(row.id, $event)"
148
+ @remove="removeRow(row.id)"
149
+ />
150
+ </template>
151
+
152
+ <div>
153
+ <UButton
154
+ :disabled="freeFields.length === 0 || hasBlankRow"
155
+ color="secondary"
156
+ variant="outline"
157
+ :label="t('filters.actions.add_filter')"
158
+ :data-testid="`${prefix}filters-add-button`"
159
+ @click="addRow"
160
+ />
161
+ </div>
162
+ </div>
163
+ </template>