@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,136 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ MetaImportProposal,
4
+ MetaImportResult,
5
+ } from '@dev.smartpricing/message-composer-utils/types'
6
+ import { useMessageGroupNamesQuery } from '~/queries'
7
+
8
+ /**
9
+ * The outcome of a confirmed Import: how many Message Groups were written,
10
+ * which were not and why, and which were written without one of their
11
+ * languages. Names come from the proposal the user confirmed: the answer
12
+ * carries Meta Template ids only. It also says how many Message Groups
13
+ * imported earlier were brought up to date with Meta, and which were not.
14
+ */
15
+ const props = defineProps<{
16
+ result: MetaImportResult
17
+ proposal: MetaImportProposal
18
+ }>()
19
+
20
+ const proposed = computed(() => {
21
+ const byId = new Map<string, { group: string; template: string }>()
22
+ for (const group of props.proposal.groups) {
23
+ for (const template of group.templates) {
24
+ byId.set(template.id, {
25
+ group: group.name,
26
+ template: `${template.name} · ${template.language_code}`,
27
+ })
28
+ }
29
+ }
30
+ return byId
31
+ })
32
+
33
+ const groupName = (templateIds: string[]) =>
34
+ proposed.value.get(templateIds[0] ?? '')?.group ?? templateIds.join(', ')
35
+
36
+ const importedCount = computed(() => props.result.groups.filter((group) => group.written).length)
37
+
38
+ const failed = computed(() =>
39
+ props.result.groups
40
+ .filter((group) => !group.written)
41
+ .map((group) => ({
42
+ key: group.template_ids.join(','),
43
+ name: groupName(group.template_ids),
44
+ reason: group.reason,
45
+ })),
46
+ )
47
+
48
+ /** Meta Templates left out of a Message Group that was written. */
49
+ const leftOut = computed(() =>
50
+ props.result.groups
51
+ .filter((group) => group.written)
52
+ .flatMap((group) =>
53
+ group.templates
54
+ .filter((template) => !template.written)
55
+ .map((template) => ({
56
+ key: template.id,
57
+ group: groupName(group.template_ids),
58
+ template: proposed.value.get(template.id)?.template ?? template.id,
59
+ reason: template.reason,
60
+ })),
61
+ ),
62
+ )
63
+
64
+ const refreshedCount = computed(
65
+ () => props.result.refreshed.filter((group) => group.refreshed).length,
66
+ )
67
+
68
+ // The answer names a Message Group imported earlier by id alone: its name is
69
+ // looked up, and the id stands in when the lookup fails.
70
+ const { data: names } = useMessageGroupNamesQuery(() =>
71
+ props.result.refreshed.filter((group) => !group.refreshed).map((group) => group.message_group_id),
72
+ )
73
+
74
+ const notRefreshed = computed(() =>
75
+ props.result.refreshed
76
+ .filter((group) => !group.refreshed)
77
+ .map((group) => ({
78
+ key: group.message_group_id,
79
+ name: names.value?.[group.message_group_id] ?? group.message_group_id,
80
+ reason: group.reason,
81
+ })),
82
+ )
83
+ </script>
84
+
85
+ <template>
86
+ <div class="flex flex-col gap-4" data-testid="meta-import-result">
87
+ <UAlert
88
+ :color="importedCount > 0 ? 'success' : 'neutral'"
89
+ variant="subtle"
90
+ icon="ph:check-circle"
91
+ :title="$t('dialogs.meta_import.imported_count', { count: importedCount })"
92
+ data-testid="meta-import-result-imported"
93
+ />
94
+
95
+ <div v-if="failed.length > 0" data-testid="meta-import-result-failed">
96
+ <p class="text-sm font-medium mb-1">{{ $t('dialogs.meta_import.failed_title') }}</p>
97
+ <ul class="flex flex-col gap-1 text-sm">
98
+ <li v-for="group in failed" :key="group.key">
99
+ <span class="font-medium">{{ group.name }}</span>
100
+ <span v-if="group.reason" class="text-error">
101
+ — {{ $t(`dialogs.meta_import.group_failures.${group.reason}`) }}
102
+ </span>
103
+ </li>
104
+ </ul>
105
+ </div>
106
+
107
+ <div v-if="leftOut.length > 0" data-testid="meta-import-result-left-out">
108
+ <p class="text-sm font-medium mb-1">{{ $t('dialogs.meta_import.partial_title') }}</p>
109
+ <ul class="flex flex-col gap-1 text-sm">
110
+ <li v-for="item in leftOut" :key="item.key">
111
+ <span class="font-medium">{{ item.group }}</span>
112
+ <span class="text-xs text-dimmed font-mono"> {{ item.template }}</span>
113
+ <span v-if="item.reason" class="text-error">
114
+ — {{ $t(`dialogs.meta_import.reasons.${item.reason}`) }}
115
+ </span>
116
+ </li>
117
+ </ul>
118
+ </div>
119
+
120
+ <p v-if="refreshedCount > 0" class="text-sm text-muted" data-testid="meta-import-refreshed">
121
+ {{ $t('dialogs.meta_import.refreshed_count', { count: refreshedCount }) }}
122
+ </p>
123
+
124
+ <div v-if="notRefreshed.length > 0" data-testid="meta-import-result-not-refreshed">
125
+ <p class="text-sm font-medium mb-1">{{ $t('dialogs.meta_import.refresh_failed_title') }}</p>
126
+ <ul class="flex flex-col gap-1 text-sm">
127
+ <li v-for="group in notRefreshed" :key="group.key">
128
+ <span class="font-medium">{{ group.name }}</span>
129
+ <span v-if="group.reason" class="text-error">
130
+ — {{ $t(`dialogs.meta_import.refresh_failures.${group.reason}`) }}
131
+ </span>
132
+ </li>
133
+ </ul>
134
+ </div>
135
+ </div>
136
+ </template>
@@ -0,0 +1,192 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ MessageStatus,
4
+ MetaImportProposal,
5
+ MetaImportProposalGroup,
6
+ MetaImportProposalTemplate,
7
+ } from '@dev.smartpricing/message-composer-utils/types'
8
+ import { getLanguageDisplayName } from '@dev.smartpricing/message-composer-utils/utils'
9
+
10
+ /**
11
+ * The proposal of an Import (ADR 0020): each proposed Message Group with its
12
+ * Meta Templates, a tick box per group and per language. A Meta Template
13
+ * that cannot be imported is shown with its reason and has no box to tick.
14
+ * A group made of differently named Meta Templates can be split back into
15
+ * the groups their names make.
16
+ */
17
+ defineProps<{
18
+ proposal: MetaImportProposal
19
+ }>()
20
+
21
+ const emit = defineEmits<{ split: [group: MetaImportProposalGroup] }>()
22
+
23
+ /** The ids of the ticked Meta Templates. */
24
+ const ticked = defineModel<string[]>('ticked', { required: true })
25
+
26
+ const { locale } = useI18n()
27
+
28
+ const tickedIds = computed(() => new Set(ticked.value))
29
+
30
+ const importableIds = (group: MetaImportProposalGroup) =>
31
+ group.templates.filter((template) => template.importable).map((template) => template.id)
32
+
33
+ function groupState(group: MetaImportProposalGroup): boolean | 'indeterminate' {
34
+ const ids = importableIds(group)
35
+ const count = ids.filter((id) => tickedIds.value.has(id)).length
36
+ if (count === 0) return false
37
+ return count === ids.length ? true : 'indeterminate'
38
+ }
39
+
40
+ function setGroup(group: MetaImportProposalGroup, value: boolean | 'indeterminate') {
41
+ const ids = importableIds(group)
42
+ const others = ticked.value.filter((id) => !ids.includes(id))
43
+ ticked.value = value === true ? [...others, ...ids] : others
44
+ }
45
+
46
+ function setTemplate(template: MetaImportProposalTemplate, value: boolean | 'indeterminate') {
47
+ const others = ticked.value.filter((id) => id !== template.id)
48
+ ticked.value = value === true ? [...others, template.id] : others
49
+ }
50
+
51
+ /** The composer language the Meta Template lands on, or Meta's code when it lands on none. */
52
+ const languageName = (template: MetaImportProposalTemplate) =>
53
+ template.language_id
54
+ ? getLanguageDisplayName(template.language_id, locale.value)
55
+ : template.language_code
56
+
57
+ const STATUS_COLORS = {
58
+ draft: 'neutral',
59
+ approved: 'success',
60
+ rejected: 'error',
61
+ pending: 'warning',
62
+ } as const satisfies Record<MessageStatus, string>
63
+
64
+ /** Meta's own word for a status the composer shows as pending (`PAUSED`, `DISABLED`). */
65
+ const metaStatusNote = (template: MetaImportProposalTemplate) =>
66
+ ['APPROVED', 'PENDING', 'REJECTED'].includes(template.meta_status) ? '' : template.meta_status
67
+ </script>
68
+
69
+ <template>
70
+ <div class="flex flex-col gap-3" data-testid="meta-import-proposal">
71
+ <p class="text-sm text-muted">{{ $t('dialogs.meta_import.intro') }}</p>
72
+
73
+ <UAlert
74
+ v-if="proposal.fallback_used"
75
+ color="warning"
76
+ variant="subtle"
77
+ icon="ph:warning"
78
+ :title="$t('dialogs.meta_import.fallback_title')"
79
+ :description="$t('dialogs.meta_import.fallback_description')"
80
+ data-testid="meta-import-fallback"
81
+ />
82
+
83
+ <p v-if="proposal.groups.length === 0" class="text-sm" data-testid="meta-import-empty">
84
+ {{ $t('dialogs.meta_import.empty') }}
85
+ </p>
86
+
87
+ <section
88
+ v-for="group in proposal.groups"
89
+ :key="group.templates[0]?.id"
90
+ class="rounded-lg border border-default"
91
+ data-testid="meta-import-group"
92
+ >
93
+ <header class="flex items-center gap-3 px-3 py-2 bg-elevated/50 rounded-t-lg">
94
+ <UCheckbox
95
+ :model-value="groupState(group)"
96
+ :disabled="importableIds(group).length === 0"
97
+ :aria-label="group.name"
98
+ data-testid="meta-import-group-checkbox"
99
+ @update:model-value="setGroup(group, $event)"
100
+ />
101
+ <span class="font-medium truncate">{{ group.name }}</span>
102
+ <UBadge
103
+ v-if="group.category"
104
+ :label="$t(`categories.${group.category}`)"
105
+ color="neutral"
106
+ variant="subtle"
107
+ size="sm"
108
+ />
109
+ <template v-if="group.name_groups">
110
+ <span class="text-xs text-muted ml-auto" data-testid="meta-import-group-merged">
111
+ {{ $t('dialogs.meta_import.merged_hint') }}
112
+ </span>
113
+ <UButton
114
+ :label="$t('dialogs.meta_import.split')"
115
+ icon="ph:arrows-split"
116
+ color="neutral"
117
+ variant="outline"
118
+ size="xs"
119
+ class="shrink-0"
120
+ data-testid="meta-import-group-split"
121
+ @click="emit('split', group)"
122
+ />
123
+ </template>
124
+ </header>
125
+
126
+ <ul class="divide-y divide-default">
127
+ <li
128
+ v-for="template in group.templates"
129
+ :key="template.id"
130
+ class="flex items-start gap-3 px-3 py-2"
131
+ data-testid="meta-import-template"
132
+ >
133
+ <UCheckbox
134
+ v-if="template.importable"
135
+ :model-value="tickedIds.has(template.id)"
136
+ :aria-label="`${languageName(template)} ${template.name}`"
137
+ class="mt-0.5"
138
+ data-testid="meta-import-template-checkbox"
139
+ @update:model-value="setTemplate(template, $event)"
140
+ />
141
+ <UIcon v-else name="ph:prohibit" class="size-4 mt-0.5 shrink-0 text-error" />
142
+
143
+ <div class="flex flex-col gap-1 min-w-0 flex-1">
144
+ <div class="flex flex-wrap items-center gap-x-2 gap-y-1">
145
+ <span class="text-sm" :class="{ 'text-muted': !template.importable }">
146
+ {{ languageName(template) }}
147
+ </span>
148
+ <span class="text-xs text-dimmed font-mono break-all">
149
+ {{ template.name }} · {{ template.language_code }}
150
+ </span>
151
+ </div>
152
+
153
+ <p
154
+ v-if="!template.importable"
155
+ class="text-xs text-error"
156
+ data-testid="meta-import-template-reason"
157
+ >
158
+ {{ $t('dialogs.meta_import.not_importable') }}:
159
+ {{ template.reason ? $t(`dialogs.meta_import.reasons.${template.reason}`) : '' }}
160
+ </p>
161
+ <p
162
+ v-for="warning in template.warnings"
163
+ :key="warning"
164
+ class="flex items-start gap-1 text-xs text-warning"
165
+ data-testid="meta-import-template-warning"
166
+ >
167
+ <UIcon name="ph:warning" class="size-3.5 mt-px shrink-0" />
168
+ {{ $t(`dialogs.meta_import.warnings.${warning}`) }}
169
+ </p>
170
+ </div>
171
+
172
+ <UBadge
173
+ leading-icon="ph:circle-fill"
174
+ :label="
175
+ metaStatusNote(template)
176
+ ? `${$t(`status.${template.status}`)} (${metaStatusNote(template)})`
177
+ : $t(`status.${template.status}`)
178
+ "
179
+ :color="STATUS_COLORS[template.status]"
180
+ variant="outline"
181
+ size="sm"
182
+ class="shrink-0"
183
+ />
184
+ </li>
185
+ </ul>
186
+ </section>
187
+
188
+ <p v-if="proposal.held_count > 0" class="text-sm text-muted" data-testid="meta-import-held">
189
+ {{ $t('dialogs.meta_import.held_count', { count: proposal.held_count }) }}
190
+ </p>
191
+ </div>
192
+ </template>