@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,215 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ Condition,
4
+ FilterField,
5
+ FilterOptionValue,
6
+ FiltersReport,
7
+ } from '@dev.smartpricing/message-composer-utils/types'
8
+ import {
9
+ conditionsToFilterRows,
10
+ FILTER_OPERATOR_LABEL_KEYS,
11
+ filterCurrency,
12
+ isFilterRange,
13
+ missingFilterOptions,
14
+ rawConditionValue,
15
+ reportFilterRows,
16
+ type FilterEditableRow,
17
+ type FilterRow,
18
+ type FilterRowValue,
19
+ } from '../../utils/filters/rows'
20
+
21
+ /**
22
+ * Public (ADR 0018): a list of Conditions, read-only, one line each.
23
+ * Props-only, as `FiltersEditor`, and it leaves no Condition out: one the
24
+ * editor cannot edit shows as unavailable.
25
+ */
26
+ const props = withDefaults(
27
+ defineProps<{
28
+ modelValue: Condition[]
29
+ /** The fields a Condition can be on. */
30
+ fields: FilterField[]
31
+ /** ISO code of the currency `price` fields show; EUR when absent. */
32
+ currency?: string
33
+ /** How many lines show before "View more". */
34
+ preview?: number
35
+ testIdPrefix?: string
36
+ }>(),
37
+ { currency: undefined, preview: 3, testIdPrefix: undefined },
38
+ )
39
+
40
+ const emit = defineEmits<{ report: [report: FiltersReport] }>()
41
+
42
+ const { t, locale } = useI18n()
43
+
44
+ interface Line {
45
+ id: number
46
+ /** "Total price is at least:". */
47
+ heading: string
48
+ value: string
49
+ /** Shown in place of `value`, which then goes in a tooltip. */
50
+ count?: string
51
+ /** Option values the field does not list, struck through. */
52
+ missing: string[]
53
+ /** Why the line is an unavailable one, as a sentence. */
54
+ unavailable?: string
55
+ /** A stored value, shown as it is. */
56
+ raw: boolean
57
+ /** A field the caller did not declare: the whole line shows as stored. */
58
+ unknown: boolean
59
+ }
60
+
61
+ const fieldsByKey = computed(() => new Map(props.fields.map((field) => [field.key, field])))
62
+
63
+ const rows = computed(() => {
64
+ let id = 0
65
+ return conditionsToFilterRows(props.modelValue, props.fields, () => ++id)
66
+ })
67
+
68
+ const report = computed(() => reportFilterRows(rows.value, props.fields))
69
+ watch(report, (value) => emit('report', value), { immediate: true })
70
+
71
+ function formatValue(row: FilterEditableRow, value: FilterRowValue): string {
72
+ if (value === undefined || Array.isArray(value)) return ''
73
+ switch (row.type) {
74
+ case 'price':
75
+ return new Intl.NumberFormat(locale.value, {
76
+ style: 'currency',
77
+ currency: filterCurrency(props.currency),
78
+ }).format(value as number)
79
+ case 'number':
80
+ return new Intl.NumberFormat(locale.value).format(value as number)
81
+ case 'date':
82
+ return new Intl.DateTimeFormat(locale.value, { dateStyle: 'medium', timeZone: 'UTC' }).format(
83
+ new Date(`${value}T00:00:00Z`),
84
+ )
85
+ default:
86
+ return String(value)
87
+ }
88
+ }
89
+
90
+ function editableLine(row: FilterEditableRow): Line {
91
+ const field = fieldsByKey.value.get(row.field)
92
+ const operator = t(`filters.operators.${FILTER_OPERATOR_LABEL_KEYS[row.operator]}`)
93
+ const line: Line = {
94
+ id: row.id,
95
+ heading: `${field?.label ?? row.field} ${operator}`,
96
+ value: '',
97
+ missing: [],
98
+ raw: false,
99
+ unknown: false,
100
+ }
101
+ if (row.operator === 'exists') return line
102
+ line.heading += ':'
103
+
104
+ if (row.type === 'select' || row.type === 'multiselect') {
105
+ const missing = missingFilterOptions(row, field)
106
+ const selected: FilterOptionValue[] = Array.isArray(row.value)
107
+ ? row.value
108
+ : row.value === undefined
109
+ ? []
110
+ : [row.value]
111
+ const labels = (field?.options ?? [])
112
+ .filter((option) => selected.includes(option.value))
113
+ .map((option) => option.label)
114
+
115
+ line.value = labels.join(', ')
116
+ line.missing = missing.map(String)
117
+ if (labels.length > 1) line.count = t('filters.selected', { count: labels.length })
118
+ return line
119
+ }
120
+
121
+ line.value = isFilterRange(row.operator)
122
+ ? `${formatValue(row, row.value)} - ${formatValue(row, row.to)}`
123
+ : formatValue(row, row.value)
124
+ return line
125
+ }
126
+
127
+ function toLine(row: FilterRow): Line | undefined {
128
+ if (row.kind === 'blank') return undefined
129
+ if (row.kind === 'editable') return editableLine(row)
130
+
131
+ const { field: fieldKey, operator, value } = row.condition
132
+ const field = fieldsByKey.value.get(fieldKey)
133
+ const operatorKey = FILTER_OPERATOR_LABEL_KEYS[operator]
134
+ return {
135
+ id: row.id,
136
+ heading:
137
+ field && operatorKey
138
+ ? `${field.label} ${t(`filters.operators.${operatorKey}`)}`
139
+ : `${fieldKey} ${operator}`,
140
+ value: rawConditionValue(value),
141
+ missing: [],
142
+ unavailable: t(`filters.unavailable.${row.reason}`),
143
+ raw: true,
144
+ unknown: !field,
145
+ }
146
+ }
147
+
148
+ const lines = computed(() => rows.value.flatMap((row) => toLine(row) ?? []))
149
+
150
+ const expanded = ref(false)
151
+ const shown = computed(() => (expanded.value ? lines.value : lines.value.slice(0, props.preview)))
152
+
153
+ const prefix = computed(() => (props.testIdPrefix ? `${props.testIdPrefix}-` : ''))
154
+ </script>
155
+
156
+ <template>
157
+ <div v-if="lines.length" class="space-y-1" :data-testid="`${prefix}filters-summary`">
158
+ <div
159
+ v-for="line in shown"
160
+ :key="line.id"
161
+ class="flex flex-wrap items-baseline gap-1"
162
+ :data-testid="`${prefix}filters-summary-item`"
163
+ >
164
+ <span class="label-sm text-muted" :class="{ 'font-mono': line.unknown }">
165
+ {{ line.heading }}
166
+ </span>
167
+ <UTooltip v-if="line.count" :text="line.value">
168
+ <span class="paragraph-sm text-highlighted">{{ line.count }}</span>
169
+ </UTooltip>
170
+ <span
171
+ v-else-if="line.value"
172
+ class="paragraph-sm text-highlighted"
173
+ :class="{ 'font-mono': line.raw }"
174
+ >
175
+ {{ line.value }}
176
+ </span>
177
+ <UTooltip
178
+ v-for="value in line.missing"
179
+ :key="value"
180
+ :text="t('filters.unavailable.option_description')"
181
+ >
182
+ <span
183
+ class="paragraph-sm text-muted line-through"
184
+ :data-testid="`${prefix}filters-summary-unavailable-option`"
185
+ >
186
+ {{ value }}
187
+ </span>
188
+ </UTooltip>
189
+ <UTooltip v-if="line.unavailable" :text="line.unavailable">
190
+ <UBadge
191
+ color="warning"
192
+ variant="subtle"
193
+ size="sm"
194
+ :data-testid="`${prefix}filters-summary-unavailable-badge`"
195
+ >
196
+ {{ t('filters.unavailable.badge') }}
197
+ </UBadge>
198
+ </UTooltip>
199
+ </div>
200
+ <UButton
201
+ v-if="lines.length > preview"
202
+ variant="link"
203
+ color="neutral"
204
+ size="xs"
205
+ class="px-0"
206
+ :label="t(expanded ? 'common.view_less' : 'common.view_more')"
207
+ :trailing-icon="expanded ? 'ph:caret-up-bold' : 'ph:caret-down-bold'"
208
+ :data-testid="`${prefix}filters-summary-toggle`"
209
+ @click="expanded = !expanded"
210
+ />
211
+ </div>
212
+ <div v-else :data-testid="`${prefix}filters-summary`">
213
+ <span class="paragraph-sm text-muted">-</span>
214
+ </div>
215
+ </template>
@@ -0,0 +1,74 @@
1
+ <script setup lang="ts">
2
+ import type { FilterField } from '@dev.smartpricing/message-composer-utils/types'
3
+ import {
4
+ FILTER_OPERATOR_LABEL_KEYS,
5
+ rawConditionValue,
6
+ type FilterUnavailableRow,
7
+ } from '../../utils/filters/rows'
8
+
9
+ /**
10
+ * Internal to the filter components: a Condition the editor cannot edit,
11
+ * locked and removable. On a field the caller did not declare it shows raw.
12
+ */
13
+ const props = defineProps<{
14
+ row: FilterUnavailableRow
15
+ field: FilterField | undefined
16
+ testId: string
17
+ }>()
18
+
19
+ const emit = defineEmits<{ remove: [] }>()
20
+
21
+ const { t } = useI18n()
22
+
23
+ const isUnknownField = computed(() => props.row.reason === 'unknown_field')
24
+
25
+ const operatorLabel = computed(() => {
26
+ const { operator } = props.row.condition
27
+ const key = FILTER_OPERATOR_LABEL_KEYS[operator]
28
+ // A stored operator the engine's vocabulary does not have shows as it is.
29
+ return isUnknownField.value || !key ? operator : t(`filters.operators.${key}`)
30
+ })
31
+
32
+ const rawValue = computed(() => rawConditionValue(props.row.condition.value))
33
+ </script>
34
+
35
+ <template>
36
+ <div class="flex gap-2" :data-testid="testId">
37
+ <div
38
+ class="flex-1 grid grid-cols-5 gap-2 items-center rounded-md border border-dashed border-muted bg-elevated/50 px-2.5 py-1.5 min-h-8"
39
+ >
40
+ <p
41
+ class="col-span-2 paragraph-sm truncate"
42
+ :class="{ 'font-mono': isUnknownField }"
43
+ :data-testid="`${testId}-field`"
44
+ >
45
+ {{ field?.label ?? row.condition.field }}
46
+ </p>
47
+ <p class="paragraph-sm truncate" :class="{ 'font-mono': isUnknownField }">
48
+ {{ operatorLabel }}
49
+ </p>
50
+ <div class="col-span-2 flex items-center justify-between gap-2 min-w-0">
51
+ <p class="paragraph-sm font-mono truncate">{{ rawValue }}</p>
52
+ <UTooltip :text="t(`filters.unavailable.${row.reason}`)">
53
+ <UBadge
54
+ :color="isUnknownField ? 'error' : 'warning'"
55
+ variant="subtle"
56
+ class="shrink-0"
57
+ :data-testid="`${testId}-badge`"
58
+ >
59
+ {{ t('filters.unavailable.badge') }}
60
+ </UBadge>
61
+ </UTooltip>
62
+ </div>
63
+ </div>
64
+ <UButton
65
+ color="error"
66
+ variant="ghost"
67
+ icon="ph:trash"
68
+ class="shrink-0"
69
+ :aria-label="t('filters.actions.remove_filter')"
70
+ :data-testid="`${testId}-delete-button`"
71
+ @click="emit('remove')"
72
+ />
73
+ </div>
74
+ </template>
@@ -0,0 +1,215 @@
1
+ <script setup lang="ts">
2
+ import type { FilterField, FilterOptionValue } from '@dev.smartpricing/message-composer-utils/types'
3
+ import {
4
+ isFilterRange,
5
+ missingFilterOptions,
6
+ type FilterEditableRow,
7
+ type FilterRowValue,
8
+ } from '../../utils/filters/rows'
9
+
10
+ /**
11
+ * Internal to the filter components: the value of one row, by field type.
12
+ * An option value the field does not list is shown as unavailable and kept
13
+ * until the user removes it (ADR 0017).
14
+ */
15
+ const props = defineProps<{
16
+ row: FilterEditableRow
17
+ field: FilterField
18
+ currency: string
19
+ testId: string
20
+ }>()
21
+
22
+ const emit = defineEmits<{
23
+ 'update:value': [value: FilterRowValue]
24
+ 'update:to': [value: FilterRowValue]
25
+ }>()
26
+
27
+ const { t } = useI18n()
28
+
29
+ const isRange = computed(() => isFilterRange(props.row.operator))
30
+ const options = computed(() => props.field.options ?? [])
31
+ const missing = computed(() => missingFilterOptions(props.row, props.field))
32
+
33
+ // Select: the missing value stays the selected item, so it shows and is not lost.
34
+ const selectItems = computed(() => [
35
+ ...options.value,
36
+ ...missing.value.map((value) => ({
37
+ value,
38
+ label: t('filters.unavailable.option'),
39
+ disabled: true,
40
+ })),
41
+ ])
42
+
43
+ const selected = computed<FilterOptionValue[]>(() =>
44
+ Array.isArray(props.row.value) ? props.row.value : [],
45
+ )
46
+ const selectedKnown = computed(() =>
47
+ selected.value.filter((value) => !missing.value.includes(value)),
48
+ )
49
+ const selectedLabels = computed(() =>
50
+ options.value
51
+ .filter((option) => selectedKnown.value.includes(option.value))
52
+ .map((option) => option.label),
53
+ )
54
+ const selectionLabel = computed(() =>
55
+ selectedLabels.value.length === 1
56
+ ? selectedLabels.value[0]
57
+ : t('filters.selected', { count: selectedLabels.value.length }),
58
+ )
59
+
60
+ function onMultiselect(values: FilterOptionValue[]) {
61
+ emit('update:value', [...values, ...missing.value])
62
+ }
63
+
64
+ function removeMissing(value: FilterOptionValue) {
65
+ emit(
66
+ 'update:value',
67
+ selected.value.filter((item) => item !== value),
68
+ )
69
+ }
70
+
71
+ const numberFormat = computed<Intl.NumberFormatOptions | undefined>(() =>
72
+ props.field.type === 'price'
73
+ ? { style: 'currency', currency: props.currency, currencyDisplay: 'narrowSymbol' }
74
+ : undefined,
75
+ )
76
+
77
+ function asNumber(value: FilterRowValue): number | undefined {
78
+ return typeof value === 'number' ? value : undefined
79
+ }
80
+
81
+ function asString(value: FilterRowValue): string | undefined {
82
+ return typeof value === 'string' ? value : undefined
83
+ }
84
+ </script>
85
+
86
+ <template>
87
+ <div v-if="row.operator === 'exists'" />
88
+
89
+ <USelectMenu
90
+ v-else-if="field.type === 'select'"
91
+ :model-value="row.value as FilterOptionValue | undefined"
92
+ :items="selectItems"
93
+ value-key="value"
94
+ placeholder="&nbsp;"
95
+ class="w-full"
96
+ :ui="{ content: 'min-w-fit' }"
97
+ :search-input="{ placeholder: t('common.search') }"
98
+ :data-testid="`${testId}-select`"
99
+ @update:model-value="emit('update:value', $event)"
100
+ >
101
+ <UBadge
102
+ v-if="missing.length"
103
+ color="warning"
104
+ variant="outline"
105
+ class="border border-dashed ring-0 truncate"
106
+ :data-testid="`${testId}-unavailable-option`"
107
+ >
108
+ {{ t('filters.unavailable.option') }}
109
+ </UBadge>
110
+ </USelectMenu>
111
+
112
+ <div v-else-if="field.type === 'multiselect'" class="flex flex-col gap-1">
113
+ <USelectMenu
114
+ :model-value="selectedKnown"
115
+ multiple
116
+ :items="options"
117
+ value-key="value"
118
+ placeholder="&nbsp;"
119
+ class="w-full"
120
+ virtualize
121
+ :reset-search-term-on-select="false"
122
+ :ui="{ content: 'min-w-fit' }"
123
+ :search-input="{
124
+ placeholder: t('common.search'),
125
+ 'data-testid': `${testId}-multiselect-search`,
126
+ }"
127
+ :data-testid="`${testId}-multiselect`"
128
+ @update:model-value="onMultiselect"
129
+ >
130
+ <UTooltip v-if="selectedLabels.length" :text="selectedLabels.join(', ')">
131
+ <UBadge color="secondary" class="truncate">
132
+ {{ selectionLabel }}
133
+ </UBadge>
134
+ </UTooltip>
135
+ </USelectMenu>
136
+
137
+ <div v-if="missing.length" class="flex flex-wrap gap-1">
138
+ <UTooltip
139
+ v-for="value in missing"
140
+ :key="value"
141
+ :text="t('filters.unavailable.option_description')"
142
+ >
143
+ <UBadge
144
+ color="warning"
145
+ variant="outline"
146
+ class="border border-dashed ring-0 gap-1"
147
+ :data-testid="`${testId}-unavailable-option`"
148
+ >
149
+ {{ t('filters.unavailable.option') }}
150
+ <UButton
151
+ color="warning"
152
+ variant="link"
153
+ size="xs"
154
+ icon="ph:x-bold"
155
+ class="p-0"
156
+ :aria-label="t('filters.actions.remove_option')"
157
+ :data-testid="`${testId}-unavailable-option-remove`"
158
+ @click="removeMissing(value)"
159
+ />
160
+ </UBadge>
161
+ </UTooltip>
162
+ </div>
163
+ </div>
164
+
165
+ <div
166
+ v-else-if="field.type === 'number' || field.type === 'price'"
167
+ class="flex items-center gap-2"
168
+ >
169
+ <UInputNumber
170
+ :model-value="asNumber(row.value)"
171
+ class="w-full"
172
+ :format-options="numberFormat"
173
+ :increment="!isRange"
174
+ :decrement="!isRange"
175
+ :data-testid="isRange ? `${testId}-from-input` : `${testId}-input`"
176
+ @update:model-value="emit('update:value', $event ?? undefined)"
177
+ />
178
+ <template v-if="isRange">
179
+ <p class="label-xs">{{ t('filters.and') }}</p>
180
+ <UInputNumber
181
+ :model-value="asNumber(row.to)"
182
+ class="w-full"
183
+ :format-options="numberFormat"
184
+ :increment="false"
185
+ :decrement="false"
186
+ :data-testid="`${testId}-to-input`"
187
+ @update:model-value="emit('update:to', $event ?? undefined)"
188
+ />
189
+ </template>
190
+ </div>
191
+
192
+ <div v-else-if="field.type === 'date'" class="flex items-center gap-2">
193
+ <FiltersDateInput
194
+ :model-value="asString(row.value)"
195
+ :test-id="isRange ? `${testId}-from` : testId"
196
+ @update:model-value="emit('update:value', $event)"
197
+ />
198
+ <template v-if="isRange">
199
+ <p class="label-xs">{{ t('filters.and') }}</p>
200
+ <FiltersDateInput
201
+ :model-value="asString(row.to)"
202
+ :test-id="`${testId}-to`"
203
+ @update:model-value="emit('update:to', $event)"
204
+ />
205
+ </template>
206
+ </div>
207
+
208
+ <UInput
209
+ v-else
210
+ :model-value="asString(row.value)"
211
+ class="w-full"
212
+ :data-testid="`${testId}-text`"
213
+ @update:model-value="emit('update:value', $event === '' ? undefined : String($event))"
214
+ />
215
+ </template>
@@ -11,6 +11,7 @@ const props = defineProps<{
11
11
 
12
12
  const emit = defineEmits<{
13
13
  tabChange: [value: string | number]
14
+ back: []
14
15
  }>()
15
16
 
16
17
  watchEffect(() => {
@@ -28,6 +29,7 @@ watchEffect(() => {
28
29
  :data-testid="testId"
29
30
  class="bg-white sticky top-0 z-10"
30
31
  @tab-change="emit('tabChange', $event)"
32
+ @back="emit('back')"
31
33
  >
32
34
  <template #actions>
33
35
  <div class="flex items-center gap-1.5">
@@ -0,0 +1,81 @@
1
+ <script setup lang="ts">
2
+ import { useQuery } from '@pinia/colada'
3
+ import { computed, toRef } from 'vue'
4
+ import { compilationApi } from '~/api'
5
+ import HtmlPreviewIframe from '~/components/Common/HtmlPreviewIframe.vue'
6
+ import { messageSendFlowTestIds } from '~/utils/testIds.const'
7
+
8
+ defineOptions({ name: 'MessageSendFlowEmailPreview' })
9
+
10
+ /**
11
+ * The compiled email of the Preview step: `/compile` with the operator's
12
+ * parameter values (not strict, so an empty field shows as its placeholder;
13
+ * Confirm is the strict call), the brand cascade applied server-side.
14
+ */
15
+ const props = defineProps<{
16
+ messageGroupId: string
17
+ language: string
18
+ parameters: Record<string, string>
19
+ brandId?: string
20
+ }>()
21
+
22
+ // The panel follows the form live; one compile per pause, not per keystroke.
23
+ const debouncedParameters = refDebounced(toRef(props, 'parameters'), 300)
24
+
25
+ const organization = useEffectiveOrganizationStore()
26
+
27
+ const { data, isPending, isLoading, error } = useQuery({
28
+ key: () => [
29
+ 'send-flow',
30
+ 'email-preview',
31
+ props.messageGroupId,
32
+ props.language,
33
+ props.brandId ?? '',
34
+ JSON.stringify(debouncedParameters.value),
35
+ organization.organizationId,
36
+ ],
37
+ query: () =>
38
+ compilationApi.compile(
39
+ props.messageGroupId,
40
+ {
41
+ language: props.language,
42
+ parameters: { ...debouncedParameters.value },
43
+ strict: false,
44
+ strict_language: true,
45
+ brand_id: props.brandId,
46
+ },
47
+ { skipErrorToast: true },
48
+ ),
49
+ // Keep the last email on screen while the next one compiles: no skeleton, no blank.
50
+ placeholderData: (previousData) => previousData,
51
+ })
52
+
53
+ const compiled = computed(() => (data.value?.render_type === 'email_v1' ? data.value : undefined))
54
+ </script>
55
+
56
+ <template>
57
+ <div class="w-full max-w-[600px]" :data-testid="messageSendFlowTestIds.emailPreview">
58
+ <div v-if="isPending && !compiled" class="space-y-2">
59
+ <USkeleton class="h-6 w-1/3" />
60
+ <USkeleton class="h-4" />
61
+ <USkeleton class="h-32" />
62
+ </div>
63
+ <div
64
+ v-else-if="compiled"
65
+ class="transition-opacity duration-200"
66
+ :class="{ 'opacity-60': isLoading }"
67
+ >
68
+ <p class="mb-2">
69
+ <span class="paragraph-sm-bold">{{ $t('email_preview.subject') }}:&nbsp;</span>
70
+ <span class="paragraph-sm">{{ compiled.subject }}</span>
71
+ </p>
72
+ <HtmlPreviewIframe
73
+ :html="compiled.html"
74
+ title="Email preview"
75
+ :min-height="480"
76
+ class="w-full rounded-lg border border-default bg-white"
77
+ />
78
+ </div>
79
+ <p v-else-if="error" class="text-sm text-muted">{{ $t('email_preview.no_preview') }}</p>
80
+ </div>
81
+ </template>
@@ -0,0 +1,39 @@
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import type { MessageSendFlowLanguage } from '~/composables/useMessageSendFlow'
4
+ import { messageSendFlowTestIds } from '~/utils/testIds.const'
5
+
6
+ defineOptions({ name: 'MessageSendFlowLanguageSelect' })
7
+
8
+ /**
9
+ * The approved Messages of a Sendable group, one radio card per language.
10
+ * Non-approved languages stay visible but disabled, with their status.
11
+ */
12
+ const props = defineProps<{
13
+ languages: MessageSendFlowLanguage[]
14
+ }>()
15
+
16
+ const modelValue = defineModel<string>()
17
+
18
+ const { t } = useI18n()
19
+
20
+ const items = computed(() =>
21
+ props.languages.map((l) => ({
22
+ value: l.code,
23
+ label: l.code.toUpperCase(),
24
+ description: l.approved
25
+ ? t('send_flow.language.approved')
26
+ : t('send_flow.language.not_sendable', { status: t(`status.${l.status}`) }),
27
+ disabled: !l.approved,
28
+ })),
29
+ )
30
+ </script>
31
+
32
+ <template>
33
+ <URadioGroup
34
+ v-model="modelValue"
35
+ :items="items"
36
+ variant="card"
37
+ :data-testid="messageSendFlowTestIds.languageGroup"
38
+ />
39
+ </template>