@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
@@ -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>
@@ -0,0 +1,30 @@
1
+ <script setup lang="ts">
2
+ import { useAppContextStore } from '~/stores/appContext'
3
+
4
+ /**
5
+ * Host-integration problems reported by the app-context store (missing
6
+ * Product, ...). Shown persistently: the host has to fix its context, the
7
+ * user cannot.
8
+ */
9
+ const { validationErrors } = storeToRefs(useAppContextStore())
10
+ const messages = computed(() => Object.values(validationErrors.value))
11
+ </script>
12
+
13
+ <template>
14
+ <UAlert
15
+ v-if="messages.length"
16
+ color="error"
17
+ variant="subtle"
18
+ icon="i-lucide-alert-triangle"
19
+ :title="$t('common.context_error_title')"
20
+ class="rounded-none"
21
+ >
22
+ <template #description>
23
+ <ul class="list-disc pl-4 space-y-1">
24
+ <li v-for="message in messages" :key="message">
25
+ {{ message }}
26
+ </li>
27
+ </ul>
28
+ </template>
29
+ </UAlert>
30
+ </template>
@@ -17,6 +17,8 @@ const props = withDefaults(
17
17
 
18
18
  const iframeRef = useTemplateRef<HTMLIFrameElement>('iframe')
19
19
  const measuredHeight = ref(0)
20
+ // The first document comes from `srcdoc`; later ones are written in place (see the watch).
21
+ const initialHtml = props.html
20
22
 
21
23
  const heightStyle = computed(() => {
22
24
  if (!measuredHeight.value) return `${props.minHeight}px`
@@ -44,10 +46,22 @@ function onLoad() {
44
46
  observeContent()
45
47
  }
46
48
 
49
+ /**
50
+ * Replace the document in place instead of re-binding `srcdoc`: a `srcdoc`
51
+ * change is a navigation, which blanks the frame and drops the height for a
52
+ * few frames. Writing keeps the frame painted and the last measured height
53
+ * until the new content is measured.
54
+ */
47
55
  watch(
48
56
  () => props.html,
49
- () => {
50
- measuredHeight.value = 0
57
+ (html) => {
58
+ const doc = iframeRef.value?.contentDocument
59
+ if (!doc) return
60
+ doc.open()
61
+ doc.write(html)
62
+ doc.close()
63
+ fitToContent()
64
+ observeContent()
51
65
  },
52
66
  )
53
67
 
@@ -59,7 +73,7 @@ onBeforeUnmount(() => {
59
73
  <template>
60
74
  <iframe
61
75
  ref="iframe"
62
- :srcdoc="html"
76
+ :srcdoc="initialHtml"
63
77
  :title="title"
64
78
  sandbox="allow-same-origin"
65
79
  :style="{ height: heightStyle }"
@@ -1,9 +1,43 @@
1
1
  <script setup lang="ts">
2
- import type { RenderType, MessageStatus } from '@dev.smartpricing/message-composer-utils/types'
3
- import { useMessageGroupsQuery } from '~/queries/messageGroups'
2
+ import type { MessageStatus, RenderType } from '@dev.smartpricing/message-composer-utils/types'
3
+ import { usePagedMessageGroups } from '~/composables/usePagedMessageGroups'
4
+ import { useMessageGroupQuery } from '~/queries/messageGroups'
5
+ import { useAppContextStore } from '~/stores/appContext'
4
6
 
5
7
  defineOptions({ name: 'MessageGroupSelect' })
6
8
 
9
+ type MessageGroupEligibility = 'active' | 'sendable'
10
+
11
+ /** Per mode: the selectability rule and the copy shown for groups that fail it. */
12
+ const ELIGIBILITY_RULES: Record<
13
+ MessageGroupEligibility,
14
+ {
15
+ isEligible: (messages: Array<{ status: MessageStatus }>) => boolean
16
+ tooltipKey: string
17
+ hideFilterKey: string
18
+ }
19
+ > = {
20
+ active: {
21
+ isEligible: (messages) => messages.length > 0 && messages.every((m) => m.status === 'approved'),
22
+ tooltipKey: 'common.messageGroupSelect.inactive_tooltip',
23
+ hideFilterKey: 'common.messageGroupSelect.hide_inactive',
24
+ },
25
+ sendable: {
26
+ isEligible: (messages) => messages.some((m) => m.status === 'approved'),
27
+ tooltipKey: 'common.messageGroupSelect.not_sendable_tooltip',
28
+ hideFilterKey: 'common.messageGroupSelect.hide_not_sendable',
29
+ },
30
+ }
31
+
32
+ /**
33
+ * In-composer Message Group picker (ADR 0012). Always lists the context
34
+ * Product's groups only: search is server-side, debounced and bound to the
35
+ * menu's search input; pages of 100 load on demand through "Load more".
36
+ * The selected group stays in the menu even when the loaded pages no longer
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.
40
+ */
7
41
  const props = withDefaults(
8
42
  defineProps<{
9
43
  renderType?: RenderType
@@ -21,10 +55,22 @@ const props = withDefaults(
21
55
  disabledGroupReasons?: Record<string, string>
22
56
  /** Overrides the "hide inactive" filter label. Defaults to the built-in translation. */
23
57
  hideFilterLabel?: string
58
+ /**
59
+ * Which groups are selectable: `active` (every Message approved, the
60
+ * composer's own rule) or `sendable` (at least one approved Message, the
61
+ * Message Send Flow's rule). The disabled tooltip and the hide filter
62
+ * follow the mode.
63
+ */
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
24
69
  }>(),
25
70
  {
26
71
  placeholder: 'Select a message group',
27
72
  searchPlaceholder: 'Search...',
73
+ eligibility: 'active',
28
74
  },
29
75
  )
30
76
 
@@ -34,20 +80,102 @@ const emit = defineEmits<{
34
80
  select: [item: { id: string; name: string }]
35
81
  }>()
36
82
 
83
+ /** What the picker needs from a group, whichever endpoint it came from. */
84
+ interface PickerGroup {
85
+ id: string
86
+ name: string
87
+ messages: Array<{ status: MessageStatus }>
88
+ }
89
+
90
+ const PER_PAGE = 100
91
+
37
92
  const { t } = useI18n()
93
+ const appContext = useAppContextStore()
38
94
 
39
- const { data: messageGroups, isLoading } = useMessageGroupsQuery(() => ({
40
- renderType: props.renderType,
41
- }))
95
+ // Server-side search: the menu's own client filter is off (`ignore-filter`),
96
+ // the typed term reaches the list request once it settles. A new search,
97
+ // render type, context Product or WABA starts over from page one.
98
+ const searchTerm = ref('')
99
+ const page = ref(1)
42
100
 
43
- const hideInactive = ref(false)
101
+ // Without a context Product the server would answer with every Product's
102
+ // groups (ADR 0011): never ask. The host's missing Product is already reported
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
+ )
44
108
 
45
- function isGroupActive(messages: Array<{ status: MessageStatus }>): boolean {
46
- return messages.length > 0 && messages.every((m) => m.status === 'approved')
47
- }
109
+ const {
110
+ query: { data: envelope, isPlaceholderData },
111
+ loading,
112
+ } = usePagedMessageGroups({
113
+ search: searchTerm,
114
+ page,
115
+ perPage: PER_PAGE,
116
+ renderType: () => props.renderType,
117
+ filters: () => ({
118
+ product: appContext.product,
119
+ visibility: appContext.isAdmin ? 'all' : 'public',
120
+ waba_id: wabaFilter.value,
121
+ }),
122
+ resetOn: [() => appContext.product, wabaFilter],
123
+ enabled: () => appContext.product != null,
124
+ organizationId: () => props.organizationId,
125
+ })
126
+
127
+ // Pages loaded so far, indexed by page number: page one replaces everything,
128
+ // later pages slot in at their index (a refetch replaces, never duplicates).
129
+ const pages = shallowRef<PickerGroup[][]>([])
130
+ watch(
131
+ envelope,
132
+ (value) => {
133
+ if (!value) return
134
+ const index = value.meta.current_page - 1
135
+ pages.value = index === 0 ? [value.data] : [...pages.value.slice(0, index), value.data]
136
+ },
137
+ { immediate: true },
138
+ )
139
+ const loadedGroups = computed(() => pages.value.flat())
140
+
141
+ // The selected group is pinned on top of the loaded pages when they do not
142
+ // contain it: remembered from the last pick, or fetched by id when preselected.
143
+ const lastPicked = shallowRef<PickerGroup>()
144
+ const missingSelectedId = computed(() => {
145
+ const id = modelValue.value
146
+ if (!id || loadedGroups.value.some((g) => g.id === id)) return undefined
147
+ return lastPicked.value?.id === id ? undefined : id
148
+ })
149
+ const { data: fetchedSelected } = useMessageGroupQuery(() => missingSelectedId.value ?? '', {
150
+ enabled: () => missingSelectedId.value != null,
151
+ })
152
+ const messageGroups = computed<PickerGroup[]>(() => {
153
+ const id = modelValue.value
154
+ if (!id || loadedGroups.value.some((g) => g.id === id)) return loadedGroups.value
155
+ const pinned =
156
+ lastPicked.value?.id === id
157
+ ? lastPicked.value
158
+ : fetchedSelected.value?.id === id
159
+ ? fetchedSelected.value
160
+ : undefined
161
+ return pinned ? [pinned, ...loadedGroups.value] : loadedGroups.value
162
+ })
163
+
164
+ const hasMore = computed(
165
+ () =>
166
+ !isPlaceholderData.value &&
167
+ envelope.value != null &&
168
+ envelope.value.meta.current_page < envelope.value.meta.last_page,
169
+ )
170
+ const isLoadingFirstPage = computed(() => page.value === 1 && loading.value)
171
+ const isLoadingMore = computed(() => page.value > 1 && loading.value)
172
+
173
+ const hideIneligible = ref(false)
174
+
175
+ const rule = computed(() => ELIGIBILITY_RULES[props.eligibility])
176
+ const hideFilterLabel = computed(() => props.hideFilterLabel ?? t(rule.value.hideFilterKey))
48
177
 
49
178
  const items = computed(() => {
50
- if (!messageGroups.value) return []
51
179
  return messageGroups.value.reduce<
52
180
  Array<{
53
181
  label: string
@@ -58,45 +186,73 @@ const items = computed(() => {
58
186
  }>
59
187
  >((acc, group) => {
60
188
  const externalReason = props.disabledGroupReasons?.[group.id]
61
- const externallyUsed = externalReason != null
62
- const active = isGroupActive(group.messages)
63
- const disabled = !active || externallyUsed
64
- if (hideInactive.value && disabled) return acc
189
+ const eligible = rule.value.isEligible(group.messages)
190
+ const disabled = !eligible || externalReason != null
191
+ if (hideIneligible.value && disabled && group.id !== modelValue.value) return acc
192
+ // External reason wins over the mode's own tooltip when both apply.
193
+ let tooltip: string | undefined
194
+ if (externalReason != null) tooltip = externalReason
195
+ else if (!eligible) tooltip = t(rule.value.tooltipKey)
65
196
  acc.push({
66
197
  label: group.name,
67
198
  value: group.id,
68
199
  disabled,
69
- // External reason wins over the inactive tooltip when both apply.
70
- tooltip: externallyUsed
71
- ? externalReason
72
- : !active
73
- ? t('common.messageGroupSelect.inactive_tooltip')
74
- : undefined,
200
+ tooltip,
75
201
  chip: { color: disabled ? 'neutral' : 'success' },
76
202
  })
77
203
  return acc
78
204
  }, [])
79
205
  })
80
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
+
81
222
  function handleUpdate(value: string) {
82
223
  modelValue.value = value
83
- const group = messageGroups.value?.find((g) => g.id === value)
224
+ const group = messageGroups.value.find((g) => g.id === value)
225
+ lastPicked.value = group
84
226
  emit('select', { id: value, name: group?.name ?? '' })
85
227
  }
86
228
  </script>
87
229
 
88
230
  <template>
89
231
  <USelectMenu
232
+ v-model:search-term="searchTerm"
90
233
  :model-value="modelValue"
91
234
  :items="items"
92
235
  value-key="value"
93
- :loading="isLoading"
236
+ :loading="isLoadingFirstPage"
94
237
  searchable
238
+ ignore-filter
95
239
  :placeholder="placeholder"
96
240
  :search-input="{ placeholder: searchPlaceholder }"
97
241
  :data-testid="messageGroupSelectTestIds.root"
98
242
  @update:model-value="handleUpdate"
99
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
+
100
256
  <template #item-label="{ item }">
101
257
  <UTooltip v-if="item.disabled" :text="item.tooltip">
102
258
  <span class="text-muted">{{ item.label }}</span>
@@ -106,10 +262,21 @@ function handleUpdate(value: string) {
106
262
 
107
263
  <template #content-top>
108
264
  <div class="flex items-center gap-2 px-2 py-1.5 border-b border-default">
109
- <USwitch v-model="hideInactive" size="xs" />
110
- <span class="text-xs text-muted">
111
- {{ hideFilterLabel ?? t('common.messageGroupSelect.hide_inactive') }}
112
- </span>
265
+ <USwitch v-model="hideIneligible" size="xs" />
266
+ <span class="text-xs text-muted">{{ hideFilterLabel }}</span>
267
+ </div>
268
+ </template>
269
+
270
+ <template v-if="hasMore || isLoadingMore" #content-bottom>
271
+ <div class="flex justify-center px-2 py-1.5 border-t border-default">
272
+ <UButton
273
+ variant="link"
274
+ size="xs"
275
+ :loading="isLoadingMore"
276
+ :label="t('common.messageGroupSelect.load_more')"
277
+ :data-testid="messageGroupSelectTestIds.loadMore"
278
+ @click="page++"
279
+ />
113
280
  </div>
114
281
  </template>
115
282
  </USelectMenu>
@@ -14,6 +14,8 @@ import { useEmailEditorStore } from '~/stores/emailEditor'
14
14
  interface Props {
15
15
  message: PostEntity<Message> | MessageFromDb | null | undefined
16
16
  messageGroupId?: string
17
+ /** WhatsApp only, forwarded to `WhatsappPreview`: operator-typed values overriding the resolved ones. No effect on the email preview. */
18
+ parameters?: Record<string, string>
17
19
  }
18
20
 
19
21
  const props = defineProps<Props>()
@@ -72,6 +74,7 @@ const isEmail = computed(() => renderType.value === 'email_v1')
72
74
  v-if="isWhatsapp && messageGroupId"
73
75
  :message="message as WhatsappMessage"
74
76
  :message-group-id="messageGroupId"
77
+ :parameters="parameters"
75
78
  />
76
79
 
77
80
  <!-- Email Inline Preview (client-driven, reflects unsaved changes) -->
@@ -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
  },