@dev.smartpricing/message-composer-layer 4.5.1-next.4 → 4.5.1-next.5
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.
- package/README.md +4 -133
- package/app/api/index.ts +0 -1
- package/app/api/messageGroups.ts +1 -5
- package/app/api/meta.ts +36 -0
- package/app/components/Common/MessageGroupSelect.vue +1 -30
- package/app/components/Composer/EmailComposer.vue +1 -5
- package/app/components/Composer/MessageLibrary.vue +8 -0
- package/app/components/Composer/WabaSelectModal.vue +1 -3
- package/app/components/Composer/WhatsappComposer.vue +1 -5
- package/app/components/Layout/BasePage.vue +0 -2
- package/app/components/MetaImport/Button.vue +50 -0
- package/app/components/MetaImport/Dialog.vue +261 -0
- package/app/components/MetaImport/Outcome.vue +136 -0
- package/app/components/MetaImport/ProposalList.vue +192 -0
- package/app/components/TemplateList/BaseTable.vue +22 -1
- package/app/composables/apiErrorMessages.ts +0 -1
- package/app/composables/composerContext.ts +3 -3
- package/app/composables/useMessageGroupWaba.ts +10 -7
- package/app/composables/useTemplateOperations.ts +3 -8
- package/app/pages/index.vue +5 -1
- package/app/pages/template/email/[id].vue +0 -5
- package/app/pages/template/email/create.vue +0 -5
- package/app/pages/template/whatsapp/[id].vue +0 -5
- package/app/pages/template/whatsapp/create.vue +0 -5
- package/app/queries/index.ts +0 -1
- package/app/queries/messageGroups.ts +29 -20
- package/app/queries/meta.ts +91 -1
- package/app/stores/appContext.ts +1 -1
- package/app/types/app-config.d.ts +0 -3
- package/app/types/tracking.ts +0 -33
- package/app/utils/testIds.const.ts +1 -107
- package/app.config.ts +5 -0
- package/i18n/locales/de.ts +64 -269
- package/i18n/locales/en.ts +61 -255
- package/i18n/locales/es.ts +62 -258
- package/i18n/locales/fr.ts +63 -264
- package/i18n/locales/it.ts +65 -260
- package/package.json +4 -4
- package/app/api/automations.ts +0 -74
- package/app/app.config.ts +0 -10
- package/app/components/Automations/ActionCard.vue +0 -174
- package/app/components/Automations/ActionEditor.vue +0 -398
- package/app/components/Automations/Actions.vue +0 -148
- package/app/components/Automations/CloneModal.vue +0 -78
- package/app/components/Automations/Conditions.vue +0 -155
- package/app/components/Automations/Create.vue +0 -114
- package/app/components/Automations/Data.vue +0 -46
- package/app/components/Automations/DeleteModal.vue +0 -80
- package/app/components/Automations/Edit.vue +0 -145
- package/app/components/Automations/Form.vue +0 -282
- package/app/components/Automations/List.vue +0 -370
- package/app/components/Automations/PageGate.vue +0 -50
- package/app/components/Automations/SaveProblems.vue +0 -54
- package/app/components/Automations/Unavailable.vue +0 -71
- package/app/components/Automations/UnavailableBadge.vue +0 -35
- package/app/components/Filters/DateInput.vue +0 -57
- package/app/components/Filters/Editor.vue +0 -163
- package/app/components/Filters/Row.vue +0 -119
- package/app/components/Filters/Summary.vue +0 -215
- package/app/components/Filters/UnavailableRow.vue +0 -74
- package/app/components/Filters/ValueInput.vue +0 -215
- package/app/composables/automationsContext.ts +0 -42
- package/app/composables/useAutomationClone.ts +0 -33
- package/app/composables/useAutomationEditorTrip.ts +0 -77
- package/app/composables/useAutomationSaveProblems.ts +0 -82
- package/app/composables/useAutomationUnavailable.ts +0 -98
- package/app/composables/useAutomationsGate.ts +0 -68
- package/app/composables/useBuiltInOptionLists.ts +0 -44
- package/app/composables/useEditorTripBack.ts +0 -15
- package/app/middleware/automations-enabled.ts +0 -12
- package/app/pages/automations/[id].vue +0 -87
- package/app/pages/automations/index.vue +0 -28
- package/app/pages/automations/new.vue +0 -53
- package/app/queries/automations.ts +0 -206
- package/app/stores/editorTrip.ts +0 -67
- package/app/utils/automations/form.ts +0 -389
- package/app/utils/automations/metadata.ts +0 -71
- package/app/utils/automations/unavailable.ts +0 -90
- package/app/utils/filters/data/countries.json +0 -998
- package/app/utils/filters/data/languages.json +0 -754
- package/app/utils/filters/rows.ts +0 -367
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
MessageGroupProduct,
|
|
4
|
+
MetaImportProposal,
|
|
5
|
+
MetaImportProposalGroup,
|
|
6
|
+
MetaImportResult,
|
|
7
|
+
MetaImportScope,
|
|
8
|
+
} from '@dev.smartpricing/message-composer-utils/types'
|
|
9
|
+
import { useConfirmMetaImportMutation, useMetaImportProposalQuery } from '~/queries'
|
|
10
|
+
import type { WabaImportCheck } from '~/queries/meta'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Import from Meta (ADR 0020): the WABA to import from, when the
|
|
14
|
+
* Organization has several; then the proposal, read from Meta; then the
|
|
15
|
+
* outcome. Nothing is written before the user confirms the proposal.
|
|
16
|
+
* Opened through `useOverlay`: closes with whether an Import was confirmed.
|
|
17
|
+
*/
|
|
18
|
+
const props = defineProps<{
|
|
19
|
+
/** The Organization's WABAs, each with what the check counted. */
|
|
20
|
+
checks: WabaImportCheck[]
|
|
21
|
+
organizationId: string
|
|
22
|
+
/** The Product the Host supplied: the imported Message Groups belong to it. */
|
|
23
|
+
product: MessageGroupProduct
|
|
24
|
+
}>()
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits<{ close: [imported: boolean] }>()
|
|
27
|
+
|
|
28
|
+
const { metaWabaId } = storeToRefs(useAppContextStore())
|
|
29
|
+
|
|
30
|
+
const severalWabas = props.checks.length > 1
|
|
31
|
+
const step = ref<'waba' | 'proposal' | 'result'>(severalWabas ? 'waba' : 'proposal')
|
|
32
|
+
|
|
33
|
+
// The WABA in the radio group: the Host's when it is one of them, else the
|
|
34
|
+
// first that has something to import.
|
|
35
|
+
const selectedWabaId = ref<string | undefined>(
|
|
36
|
+
(
|
|
37
|
+
props.checks.find(({ waba }) => waba.id === metaWabaId.value) ??
|
|
38
|
+
props.checks.find(({ count }) => count > 0)
|
|
39
|
+
)?.waba.id,
|
|
40
|
+
)
|
|
41
|
+
/** The WABA the proposal is read from: set once the choice is made. */
|
|
42
|
+
const wabaId = ref<string | undefined>(severalWabas ? undefined : props.checks[0]?.waba.id)
|
|
43
|
+
|
|
44
|
+
const wabaItems = computed(() =>
|
|
45
|
+
props.checks.map(({ waba, count }) => ({
|
|
46
|
+
value: waba.id,
|
|
47
|
+
label: waba.name || waba.id,
|
|
48
|
+
numbers: waba.phone_numbers.join(', '),
|
|
49
|
+
count,
|
|
50
|
+
// Not `id`: the radio group gives each item one of its own.
|
|
51
|
+
wabaId: waba.id,
|
|
52
|
+
})),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
function chooseWaba() {
|
|
56
|
+
wabaId.value = selectedWabaId.value
|
|
57
|
+
step.value = 'proposal'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const scope = computed<MetaImportScope | undefined>(() =>
|
|
61
|
+
wabaId.value
|
|
62
|
+
? { organization_id: props.organizationId, product: props.product, waba_id: wabaId.value }
|
|
63
|
+
: undefined,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
const { data: proposed, isLoading, error, refetch } = useMetaImportProposalQuery(scope)
|
|
67
|
+
|
|
68
|
+
/** What tells a proposed group from the others: a Meta Template is in one only. */
|
|
69
|
+
const groupKey = (group: MetaImportProposalGroup) => group.templates[0]?.id
|
|
70
|
+
|
|
71
|
+
// The groups of differently named Meta Templates the user split back into
|
|
72
|
+
// the groups their names make. There is no putting them together again.
|
|
73
|
+
const split = ref<Array<string | undefined>>([])
|
|
74
|
+
|
|
75
|
+
function splitGroup(group: MetaImportProposalGroup) {
|
|
76
|
+
split.value = [...split.value, groupKey(group)]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The proposal as the user left it: what is shown, confirmed and reported on. */
|
|
80
|
+
const proposal = computed<MetaImportProposal | undefined>(() => {
|
|
81
|
+
if (!proposed.value) return undefined
|
|
82
|
+
return {
|
|
83
|
+
...proposed.value,
|
|
84
|
+
groups: proposed.value.groups.flatMap((group) =>
|
|
85
|
+
group.name_groups && split.value.includes(groupKey(group))
|
|
86
|
+
? group.name_groups.map((part) => ({ ...part, name_groups: null }))
|
|
87
|
+
: [group],
|
|
88
|
+
),
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
// Everything that can be imported starts ticked: the user unticks.
|
|
93
|
+
const ticked = ref<string[]>([])
|
|
94
|
+
watch(
|
|
95
|
+
proposed,
|
|
96
|
+
(value) => {
|
|
97
|
+
split.value = []
|
|
98
|
+
ticked.value = (value?.groups ?? []).flatMap((group) =>
|
|
99
|
+
group.templates.filter((template) => template.importable).map((template) => template.id),
|
|
100
|
+
)
|
|
101
|
+
},
|
|
102
|
+
{ immediate: true },
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
/** The ticked Meta Templates, grouped as proposed; a group with none ticked is left out. */
|
|
106
|
+
const groupsToImport = computed(() => {
|
|
107
|
+
const tickedIds = new Set(ticked.value)
|
|
108
|
+
return (proposal.value?.groups ?? [])
|
|
109
|
+
.map((group) => ({
|
|
110
|
+
template_ids: group.templates.map(({ id }) => id).filter((id) => tickedIds.has(id)),
|
|
111
|
+
}))
|
|
112
|
+
.filter((group) => group.template_ids.length > 0)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
const { mutateAsync: confirmImport, isLoading: isImporting } = useConfirmMetaImportMutation()
|
|
116
|
+
const result = shallowRef<MetaImportResult>()
|
|
117
|
+
|
|
118
|
+
async function confirm() {
|
|
119
|
+
if (!scope.value || groupsToImport.value.length === 0) return
|
|
120
|
+
try {
|
|
121
|
+
const answer = await confirmImport({ ...scope.value, groups: groupsToImport.value })
|
|
122
|
+
// A demo session is answered without an outcome: nothing was written.
|
|
123
|
+
result.value = { groups: answer.groups ?? [], refreshed: answer.refreshed ?? [] }
|
|
124
|
+
step.value = 'result'
|
|
125
|
+
} catch {
|
|
126
|
+
// The API client has told the user; the proposal stays to try again.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function close() {
|
|
131
|
+
if (isImporting.value) return
|
|
132
|
+
emit('close', !!result.value)
|
|
133
|
+
}
|
|
134
|
+
</script>
|
|
135
|
+
|
|
136
|
+
<template>
|
|
137
|
+
<UModal
|
|
138
|
+
:title="
|
|
139
|
+
step === 'result' ? $t('dialogs.meta_import.result_title') : $t('dialogs.meta_import.title')
|
|
140
|
+
"
|
|
141
|
+
:description="$t('dialogs.meta_import.description')"
|
|
142
|
+
close-icon="ph:x"
|
|
143
|
+
:close="{ onClick: close }"
|
|
144
|
+
:dismissible="false"
|
|
145
|
+
:ui="{ content: 'sm:max-w-3xl' }"
|
|
146
|
+
data-testid="meta-import-dialog"
|
|
147
|
+
>
|
|
148
|
+
<template #body>
|
|
149
|
+
<div v-if="step === 'waba'" class="flex flex-col gap-3">
|
|
150
|
+
<p class="text-sm text-muted">{{ $t('dialogs.meta_import.choose_waba') }}</p>
|
|
151
|
+
<URadioGroup
|
|
152
|
+
v-model="selectedWabaId"
|
|
153
|
+
:items="wabaItems"
|
|
154
|
+
variant="table"
|
|
155
|
+
class="w-full"
|
|
156
|
+
:ui="{ item: 'w-full' }"
|
|
157
|
+
data-testid="meta-import-waba-options"
|
|
158
|
+
>
|
|
159
|
+
<template #description="{ item }">
|
|
160
|
+
<span class="flex flex-col">
|
|
161
|
+
<span>{{ item.numbers || $t('dialogs.select_waba.no_numbers') }}</span>
|
|
162
|
+
<span class="text-xs text-dimmed font-mono">{{ item.wabaId }}</span>
|
|
163
|
+
<span class="text-xs">
|
|
164
|
+
{{ $t('dialogs.meta_import.waba_count', { count: item.count }) }}
|
|
165
|
+
</span>
|
|
166
|
+
</span>
|
|
167
|
+
</template>
|
|
168
|
+
</URadioGroup>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<MetaImportOutcome
|
|
172
|
+
v-else-if="step === 'result' && result && proposal"
|
|
173
|
+
:result="result"
|
|
174
|
+
:proposal="proposal"
|
|
175
|
+
/>
|
|
176
|
+
|
|
177
|
+
<div
|
|
178
|
+
v-else-if="isLoading"
|
|
179
|
+
class="flex items-center justify-center gap-2 py-10 text-sm text-muted"
|
|
180
|
+
data-testid="meta-import-loading"
|
|
181
|
+
>
|
|
182
|
+
<UIcon name="ph:circle-notch" class="size-5 animate-spin" />
|
|
183
|
+
{{ $t('dialogs.meta_import.loading') }}
|
|
184
|
+
</div>
|
|
185
|
+
|
|
186
|
+
<UAlert
|
|
187
|
+
v-else-if="error || !proposal"
|
|
188
|
+
color="error"
|
|
189
|
+
variant="subtle"
|
|
190
|
+
icon="ph:warning-circle"
|
|
191
|
+
:title="$t('dialogs.meta_import.load_failed_title')"
|
|
192
|
+
:description="$t('dialogs.meta_import.load_failed_description')"
|
|
193
|
+
:actions="[
|
|
194
|
+
{
|
|
195
|
+
label: $t('dialogs.meta_import.retry'),
|
|
196
|
+
color: 'neutral',
|
|
197
|
+
variant: 'outline',
|
|
198
|
+
onClick: () => void refetch(),
|
|
199
|
+
},
|
|
200
|
+
]"
|
|
201
|
+
data-testid="meta-import-load-failed"
|
|
202
|
+
/>
|
|
203
|
+
|
|
204
|
+
<MetaImportProposalList
|
|
205
|
+
v-else
|
|
206
|
+
v-model:ticked="ticked"
|
|
207
|
+
:proposal="proposal"
|
|
208
|
+
@split="splitGroup"
|
|
209
|
+
/>
|
|
210
|
+
</template>
|
|
211
|
+
|
|
212
|
+
<template #footer>
|
|
213
|
+
<div class="flex items-center gap-2 justify-end w-full">
|
|
214
|
+
<span
|
|
215
|
+
v-if="step === 'proposal' && proposal && !isLoading && !error"
|
|
216
|
+
class="text-sm text-muted mr-auto"
|
|
217
|
+
data-testid="meta-import-selection"
|
|
218
|
+
>
|
|
219
|
+
{{
|
|
220
|
+
$t('dialogs.meta_import.selection', {
|
|
221
|
+
groups: groupsToImport.length,
|
|
222
|
+
templates: ticked.length,
|
|
223
|
+
})
|
|
224
|
+
}}
|
|
225
|
+
</span>
|
|
226
|
+
|
|
227
|
+
<UButton
|
|
228
|
+
v-if="step === 'result'"
|
|
229
|
+
:label="$t('dialogs.meta_import.close')"
|
|
230
|
+
data-testid="meta-import-close"
|
|
231
|
+
@click="close"
|
|
232
|
+
/>
|
|
233
|
+
<template v-else>
|
|
234
|
+
<UButton
|
|
235
|
+
variant="outline"
|
|
236
|
+
color="neutral"
|
|
237
|
+
:label="$t('common.actions.cancel')"
|
|
238
|
+
:disabled="isImporting"
|
|
239
|
+
data-testid="meta-import-cancel"
|
|
240
|
+
@click="close"
|
|
241
|
+
/>
|
|
242
|
+
<UButton
|
|
243
|
+
v-if="step === 'waba'"
|
|
244
|
+
:label="$t('dialogs.meta_import.continue')"
|
|
245
|
+
:disabled="!selectedWabaId"
|
|
246
|
+
data-testid="meta-import-continue"
|
|
247
|
+
@click="chooseWaba"
|
|
248
|
+
/>
|
|
249
|
+
<UButton
|
|
250
|
+
v-else
|
|
251
|
+
:label="$t('dialogs.meta_import.confirm')"
|
|
252
|
+
:loading="isImporting"
|
|
253
|
+
:disabled="isLoading || !!error || groupsToImport.length === 0"
|
|
254
|
+
data-testid="meta-import-confirm"
|
|
255
|
+
@click="confirm"
|
|
256
|
+
/>
|
|
257
|
+
</template>
|
|
258
|
+
</div>
|
|
259
|
+
</template>
|
|
260
|
+
</UModal>
|
|
261
|
+
</template>
|
|
@@ -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>
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
MESSAGE_GROUP_PRODUCTS,
|
|
6
6
|
MESSAGE_STATUS,
|
|
7
7
|
type MessageGroupListSort,
|
|
8
|
+
type MessageGroupProduct,
|
|
8
9
|
type MessageGroupWithMessageSummary,
|
|
9
10
|
type PaginationMeta,
|
|
10
11
|
type RenderType,
|
|
@@ -203,8 +204,17 @@ const categoryItems = computed(() =>
|
|
|
203
204
|
toSelectItems(MESSAGE_GROUP_CATEGORIES, 'categories', t('common.all')),
|
|
204
205
|
)
|
|
205
206
|
const statusItems = computed(() => toSelectItems(MESSAGE_STATUS, 'status', t('common.all')))
|
|
207
|
+
// Only the Products that have Message Groups today. The Host's own Product
|
|
208
|
+
// is always offered, since the filter starts on it.
|
|
209
|
+
const PRODUCTS_WITH_MESSAGES: readonly MessageGroupProduct[] = ['connect', 'chat']
|
|
206
210
|
const productItems = computed(() =>
|
|
207
|
-
toSelectItems(
|
|
211
|
+
toSelectItems(
|
|
212
|
+
MESSAGE_GROUP_PRODUCTS.filter(
|
|
213
|
+
(product) => PRODUCTS_WITH_MESSAGES.includes(product) || product === appContext.product,
|
|
214
|
+
),
|
|
215
|
+
'products',
|
|
216
|
+
t('pages.message_library.all_products'),
|
|
217
|
+
),
|
|
208
218
|
)
|
|
209
219
|
|
|
210
220
|
const visibilityItems = computed(() =>
|
|
@@ -322,6 +332,17 @@ const paginationSummary = computed(() => {
|
|
|
322
332
|
v-model:sorting="sorting"
|
|
323
333
|
:data-testid="templateListTableTestIds.table"
|
|
324
334
|
>
|
|
335
|
+
<!-- Shown instead of the "no data" row while a list with no rows is loading. -->
|
|
336
|
+
<template #loading>
|
|
337
|
+
<div
|
|
338
|
+
class="flex items-center justify-center gap-2 text-muted"
|
|
339
|
+
:data-testid="templateListTableTestIds.loading"
|
|
340
|
+
>
|
|
341
|
+
<UIcon name="ph:circle-notch-bold" class="size-4 animate-spin" />
|
|
342
|
+
<span>{{ t('pages.message_library.loading') }}</span>
|
|
343
|
+
</div>
|
|
344
|
+
</template>
|
|
345
|
+
|
|
325
346
|
<template #name-cell="{ row }">
|
|
326
347
|
<div
|
|
327
348
|
class="flex items-center gap-2"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const CODE_TO_KEY: Record<string, string> = {
|
|
2
2
|
'session.missing': 'common.errors.session_expired',
|
|
3
3
|
'session.expired': 'common.errors.session_expired',
|
|
4
|
-
AUTOMATION_ENGINE_REJECTED: 'automations.toast.engine_rejected',
|
|
5
4
|
}
|
|
6
5
|
|
|
7
6
|
function descriptionKeyByStatus(status: number): string {
|
|
@@ -17,9 +17,9 @@ export interface ComposerContext {
|
|
|
17
17
|
mainLanguage?: Ref<string>
|
|
18
18
|
default_tags?: Ref<string[]>
|
|
19
19
|
/**
|
|
20
|
-
* The WABA the Host works on.
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* The WABA the Host works on. A new Message Group is submitted to it and
|
|
21
|
+
* the user is not asked, as long as it is one of the Organization's
|
|
22
|
+
* (ADR 0015). Without it the user picks when there are several.
|
|
23
23
|
*/
|
|
24
24
|
metaWabaId?: Ref<string>
|
|
25
25
|
isAdmin?: Ref<boolean>
|
|
@@ -43,9 +43,10 @@ export function useMessageGroupWaba(storedWabaId: MaybeRefOrGetter<string | null
|
|
|
43
43
|
)
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* The WABA to name in a submission.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
46
|
+
* The WABA to name in a submission. At the first submission of a Message
|
|
47
|
+
* Group whose Organization has several WABAs, it is the Host's when the
|
|
48
|
+
* Host passed one of them, otherwise the user is asked. In every other
|
|
49
|
+
* case none is named and the backend resolves it. A lookup that has not
|
|
49
50
|
* answered yet is waited for; one that failed leaves it to the backend.
|
|
50
51
|
* Returns null when the user gives up.
|
|
51
52
|
*/
|
|
@@ -55,10 +56,12 @@ export function useMessageGroupWaba(storedWabaId: MaybeRefOrGetter<string | null
|
|
|
55
56
|
const candidates = wabas.value
|
|
56
57
|
if (!candidates || candidates.length < 2) return {}
|
|
57
58
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
:
|
|
61
|
-
|
|
59
|
+
const hostWabaId = metaWabaId.value
|
|
60
|
+
if (hostWabaId && candidates.some((candidate) => candidate.id === hostWabaId)) {
|
|
61
|
+
return { wabaId: hostWabaId }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const chosen = await modal.open({ wabas: candidates }).result
|
|
62
65
|
|
|
63
66
|
return chosen ? { wabaId: chosen } : null
|
|
64
67
|
}
|