@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.
- package/README.md +357 -46
- package/app/api/automations.ts +74 -0
- package/app/api/brands.ts +20 -13
- package/app/api/client.ts +15 -6
- package/app/api/compilation.ts +13 -3
- package/app/api/dynamicValues.ts +6 -2
- package/app/api/index.ts +1 -0
- package/app/api/media.ts +6 -3
- package/app/api/messageGroups.ts +34 -15
- 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 +30 -0
- package/app/components/Common/HtmlPreviewIframe.vue +17 -3
- package/app/components/Common/MessageGroupSelect.vue +193 -26
- package/app/components/Common/MessagePreviewSlideover.vue +3 -0
- 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 +25 -7
- 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 +81 -0
- package/app/components/MessageSendFlow/LanguageSelect.vue +39 -0
- package/app/components/MessageSendFlow/MessageSendFlow.vue +265 -0
- package/app/components/MessageSendFlow/ParametersForm.vue +51 -0
- 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 +177 -108
- package/app/components/Whatsapp/Preview.vue +17 -16
- package/app/components/Whatsapp/PreviewPanel.vue +7 -1
- 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 +9 -7
- 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/useMessageGroupList.ts +186 -0
- package/app/composables/useMessageGroupWaba.ts +76 -0
- package/app/composables/useMessageSendFlow.ts +284 -0
- package/app/composables/usePagedMessageGroups.ts +78 -0
- package/app/composables/useTemplateOperations.ts +31 -7
- package/app/composables/useTracking.ts +14 -5
- package/app/composables/useWhatsappConfiguration.ts +32 -0
- package/app/layouts/default.vue +5 -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 +16 -3
- package/app/queries/dynamicValues.ts +19 -2
- package/app/queries/index.ts +1 -0
- package/app/queries/media.ts +8 -3
- package/app/queries/messageGroups.ts +84 -36
- package/app/queries/meta.ts +100 -5
- package/app/stores/appContext.ts +18 -48
- 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 +50 -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 +137 -0
- package/i18n/locales/de.ts +419 -2
- package/i18n/locales/en.ts +398 -2
- package/i18n/locales/es.ts +403 -2
- package/i18n/locales/fr.ts +410 -2
- package/i18n/locales/it.ts +409 -2
- package/package.json +4 -4
- package/app.config.ts +0 -5
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
-
useMessageGroupsQuery,
|
|
4
3
|
useDeleteMessageGroupMutation,
|
|
5
4
|
usePublishMessageGroupMutation,
|
|
6
5
|
useUnpublishMessageGroupMutation,
|
|
@@ -10,7 +9,6 @@ import type {
|
|
|
10
9
|
RenderType,
|
|
11
10
|
} from '@dev.smartpricing/message-composer-utils/types'
|
|
12
11
|
import type { MessageActionProperties, MessagesKind } from '@/types/tracking'
|
|
13
|
-
import { computed } from 'vue'
|
|
14
12
|
import BaseTable from '@/components/TemplateList/BaseTable.vue'
|
|
15
13
|
|
|
16
14
|
const renderType = defineModel<RenderType>('renderType', { required: true })
|
|
@@ -21,17 +19,30 @@ const emit = defineEmits<{
|
|
|
21
19
|
duplicated: [result: { id: string | number; sourceId: string | number; name: string }]
|
|
22
20
|
published: [row: MessageGroupWithMessageSummary]
|
|
23
21
|
unpublished: [row: MessageGroupWithMessageSummary]
|
|
22
|
+
/** Once, when the list has loaded for the first time. */
|
|
23
|
+
loaded: []
|
|
24
24
|
}>()
|
|
25
25
|
|
|
26
26
|
const { trackEvent } = useTracking()
|
|
27
27
|
const { t } = useI18n()
|
|
28
28
|
|
|
29
|
-
//
|
|
29
|
+
// List state + server-side paginated query (ADR 0012)
|
|
30
30
|
const {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
state: listState,
|
|
32
|
+
setFilters,
|
|
33
|
+
setSorting,
|
|
34
|
+
setPage,
|
|
35
|
+
rows: messageGroups,
|
|
36
|
+
meta,
|
|
37
|
+
loading: isFetching,
|
|
33
38
|
refetch: execute,
|
|
34
|
-
} =
|
|
39
|
+
} = useMessageGroupList(renderType)
|
|
40
|
+
|
|
41
|
+
whenever(
|
|
42
|
+
() => !isFetching.value,
|
|
43
|
+
() => emit('loaded'),
|
|
44
|
+
{ immediate: true, once: true },
|
|
45
|
+
)
|
|
35
46
|
|
|
36
47
|
// Polling
|
|
37
48
|
const interval = setInterval(() => execute(), 15000)
|
|
@@ -144,8 +155,15 @@ defineExpose({ execute })
|
|
|
144
155
|
<template>
|
|
145
156
|
<BaseTable
|
|
146
157
|
:loading="isFetching"
|
|
147
|
-
:message-groups="messageGroups
|
|
158
|
+
:message-groups="messageGroups"
|
|
159
|
+
:meta="meta"
|
|
148
160
|
:render-type="renderType"
|
|
161
|
+
:filters="listState"
|
|
162
|
+
:sorting="listState"
|
|
163
|
+
:page="listState.page"
|
|
164
|
+
@update:filters="setFilters"
|
|
165
|
+
@update:sorting="setSorting"
|
|
166
|
+
@update:page="setPage"
|
|
149
167
|
@edit="navigate"
|
|
150
168
|
@delete="askDeleteGroup"
|
|
151
169
|
@duplicate="handleDuplicate"
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { OrganizationWaba } from '@dev.smartpricing/message-composer-utils/types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Asks which WABA a Message Group is submitted to, at its first submission,
|
|
6
|
+
* when its Organization has several (ADR 0015). Opened through `useOverlay`:
|
|
7
|
+
* closes with the chosen WABA id, or with nothing when the user gives up.
|
|
8
|
+
*/
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
wabas: OrganizationWaba[]
|
|
11
|
+
}>()
|
|
12
|
+
|
|
13
|
+
const emit = defineEmits<{ close: [wabaId?: string] }>()
|
|
14
|
+
|
|
15
|
+
const selected = ref<string>()
|
|
16
|
+
|
|
17
|
+
const items = computed(() =>
|
|
18
|
+
props.wabas.map((waba) => ({
|
|
19
|
+
value: waba.id,
|
|
20
|
+
label: waba.name || waba.id,
|
|
21
|
+
numbers: waba.phone_numbers.join(', '),
|
|
22
|
+
// Not `id`: the radio group gives each item one of its own.
|
|
23
|
+
wabaId: waba.id,
|
|
24
|
+
})),
|
|
25
|
+
)
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<UModal
|
|
30
|
+
:title="$t('dialogs.select_waba.title')"
|
|
31
|
+
:description="$t('dialogs.select_waba.description')"
|
|
32
|
+
close-icon="ph:x"
|
|
33
|
+
:close="{ onClick: () => emit('close') }"
|
|
34
|
+
:dismissible="false"
|
|
35
|
+
data-testid="waba-select-modal"
|
|
36
|
+
>
|
|
37
|
+
<template #body>
|
|
38
|
+
<URadioGroup
|
|
39
|
+
v-model="selected"
|
|
40
|
+
:items="items"
|
|
41
|
+
variant="table"
|
|
42
|
+
class="w-full"
|
|
43
|
+
:ui="{ item: 'w-full' }"
|
|
44
|
+
data-testid="waba-select-options"
|
|
45
|
+
>
|
|
46
|
+
<template #description="{ item }">
|
|
47
|
+
<span class="flex flex-col">
|
|
48
|
+
<span>{{ item.numbers || $t('dialogs.select_waba.no_numbers') }}</span>
|
|
49
|
+
<span class="text-xs text-dimmed font-mono">{{ item.wabaId }}</span>
|
|
50
|
+
</span>
|
|
51
|
+
</template>
|
|
52
|
+
</URadioGroup>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<template #footer>
|
|
56
|
+
<div class="flex gap-2 justify-end w-full">
|
|
57
|
+
<UButton
|
|
58
|
+
variant="outline"
|
|
59
|
+
color="neutral"
|
|
60
|
+
:label="$t('common.actions.cancel')"
|
|
61
|
+
data-testid="waba-select-cancel"
|
|
62
|
+
@click="emit('close')"
|
|
63
|
+
/>
|
|
64
|
+
<UButton
|
|
65
|
+
:label="$t('dialogs.select_waba.confirm')"
|
|
66
|
+
:disabled="!selected"
|
|
67
|
+
data-testid="waba-select-confirm"
|
|
68
|
+
@click="emit('close', selected)"
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
</template>
|
|
72
|
+
</UModal>
|
|
73
|
+
</template>
|
|
@@ -27,8 +27,33 @@ const { mainLanguage } = storeToRefs(useAppContextStore())
|
|
|
27
27
|
const { trackEvent } = useTracking()
|
|
28
28
|
const { goBackOrFallback } = useGoBack()
|
|
29
29
|
const { submitToMeta, submitMessageToMeta } = useMetaSubmissionStore()
|
|
30
|
+
const { status: whatsappConfiguration } = useWhatsappConfiguration()
|
|
30
31
|
const { confirm } = useConfirm()
|
|
31
32
|
const { t } = useI18n()
|
|
33
|
+
const toast = useToast()
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A submission needs a WABA of the Message Group's Organization: when it is
|
|
37
|
+
* known to have none, or the Message Group is on one the Organization no
|
|
38
|
+
* longer has, say so before anything is saved on the way to the submission.
|
|
39
|
+
* While that is not known (lookup running or failed) the submission goes
|
|
40
|
+
* ahead and the backend decides.
|
|
41
|
+
*/
|
|
42
|
+
function canSubmitToMeta(): boolean {
|
|
43
|
+
const reason =
|
|
44
|
+
whatsappConfiguration.value === 'not_configured'
|
|
45
|
+
? 'whatsapp_not_configured'
|
|
46
|
+
: isWabaDetached.value
|
|
47
|
+
? 'whatsapp_waba_detached'
|
|
48
|
+
: null
|
|
49
|
+
if (!reason) return true
|
|
50
|
+
toast.add({
|
|
51
|
+
color: 'error',
|
|
52
|
+
title: t(`common.${reason}_title`),
|
|
53
|
+
description: t(`common.${reason}_description`),
|
|
54
|
+
})
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
32
57
|
|
|
33
58
|
// ── Init ──────────────────────────────────────────────────────────
|
|
34
59
|
if (props.mode === 'create') {
|
|
@@ -41,6 +66,19 @@ const { data: messageGroupData, isPending: isFetching } =
|
|
|
41
66
|
? useMessageGroupQuery(props.messageGroupId)
|
|
42
67
|
: { data: ref(null), isPending: ref(false) }
|
|
43
68
|
|
|
69
|
+
// The editor works on the Organization of the Message Group it loaded, not on
|
|
70
|
+
// the selector's. Claimed before the watcher below loads dependent data.
|
|
71
|
+
useResourceOrganization(() => messageGroupData.value?.organization_id)
|
|
72
|
+
|
|
73
|
+
// The WABA the Message Group is on, and the choice of one at its first
|
|
74
|
+
// submission (ADR 0015).
|
|
75
|
+
const {
|
|
76
|
+
waba: messageGroupWaba,
|
|
77
|
+
isDetached: isWabaDetached,
|
|
78
|
+
chooseWaba,
|
|
79
|
+
markSubmitted,
|
|
80
|
+
} = useMessageGroupWaba(() => messageGroupData.value?.waba_id)
|
|
81
|
+
|
|
44
82
|
// ── Change tracking ───────────────────────────────────────────────
|
|
45
83
|
const changeTracking = useChangeTracking(computed(() => store.changeTrackingId))
|
|
46
84
|
|
|
@@ -96,8 +134,12 @@ const { formState, draftSchema, validationErrors, validateDraft, validateFull, c
|
|
|
96
134
|
// ── Template operations ───────────────────────────────────────────
|
|
97
135
|
const successFlag = ref(false)
|
|
98
136
|
|
|
137
|
+
const editorTrip = useEditorTripStore()
|
|
138
|
+
|
|
99
139
|
const { saving, createTemplate, updateTemplate } = useTemplateOperations({
|
|
100
|
-
onSuccess: () => {
|
|
140
|
+
onSuccess: (saved) => {
|
|
141
|
+
// Recorded before the editor navigates: whoever opened it reads it on landing.
|
|
142
|
+
if (saved) editorTrip.recordSaved(saved)
|
|
101
143
|
successFlag.value = true
|
|
102
144
|
changeTracking.clearAllChanges()
|
|
103
145
|
if (props.mode === 'create') {
|
|
@@ -238,6 +280,10 @@ async function saveAsNew() {
|
|
|
238
280
|
}
|
|
239
281
|
|
|
240
282
|
async function requestApproval() {
|
|
283
|
+
// Asked before anything is saved: giving up leaves the editor as it was.
|
|
284
|
+
const choice = await chooseWaba()
|
|
285
|
+
if (!choice) return
|
|
286
|
+
|
|
241
287
|
track('request_approval', getWaDraftProps())
|
|
242
288
|
|
|
243
289
|
if (props.mode === 'create') {
|
|
@@ -246,7 +292,7 @@ async function requestApproval() {
|
|
|
246
292
|
'draft',
|
|
247
293
|
)
|
|
248
294
|
if (result) {
|
|
249
|
-
await submitToMeta(result.id.toString())
|
|
295
|
+
await submitToMeta(result.id.toString(), choice.wabaId)
|
|
250
296
|
emit('saved', { id: result.id, name: result.name })
|
|
251
297
|
notifyParent('TEMPLATE_APPROVAL_REQUESTED', { id: result.id, name: result.name })
|
|
252
298
|
}
|
|
@@ -256,7 +302,7 @@ async function requestApproval() {
|
|
|
256
302
|
messageGroup: store.messageGroupUpdateData,
|
|
257
303
|
messages: store.messages,
|
|
258
304
|
})
|
|
259
|
-
await submitToMeta(store.messageGroupId)
|
|
305
|
+
await submitToMeta(store.messageGroupId, choice.wabaId)
|
|
260
306
|
emit('saved', { id: store.messageGroupId, name: store.name })
|
|
261
307
|
notifyParent('TEMPLATE_APPROVAL_REQUESTED', { id: store.messageGroupId, name: store.name })
|
|
262
308
|
goBackOrFallback()
|
|
@@ -267,6 +313,10 @@ async function requestApproval() {
|
|
|
267
313
|
async function onRequestReview(languageId: string) {
|
|
268
314
|
const message = store.messages[languageId] as (WhatsappMessage & { id?: string }) | undefined
|
|
269
315
|
if (!message?.id) return
|
|
316
|
+
if (!canSubmitToMeta()) return
|
|
317
|
+
|
|
318
|
+
const choice = await chooseWaba()
|
|
319
|
+
if (!choice) return
|
|
270
320
|
|
|
271
321
|
const languageName = languages.value?.find((l) => l.id === languageId)?.name ?? languageId
|
|
272
322
|
|
|
@@ -278,7 +328,8 @@ async function onRequestReview(languageId: string) {
|
|
|
278
328
|
action: async () => {
|
|
279
329
|
// Decision C: persist only this language's current edits, then submit it.
|
|
280
330
|
await messagesApi.update(message.id!, message)
|
|
281
|
-
await submitMessageToMeta(message.id
|
|
331
|
+
await submitMessageToMeta(message.id!, choice.wabaId)
|
|
332
|
+
markSubmitted(choice.wabaId)
|
|
282
333
|
// Reflect pending locally instead of refetching the group, so unsaved
|
|
283
334
|
// edits in other languages are preserved.
|
|
284
335
|
store.messages[languageId] = { ...message, status: 'pending' }
|
|
@@ -312,6 +363,7 @@ async function handleSaveAsNew() {
|
|
|
312
363
|
}
|
|
313
364
|
|
|
314
365
|
async function handleRequestApproval() {
|
|
366
|
+
if (!canSubmitToMeta()) return
|
|
315
367
|
if (!(await validateFull())) return
|
|
316
368
|
if (hasIncompleteTranslations.value) {
|
|
317
369
|
pendingAction.value = 'request_approval'
|
|
@@ -409,6 +461,7 @@ defineExpose({
|
|
|
409
461
|
validationErrors,
|
|
410
462
|
isPending: store.isPending,
|
|
411
463
|
isApproved: store.isApproved,
|
|
464
|
+
isWabaDetached,
|
|
412
465
|
})
|
|
413
466
|
</script>
|
|
414
467
|
|
|
@@ -439,6 +492,32 @@ defineExpose({
|
|
|
439
492
|
</UAlert>
|
|
440
493
|
</div>
|
|
441
494
|
|
|
495
|
+
<UAlert
|
|
496
|
+
v-if="isWabaDetached"
|
|
497
|
+
color="warning"
|
|
498
|
+
variant="subtle"
|
|
499
|
+
icon="i-lucide-unplug"
|
|
500
|
+
:title="$t('common.whatsapp_waba_detached_title')"
|
|
501
|
+
:description="$t('common.whatsapp_waba_detached_description')"
|
|
502
|
+
class="rounded-none"
|
|
503
|
+
data-testid="whatsapp-waba-detached"
|
|
504
|
+
/>
|
|
505
|
+
<div
|
|
506
|
+
v-if="messageGroupWaba"
|
|
507
|
+
class="flex items-center gap-2 px-6 py-2 text-sm text-muted border-b border-default"
|
|
508
|
+
data-testid="whatsapp-message-group-waba"
|
|
509
|
+
>
|
|
510
|
+
<UIcon name="i-lucide-building-2" class="size-4 shrink-0" />
|
|
511
|
+
<span>{{ $t('common.whatsapp_waba_label') }}</span>
|
|
512
|
+
<span v-if="messageGroupWaba.name" class="font-medium text-default">
|
|
513
|
+
{{ messageGroupWaba.name }}
|
|
514
|
+
</span>
|
|
515
|
+
<span v-if="messageGroupWaba.phone_numbers.length">
|
|
516
|
+
{{ messageGroupWaba.phone_numbers.join(', ') }}
|
|
517
|
+
</span>
|
|
518
|
+
<span class="text-xs text-dimmed font-mono">{{ messageGroupWaba.id }}</span>
|
|
519
|
+
</div>
|
|
520
|
+
|
|
442
521
|
<ComposerWhatsappContent
|
|
443
522
|
v-if="store.activeTab === 'content'"
|
|
444
523
|
:mode="mode"
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
convertToWhatsappHeaderText,
|
|
14
14
|
convertToWhatsappMarkdown,
|
|
15
15
|
getTipTapExtensions,
|
|
16
|
+
isWhatsappHeaderMultiline,
|
|
16
17
|
sanitizeContent,
|
|
17
18
|
} from '@dev.smartpricing/message-composer-utils/utils'
|
|
18
19
|
import EmojiPickerButton from '../Common/EmojiPickerButton.vue'
|
|
@@ -278,14 +279,21 @@ const toolbarItems = computed(() => {
|
|
|
278
279
|
// WhatsApp markdown-aware character count
|
|
279
280
|
// Meta counts the final markdown output (with *bold*, _italic_ marks),
|
|
280
281
|
// so we must display that count instead of TipTap's document-model count.
|
|
281
|
-
const
|
|
282
|
+
const isWhatsappHeader = computed(() => props.preset === 'whatsapp-header')
|
|
283
|
+
const isWhatsapp = computed(() => props.preset === 'whatsapp' || isWhatsappHeader.value)
|
|
282
284
|
const whatsappCharCount = computed(() => {
|
|
283
285
|
if (!isWhatsapp.value || !props.characterLimit || !text.value) return 0
|
|
284
|
-
return
|
|
286
|
+
return isWhatsappHeader.value
|
|
285
287
|
? convertToWhatsappHeaderText(text.value).length
|
|
286
288
|
: convertToWhatsappMarkdown(text.value).length
|
|
287
289
|
})
|
|
288
290
|
|
|
291
|
+
// A multi-line header is still saved (its lines are joined into one when
|
|
292
|
+
// sent to Meta), so the editor warns instead of raising a validation error.
|
|
293
|
+
const hasHeaderLineBreaks = computed(
|
|
294
|
+
() => isWhatsappHeader.value && isWhatsappHeaderMultiline(text.value),
|
|
295
|
+
)
|
|
296
|
+
|
|
289
297
|
// Handlers
|
|
290
298
|
function onSelectEmoji(emoji: EmojiExt) {
|
|
291
299
|
editor.value?.commands.insertContent(emoji.i)
|
|
@@ -491,6 +499,10 @@ defineExpose({
|
|
|
491
499
|
</span>
|
|
492
500
|
</p>
|
|
493
501
|
|
|
502
|
+
<p v-if="hasHeaderLineBreaks" class="paragraph-xs text-warning-700 pt-1.5 px-1">
|
|
503
|
+
{{ $t('editor.validation.header_line_breaks') }}
|
|
504
|
+
</p>
|
|
505
|
+
|
|
494
506
|
<!-- AI Generate slideover -->
|
|
495
507
|
</div>
|
|
496
508
|
</template>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { parseDate } from '@internationalized/date'
|
|
3
|
+
|
|
4
|
+
/** Internal to the filter components: one date, as `YYYY-MM-DD`. */
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
modelValue: string | undefined
|
|
7
|
+
testId: string
|
|
8
|
+
}>()
|
|
9
|
+
|
|
10
|
+
const emit = defineEmits<{ 'update:modelValue': [value: string | undefined] }>()
|
|
11
|
+
|
|
12
|
+
const date = computed(() => (props.modelValue ? parseDate(props.modelValue) : undefined))
|
|
13
|
+
|
|
14
|
+
// The inputs also speak ranges and lists; here they only ever hold one date.
|
|
15
|
+
function onUpdate(value: unknown) {
|
|
16
|
+
const isDate = typeof value === 'object' && value !== null && 'year' in value && 'day' in value
|
|
17
|
+
// A date with a time or a zone would still print its date first.
|
|
18
|
+
emit('update:modelValue', isDate ? String(value).slice(0, 10) : undefined)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const { t } = useI18n()
|
|
22
|
+
|
|
23
|
+
const inputDate = useTemplateRef('inputDate')
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<UInputDate
|
|
28
|
+
ref="inputDate"
|
|
29
|
+
:model-value="date"
|
|
30
|
+
class="w-full"
|
|
31
|
+
:data-testid="`${testId}-date`"
|
|
32
|
+
@update:model-value="onUpdate"
|
|
33
|
+
>
|
|
34
|
+
<template #trailing>
|
|
35
|
+
<UPopover :reference="inputDate?.inputsRef[0]?.$el">
|
|
36
|
+
<UButton
|
|
37
|
+
color="neutral"
|
|
38
|
+
variant="link"
|
|
39
|
+
size="sm"
|
|
40
|
+
icon="ph:calendar-bold"
|
|
41
|
+
:aria-label="t('filters.actions.open_calendar')"
|
|
42
|
+
class="px-0"
|
|
43
|
+
:data-testid="`${testId}-calendar-button`"
|
|
44
|
+
/>
|
|
45
|
+
|
|
46
|
+
<template #content>
|
|
47
|
+
<UCalendar
|
|
48
|
+
:model-value="date"
|
|
49
|
+
class="p-2"
|
|
50
|
+
:data-testid="`${testId}-calendar`"
|
|
51
|
+
@update:model-value="onUpdate"
|
|
52
|
+
/>
|
|
53
|
+
</template>
|
|
54
|
+
</UPopover>
|
|
55
|
+
</template>
|
|
56
|
+
</UInputDate>
|
|
57
|
+
</template>
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
Condition,
|
|
4
|
+
FilterField,
|
|
5
|
+
FiltersReport,
|
|
6
|
+
} from '@dev.smartpricing/message-composer-utils/types'
|
|
7
|
+
import {
|
|
8
|
+
conditionsToFilterRows,
|
|
9
|
+
filterCurrency,
|
|
10
|
+
filterRowsToConditions,
|
|
11
|
+
newFilterRow,
|
|
12
|
+
reportFilterRows,
|
|
13
|
+
type FilterEditableRow,
|
|
14
|
+
type FilterRow,
|
|
15
|
+
} from '../../utils/filters/rows'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Public (ADR 0018): the rows of a list of Conditions, and "add". Props-only:
|
|
19
|
+
* it reads neither the Automation Catalog nor the Host's context. A Condition
|
|
20
|
+
* it cannot edit is an unavailable row, kept as it is until the user removes
|
|
21
|
+
* it; a half-filled row is reported and never emitted.
|
|
22
|
+
*/
|
|
23
|
+
const props = withDefaults(
|
|
24
|
+
defineProps<{
|
|
25
|
+
/** The fields a Condition can be on, in display order. */
|
|
26
|
+
fields: FilterField[]
|
|
27
|
+
/** ISO code of the currency `price` fields show; EUR when absent. */
|
|
28
|
+
currency?: string
|
|
29
|
+
title?: string
|
|
30
|
+
subtitle?: string
|
|
31
|
+
testIdPrefix?: string
|
|
32
|
+
}>(),
|
|
33
|
+
{ currency: undefined, title: undefined, subtitle: undefined, testIdPrefix: undefined },
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
const model = defineModel<Condition[]>({ required: true })
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{ report: [report: FiltersReport] }>()
|
|
39
|
+
|
|
40
|
+
const { t } = useI18n()
|
|
41
|
+
|
|
42
|
+
let lastId = 0
|
|
43
|
+
const nextId = () => ++lastId
|
|
44
|
+
|
|
45
|
+
const rows = ref<FilterRow[]>([])
|
|
46
|
+
/** What the rows were last worth, to tell the caller's changes from our own. */
|
|
47
|
+
let emitted: string | undefined
|
|
48
|
+
|
|
49
|
+
function readModel() {
|
|
50
|
+
rows.value = conditionsToFilterRows(model.value, props.fields, nextId)
|
|
51
|
+
emitted = JSON.stringify(model.value)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Rows the user has not completed live only here: the rows are read again
|
|
55
|
+
// only when the Conditions change from outside, or the fields do.
|
|
56
|
+
watch(
|
|
57
|
+
model,
|
|
58
|
+
(conditions) => {
|
|
59
|
+
if (JSON.stringify(conditions) !== emitted) readModel()
|
|
60
|
+
},
|
|
61
|
+
{ deep: true, immediate: true },
|
|
62
|
+
)
|
|
63
|
+
watch(() => props.fields.map((field) => `${field.key}:${field.type}`).join('|'), readModel)
|
|
64
|
+
|
|
65
|
+
function commit(next: FilterRow[]) {
|
|
66
|
+
const before = JSON.stringify(filterRowsToConditions(rows.value))
|
|
67
|
+
rows.value = next
|
|
68
|
+
const conditions = filterRowsToConditions(next)
|
|
69
|
+
const serialized = JSON.stringify(conditions)
|
|
70
|
+
// A row in progress changes no Condition: nothing to tell the caller.
|
|
71
|
+
if (serialized === before) return
|
|
72
|
+
emitted = serialized
|
|
73
|
+
model.value = conditions
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const report = computed(() => reportFilterRows(rows.value, props.fields))
|
|
77
|
+
watch(report, (value) => emit('report', value), { immediate: true })
|
|
78
|
+
|
|
79
|
+
const shownCurrency = computed(() => filterCurrency(props.currency))
|
|
80
|
+
|
|
81
|
+
const fieldsByKey = computed(() => new Map(props.fields.map((field) => [field.key, field])))
|
|
82
|
+
|
|
83
|
+
function fieldOf(row: FilterRow): FilterField | undefined {
|
|
84
|
+
if (row.kind === 'blank') return undefined
|
|
85
|
+
return fieldsByKey.value.get(row.kind === 'editable' ? row.field : row.condition.field)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A field can be picked once: a field any row is on is taken. */
|
|
89
|
+
const freeFields = computed(() => {
|
|
90
|
+
const taken = new Set(rows.value.map((row) => fieldOf(row)?.key))
|
|
91
|
+
return props.fields.filter((field) => !taken.has(field.key))
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
function pickableFields(row: FilterRow): FilterField[] {
|
|
95
|
+
const own = fieldOf(row)
|
|
96
|
+
return props.fields.filter((field) => field === own || freeFields.value.includes(field))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const hasBlankRow = computed(() => rows.value.some((row) => row.kind === 'blank'))
|
|
100
|
+
|
|
101
|
+
function addRow() {
|
|
102
|
+
commit([...rows.value, { kind: 'blank', id: nextId() }])
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function replaceRow(id: number, row: FilterEditableRow) {
|
|
106
|
+
commit(rows.value.map((current) => (current.id === id ? row : current)))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function pickField(id: number, fieldKey: string) {
|
|
110
|
+
const field = fieldsByKey.value.get(fieldKey)
|
|
111
|
+
if (field) replaceRow(id, newFilterRow(id, field))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function removeRow(id: number) {
|
|
115
|
+
commit(rows.value.filter((row) => row.id !== id))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const prefix = computed(() => (props.testIdPrefix ? `${props.testIdPrefix}-` : ''))
|
|
119
|
+
|
|
120
|
+
function rowTestId(row: FilterRow, index: number): string {
|
|
121
|
+
if (row.kind === 'editable') return `${prefix.value}filter-${row.field}`
|
|
122
|
+
return `${prefix.value}filter-${row.kind === 'blank' ? 'new' : `unavailable-${index}`}`
|
|
123
|
+
}
|
|
124
|
+
</script>
|
|
125
|
+
|
|
126
|
+
<template>
|
|
127
|
+
<div class="flex flex-col gap-3" :data-testid="`${prefix}filters`">
|
|
128
|
+
<p v-if="title" class="label-md">{{ title }}</p>
|
|
129
|
+
<p v-if="subtitle" class="label-sm">{{ subtitle }}</p>
|
|
130
|
+
|
|
131
|
+
<template v-for="(row, index) in rows" :key="row.id">
|
|
132
|
+
<FiltersUnavailableRow
|
|
133
|
+
v-if="row.kind === 'unavailable'"
|
|
134
|
+
:row="row"
|
|
135
|
+
:field="fieldOf(row)"
|
|
136
|
+
:test-id="rowTestId(row, index)"
|
|
137
|
+
@remove="removeRow(row.id)"
|
|
138
|
+
/>
|
|
139
|
+
<FiltersRow
|
|
140
|
+
v-else
|
|
141
|
+
:row="row"
|
|
142
|
+
:field="fieldOf(row)"
|
|
143
|
+
:pickable-fields="pickableFields(row)"
|
|
144
|
+
:currency="shownCurrency"
|
|
145
|
+
:test-id="rowTestId(row, index)"
|
|
146
|
+
@pick="pickField(row.id, $event)"
|
|
147
|
+
@update="replaceRow(row.id, $event)"
|
|
148
|
+
@remove="removeRow(row.id)"
|
|
149
|
+
/>
|
|
150
|
+
</template>
|
|
151
|
+
|
|
152
|
+
<div>
|
|
153
|
+
<UButton
|
|
154
|
+
:disabled="freeFields.length === 0 || hasBlankRow"
|
|
155
|
+
color="secondary"
|
|
156
|
+
variant="outline"
|
|
157
|
+
:label="t('filters.actions.add_filter')"
|
|
158
|
+
:data-testid="`${prefix}filters-add-button`"
|
|
159
|
+
@click="addRow"
|
|
160
|
+
/>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
</template>
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { FilterField } from '@dev.smartpricing/message-composer-utils/types'
|
|
3
|
+
import {
|
|
4
|
+
FILTER_OPERATOR_LABEL_KEYS,
|
|
5
|
+
filterRowOperators,
|
|
6
|
+
missingFilterOptions,
|
|
7
|
+
withFilterOperator,
|
|
8
|
+
type FilterBlankRow,
|
|
9
|
+
type FilterEditableRow,
|
|
10
|
+
type FilterRowOperator,
|
|
11
|
+
} from '../../utils/filters/rows'
|
|
12
|
+
|
|
13
|
+
/** Internal to the filter components: one row the user can edit. */
|
|
14
|
+
const props = defineProps<{
|
|
15
|
+
row: FilterBlankRow | FilterEditableRow
|
|
16
|
+
/** The row's own field, when it has one. */
|
|
17
|
+
field: FilterField | undefined
|
|
18
|
+
/** The fields the row can be on: its own and the ones no other row is on. */
|
|
19
|
+
pickableFields: FilterField[]
|
|
20
|
+
currency: string
|
|
21
|
+
testId: string
|
|
22
|
+
}>()
|
|
23
|
+
|
|
24
|
+
const emit = defineEmits<{
|
|
25
|
+
/** The user picked a field: the row starts over on it. */
|
|
26
|
+
pick: [fieldKey: string]
|
|
27
|
+
update: [row: FilterEditableRow]
|
|
28
|
+
remove: []
|
|
29
|
+
}>()
|
|
30
|
+
|
|
31
|
+
const { t } = useI18n()
|
|
32
|
+
|
|
33
|
+
const fieldItems = computed(() =>
|
|
34
|
+
props.pickableFields.map((field) => ({ label: field.label, value: field.key })),
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
const operatorItems = computed(() =>
|
|
38
|
+
props.row.kind === 'editable'
|
|
39
|
+
? filterRowOperators(props.row.type).map((operator) => ({
|
|
40
|
+
label: t(`filters.operators.${FILTER_OPERATOR_LABEL_KEYS[operator]}`),
|
|
41
|
+
value: operator,
|
|
42
|
+
}))
|
|
43
|
+
: [],
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
const hasMissingOption = computed(
|
|
47
|
+
() => props.row.kind === 'editable' && missingFilterOptions(props.row, props.field).length > 0,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
function onField(fieldKey: string) {
|
|
51
|
+
if (props.row.kind === 'editable' && props.row.field === fieldKey) return
|
|
52
|
+
emit('pick', fieldKey)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function onOperator(operator: FilterRowOperator) {
|
|
56
|
+
if (props.row.kind !== 'editable') return
|
|
57
|
+
emit('update', withFilterOperator(props.row, operator))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function onValue(patch: Partial<Pick<FilterEditableRow, 'value' | 'to'>>) {
|
|
61
|
+
if (props.row.kind !== 'editable') return
|
|
62
|
+
emit('update', { ...props.row, ...patch, original: undefined })
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<div class="flex gap-2" :data-testid="testId">
|
|
68
|
+
<div class="flex-1 grid grid-cols-5 items-start gap-2">
|
|
69
|
+
<USelectMenu
|
|
70
|
+
class="w-full col-span-2"
|
|
71
|
+
:items="fieldItems"
|
|
72
|
+
value-key="value"
|
|
73
|
+
:model-value="row.kind === 'editable' ? row.field : undefined"
|
|
74
|
+
:placeholder="t('filters.field_placeholder')"
|
|
75
|
+
:search-input="{ placeholder: t('common.search') }"
|
|
76
|
+
:data-testid="`${testId}-field-select`"
|
|
77
|
+
@update:model-value="onField"
|
|
78
|
+
/>
|
|
79
|
+
<USelect
|
|
80
|
+
:model-value="row.kind === 'editable' ? row.operator : undefined"
|
|
81
|
+
:disabled="row.kind === 'blank'"
|
|
82
|
+
class="w-full"
|
|
83
|
+
:items="operatorItems"
|
|
84
|
+
:ui="{ content: 'min-w-fit' }"
|
|
85
|
+
:data-testid="`${testId}-operator-select`"
|
|
86
|
+
@update:model-value="onOperator($event as FilterRowOperator)"
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
<div class="col-span-2 flex items-start gap-2">
|
|
90
|
+
<FiltersValueInput
|
|
91
|
+
v-if="row.kind === 'editable' && field"
|
|
92
|
+
class="flex-1 min-w-0"
|
|
93
|
+
:row="row"
|
|
94
|
+
:field="field"
|
|
95
|
+
:currency="currency"
|
|
96
|
+
:test-id="`${testId}-value`"
|
|
97
|
+
@update:value="onValue({ value: $event })"
|
|
98
|
+
@update:to="onValue({ to: $event })"
|
|
99
|
+
/>
|
|
100
|
+
<UTooltip v-if="hasMissingOption" :text="t('filters.unavailable.option_description')">
|
|
101
|
+
<UIcon
|
|
102
|
+
name="ph:warning-bold"
|
|
103
|
+
class="size-4 mt-2 shrink-0 text-warning"
|
|
104
|
+
:data-testid="`${testId}-unavailable-option-badge`"
|
|
105
|
+
/>
|
|
106
|
+
</UTooltip>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
<UButton
|
|
110
|
+
color="error"
|
|
111
|
+
variant="ghost"
|
|
112
|
+
icon="ph:trash"
|
|
113
|
+
class="shrink-0 self-start"
|
|
114
|
+
:aria-label="t('filters.actions.remove_filter')"
|
|
115
|
+
:data-testid="`${testId}-delete-button`"
|
|
116
|
+
@click="emit('remove')"
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
</template>
|