@dev.smartpricing/message-composer-layer 4.4.1-next.0 → 4.5.1-automation.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +182 -7
- package/app/api/automations.ts +74 -0
- package/app/api/brands.ts +20 -13
- package/app/api/client.ts +3 -6
- package/app/api/dynamicValues.ts +2 -1
- package/app/api/index.ts +1 -0
- package/app/api/media.ts +6 -3
- package/app/api/messageGroups.ts +11 -3
- package/app/api/meta.ts +62 -4
- package/app/api/organization.ts +10 -1
- package/app/api/tracking.ts +2 -2
- package/app/app.config.ts +10 -0
- package/app/components/Automations/ActionCard.vue +174 -0
- package/app/components/Automations/ActionEditor.vue +398 -0
- package/app/components/Automations/Actions.vue +158 -0
- package/app/components/Automations/CloneModal.vue +78 -0
- package/app/components/Automations/Conditions.vue +155 -0
- package/app/components/Automations/Create.vue +114 -0
- package/app/components/Automations/Data.vue +46 -0
- package/app/components/Automations/DeleteModal.vue +80 -0
- package/app/components/Automations/Edit.vue +145 -0
- package/app/components/Automations/Form.vue +282 -0
- package/app/components/Automations/List.vue +370 -0
- package/app/components/Automations/PageGate.vue +50 -0
- package/app/components/Automations/SaveProblems.vue +54 -0
- package/app/components/Automations/Unavailable.vue +71 -0
- package/app/components/Automations/UnavailableBadge.vue +35 -0
- package/app/components/Common/AppContextErrors.vue +2 -2
- package/app/components/Common/MessageGroupSelect.vue +43 -3
- package/app/components/Common/OrganizationGate.vue +51 -0
- package/app/components/Common/OrganizationSelect.vue +27 -0
- package/app/components/Common/WhatsappNotConfigured.vue +20 -0
- package/app/components/Composer/EmailComposer.vue +9 -1
- package/app/components/Composer/MessageLibrary.vue +8 -0
- package/app/components/Composer/WabaSelectModal.vue +73 -0
- package/app/components/Composer/WhatsappComposer.vue +83 -4
- package/app/components/Editor/RichTextEditor.vue +14 -2
- package/app/components/Filters/DateInput.vue +57 -0
- package/app/components/Filters/Editor.vue +163 -0
- package/app/components/Filters/Row.vue +119 -0
- package/app/components/Filters/Summary.vue +215 -0
- package/app/components/Filters/UnavailableRow.vue +74 -0
- package/app/components/Filters/ValueInput.vue +215 -0
- package/app/components/Layout/BasePage.vue +2 -0
- package/app/components/MessageSendFlow/EmailPreview.vue +3 -0
- package/app/components/MessageSendFlow/MessageSendFlow.vue +15 -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/components/Whatsapp/Preview.vue +5 -12
- package/app/components/Whatsapp/Translator/Header.vue +4 -19
- package/app/composables/apiErrorMessages.ts +1 -0
- package/app/composables/automationsContext.ts +42 -0
- package/app/composables/composerContext.ts +5 -5
- package/app/composables/useAutomationClone.ts +33 -0
- package/app/composables/useAutomationEditorTrip.ts +77 -0
- package/app/composables/useAutomationSaveProblems.ts +82 -0
- package/app/composables/useAutomationUnavailable.ts +98 -0
- package/app/composables/useAutomationsGate.ts +68 -0
- package/app/composables/useBuiltInOptionLists.ts +44 -0
- package/app/composables/useEditorTripBack.ts +15 -0
- package/app/composables/useEffectiveOrganization.ts +34 -0
- package/app/composables/useMessageGroupWaba.ts +76 -0
- package/app/composables/useMessageSendFlow.ts +46 -8
- package/app/composables/usePagedMessageGroups.ts +14 -2
- package/app/composables/useTemplateOperations.ts +18 -4
- package/app/composables/useTracking.ts +14 -5
- package/app/composables/useWhatsappConfiguration.ts +32 -0
- package/app/layouts/default.vue +4 -1
- package/app/middleware/automations-enabled.ts +12 -0
- package/app/pages/automations/[id].vue +87 -0
- package/app/pages/automations/index.vue +28 -0
- package/app/pages/automations/new.vue +53 -0
- package/app/pages/brands.vue +1 -0
- package/app/pages/images.vue +4 -0
- package/app/pages/index.vue +6 -1
- package/app/pages/preview/[id].vue +2 -0
- package/app/pages/template/email/[id].vue +5 -0
- package/app/pages/template/email/create.vue +5 -0
- package/app/pages/template/whatsapp/[id].vue +6 -0
- package/app/pages/template/whatsapp/create.vue +5 -0
- package/app/queries/automations.ts +206 -0
- package/app/queries/brands.ts +27 -7
- package/app/queries/compilation.ts +15 -2
- package/app/queries/dynamicValues.ts +13 -2
- package/app/queries/index.ts +1 -0
- package/app/queries/media.ts +8 -3
- package/app/queries/messageGroups.ts +60 -25
- package/app/queries/meta.ts +100 -5
- package/app/stores/appContext.ts +9 -45
- package/app/stores/editorTrip.ts +67 -0
- package/app/stores/effectiveOrganization.ts +128 -0
- package/app/stores/emailEditor.ts +5 -1
- package/app/stores/metaSubmission.ts +7 -17
- package/app/types/app-config.d.ts +3 -0
- package/app/types/tracking.ts +33 -0
- package/app/utils/automations/form.ts +389 -0
- package/app/utils/automations/metadata.ts +71 -0
- package/app/utils/automations/unavailable.ts +90 -0
- package/app/utils/filters/data/countries.json +998 -0
- package/app/utils/filters/data/languages.json +754 -0
- package/app/utils/filters/rows.ts +367 -0
- package/app/utils/testIds.const.ts +108 -0
- package/i18n/locales/de.ts +363 -0
- package/i18n/locales/en.ts +345 -0
- package/i18n/locales/es.ts +349 -0
- package/i18n/locales/fr.ts +357 -0
- package/i18n/locales/it.ts +354 -0
- package/package.json +4 -4
- package/app.config.ts +0 -5
|
@@ -12,7 +12,6 @@ import EmailPreview from './EmailPreview.vue'
|
|
|
12
12
|
import LanguageSelect from './LanguageSelect.vue'
|
|
13
13
|
import ParametersForm from './ParametersForm.vue'
|
|
14
14
|
import { useMessageSendFlow, type MessageSendFlowEmits } from '~/composables/useMessageSendFlow'
|
|
15
|
-
import { useTracking } from '~/composables/useTracking'
|
|
16
15
|
import type { MessageSendFlowStep } from '~/types/tracking'
|
|
17
16
|
import { messageSendFlowTestIds } from '~/utils/testIds.const'
|
|
18
17
|
|
|
@@ -39,6 +38,16 @@ const props = withDefaults(
|
|
|
39
38
|
parameters?: Record<string, string>
|
|
40
39
|
/** Brand override passed to `/compile`. */
|
|
41
40
|
brandId?: string
|
|
41
|
+
/**
|
|
42
|
+
* The Organization the flow works on (ADR 0014), e.g. the conversation's.
|
|
43
|
+
* Unset, the one the layer resolved. The flow never shows a selector.
|
|
44
|
+
*/
|
|
45
|
+
organizationId?: string
|
|
46
|
+
/**
|
|
47
|
+
* The WABA the Host sends from: only WhatsApp groups on it are offered
|
|
48
|
+
* (ADR 0015). Unset, the groups of every WABA of the Organization.
|
|
49
|
+
*/
|
|
50
|
+
wabaId?: string
|
|
42
51
|
/**
|
|
43
52
|
* Where to render the action bar (Cancel, Back, Next, Confirm): a selector
|
|
44
53
|
* or element in the host's container, e.g. a `UModal` footer. Unset, the
|
|
@@ -53,7 +62,6 @@ const groupId = defineModel<string>('messageGroupId')
|
|
|
53
62
|
const emit = defineEmits<MessageSendFlowEmits>()
|
|
54
63
|
|
|
55
64
|
const { t } = useI18n()
|
|
56
|
-
const { trackEvent } = useTracking()
|
|
57
65
|
|
|
58
66
|
const {
|
|
59
67
|
group,
|
|
@@ -70,12 +78,15 @@ const {
|
|
|
70
78
|
compiling,
|
|
71
79
|
canConfirm,
|
|
72
80
|
confirm,
|
|
81
|
+
trackEvent,
|
|
73
82
|
} = useMessageSendFlow({
|
|
74
83
|
groupId,
|
|
75
84
|
renderType: () => props.renderType,
|
|
76
85
|
preferredLanguage: () => props.language,
|
|
77
86
|
prefill: () => props.parameters,
|
|
78
87
|
brandId: () => props.brandId,
|
|
88
|
+
organizationId: () => props.organizationId,
|
|
89
|
+
wabaId: () => props.wabaId,
|
|
79
90
|
emit,
|
|
80
91
|
})
|
|
81
92
|
|
|
@@ -152,6 +163,8 @@ function cancel() {
|
|
|
152
163
|
<MessageGroupSelect
|
|
153
164
|
v-model="groupId"
|
|
154
165
|
:render-type="renderType"
|
|
166
|
+
:organization-id="organizationId"
|
|
167
|
+
:waba-id="wabaId"
|
|
155
168
|
eligibility="sendable"
|
|
156
169
|
class="w-full"
|
|
157
170
|
/>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import MetaImportDialog from '~/components/MetaImport/Dialog.vue'
|
|
3
|
+
import { useMetaImportCheckQuery } from '~/queries'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The Import from Meta button of the Message Group list (ADR 0020). It is
|
|
7
|
+
* there only when a WABA of the Organization holds Meta Templates the
|
|
8
|
+
* composer does not, and says how many. The check behind it runs on its own:
|
|
9
|
+
* the list never waits for it.
|
|
10
|
+
*/
|
|
11
|
+
const props = defineProps<{
|
|
12
|
+
/** False until the list has loaded: the check is asked only after it. */
|
|
13
|
+
enabled: boolean
|
|
14
|
+
}>()
|
|
15
|
+
|
|
16
|
+
const emit = defineEmits<{
|
|
17
|
+
/** An Import was confirmed: the list holds new WhatsApp Message Groups. */
|
|
18
|
+
imported: []
|
|
19
|
+
}>()
|
|
20
|
+
|
|
21
|
+
const appContext = useAppContextStore()
|
|
22
|
+
const organization = useEffectiveOrganizationStore()
|
|
23
|
+
|
|
24
|
+
const { data: checks } = useMetaImportCheckQuery({ enabled: () => props.enabled })
|
|
25
|
+
|
|
26
|
+
const count = computed(() => (checks.value ?? []).reduce((sum, check) => sum + check.count, 0))
|
|
27
|
+
|
|
28
|
+
const dialog = useOverlay().create(MetaImportDialog)
|
|
29
|
+
|
|
30
|
+
async function openDialog() {
|
|
31
|
+
const organizationId = organization.organizationId
|
|
32
|
+
const product = appContext.product
|
|
33
|
+
if (!checks.value?.length || !organizationId || !product) return
|
|
34
|
+
|
|
35
|
+
const imported = await dialog.open({ checks: checks.value, organizationId, product }).result
|
|
36
|
+
if (imported) emit('imported')
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<template>
|
|
41
|
+
<UButton
|
|
42
|
+
v-if="count > 0"
|
|
43
|
+
:label="$t('pages.message_library.import_from_meta', { count })"
|
|
44
|
+
icon="ph:download-simple"
|
|
45
|
+
color="neutral"
|
|
46
|
+
variant="outline"
|
|
47
|
+
data-testid="meta-import-button"
|
|
48
|
+
@click="openDialog"
|
|
49
|
+
/>
|
|
50
|
+
</template>
|
|
@@ -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>
|