@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
|
@@ -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"
|
|
@@ -4,12 +4,10 @@ import type {
|
|
|
4
4
|
WaButtonTypeV1,
|
|
5
5
|
WhatsappMessage,
|
|
6
6
|
} from '@dev.smartpricing/message-composer-utils/types'
|
|
7
|
-
import { generateHTML } from '@tiptap/vue-3'
|
|
8
7
|
import { computed } from 'vue'
|
|
9
8
|
import {
|
|
9
|
+
convertToWhatsappHeaderText,
|
|
10
10
|
generateWhatsappHtml,
|
|
11
|
-
getTipTapExtensions,
|
|
12
|
-
sanitizeContent,
|
|
13
11
|
} from '@dev.smartpricing/message-composer-utils/utils'
|
|
14
12
|
import { useResolvedParametersQuery } from '~/queries/compilation'
|
|
15
13
|
|
|
@@ -57,15 +55,10 @@ const bodyHtml = computed(() => {
|
|
|
57
55
|
return replaceMentionsWithValues(html)
|
|
58
56
|
})
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
// Plain text, exactly as Meta receives it
|
|
59
|
+
const headerText = computed(() => {
|
|
61
60
|
if (props.message.body.header.type !== 'text') return ''
|
|
62
|
-
|
|
63
|
-
const extensions = getTipTapExtensions({ preset: 'whatsapp-header' })
|
|
64
|
-
const html = generateHTML(
|
|
65
|
-
sanitizeContent(props.message.body.header.content, extensions),
|
|
66
|
-
extensions,
|
|
67
|
-
).replaceAll('<p></p>', '<p> </p>')
|
|
68
|
-
return replaceMentionsWithValues(html)
|
|
61
|
+
return replaceMentionsWithValues(convertToWhatsappHeaderText(props.message.body.header.content))
|
|
69
62
|
})
|
|
70
63
|
|
|
71
64
|
const currentTime = computed(() => {
|
|
@@ -131,7 +124,7 @@ const getIcon = (type: WaButtonTypeV1) => {
|
|
|
131
124
|
v-if="message.body.header.type === 'text'"
|
|
132
125
|
class="text-sm text-primary-950 break-all"
|
|
133
126
|
>
|
|
134
|
-
<p
|
|
127
|
+
<p>{{ headerText }}</p>
|
|
135
128
|
</div>
|
|
136
129
|
<div v-else-if="message.body.header.type === 'image'" class="mb-2">
|
|
137
130
|
<img
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { JSONContent } from '@tiptap/vue-3'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
getTipTapExtensions,
|
|
6
|
-
sanitizeContent,
|
|
7
|
-
} from '@dev.smartpricing/message-composer-utils/utils'
|
|
3
|
+
import { convertToWhatsappHeaderText } from '@dev.smartpricing/message-composer-utils/utils'
|
|
8
4
|
import RichTextEditor from '@/components/Editor/RichTextEditor.vue'
|
|
9
5
|
import { useAppContextStore } from '@/stores/appContext'
|
|
10
6
|
import { WA_HEADER_TEXT_MAX_LENGTH } from '@dev.smartpricing/message-composer-utils/types'
|
|
@@ -22,26 +18,15 @@ const targetContent = defineModel<JSONContent | undefined>({
|
|
|
22
18
|
})
|
|
23
19
|
|
|
24
20
|
const appContext = useAppContextStore()
|
|
25
|
-
|
|
26
|
-
// Generate HTML for preview of base language with rich text support
|
|
27
|
-
function generatePreviewHtml(content: JSONContent | undefined): string {
|
|
28
|
-
if (!content) return ''
|
|
29
|
-
const extensions = getTipTapExtensions({ preset: 'whatsapp-header' })
|
|
30
|
-
return generateHTML(sanitizeContent(content, extensions), extensions).replaceAll(
|
|
31
|
-
'<p></p>',
|
|
32
|
-
'<p> </p>',
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
21
|
</script>
|
|
36
22
|
|
|
37
23
|
<template>
|
|
38
24
|
<div class="flex gap-8 items-start" :data-testid="whatsappTranslatorHeaderTestIds.container">
|
|
39
25
|
<!-- Base language preview (read-only) -->
|
|
40
26
|
<div class="flex-1 min-w-0" :data-testid="whatsappTranslatorHeaderTestIds.basePreview">
|
|
41
|
-
<div
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/>
|
|
27
|
+
<div class="paragraph-sm text-primary-700 break-words">
|
|
28
|
+
{{ convertToWhatsappHeaderText(baseContent) }}
|
|
29
|
+
</div>
|
|
45
30
|
</div>
|
|
46
31
|
|
|
47
32
|
<!-- Translation editor (editable) -->
|
|
@@ -1,6 +1,7 @@
|
|
|
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',
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
function descriptionKeyByStatus(status: number): string {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { InjectionKey, Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** A value is what a Condition stores: a number where the Product's data holds one. */
|
|
4
|
+
export interface AutomationOption {
|
|
5
|
+
value: string | number
|
|
6
|
+
label: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What a Host supplies to the Automation pages (ADR 0017), apart from
|
|
11
|
+
* `ComposerContext`. The Host fetches the lists and keeps them current.
|
|
12
|
+
*/
|
|
13
|
+
export interface AutomationsContext {
|
|
14
|
+
/**
|
|
15
|
+
* The option lists, by the name the Automation Catalog gives them
|
|
16
|
+
* (`option_list` of a Condition Field). A list that is not there shows as
|
|
17
|
+
* empty.
|
|
18
|
+
*/
|
|
19
|
+
optionLists: Ref<Record<string, AutomationOption[]>>
|
|
20
|
+
/** ISO code of the currency `price` fields show; EUR when absent. */
|
|
21
|
+
currency?: Ref<string | undefined>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const AUTOMATIONS_CONTEXT_KEY: InjectionKey<AutomationsContext> = Symbol.for(
|
|
25
|
+
'composer-automations-context',
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
/** Must be called in parent's app.vue or plugin before an Automation page renders. */
|
|
29
|
+
export function defineAutomationsContext(context: AutomationsContext): void {
|
|
30
|
+
// App-level provide, as `defineComposerContext`.
|
|
31
|
+
useNuxtApp().vueApp.provide(AUTOMATIONS_CONTEXT_KEY, context)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* `undefined` when the Host provided none: an Automation page shows that as
|
|
36
|
+
* an error of its own (ADR 0019), so this does not throw.
|
|
37
|
+
*/
|
|
38
|
+
export function useAutomationsContext(): AutomationsContext | undefined {
|
|
39
|
+
if (import.meta.server) return undefined
|
|
40
|
+
|
|
41
|
+
return useNuxtApp().vueApp.runWithContext(() => inject(AUTOMATIONS_CONTEXT_KEY, undefined))
|
|
42
|
+
}
|
|
@@ -9,19 +9,19 @@ export interface OrganizationData {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface ComposerContext {
|
|
12
|
-
/** @deprecated No longer used — auth is cookie-based via platform layer */
|
|
13
|
-
authenticationToken?: Ref<string>
|
|
14
12
|
organization_id?: Ref<string>
|
|
15
13
|
/** The Product the host embeds the composer in (ADR 0011). Required. */
|
|
16
14
|
product: Ref<AppContextConfig['product']>
|
|
17
|
-
strategy?: Ref<AppContextConfig['strategy']>
|
|
18
15
|
channels?: Ref<AppContextConfig['channels']>
|
|
19
16
|
languages?: Ref<string[]>
|
|
20
17
|
mainLanguage?: Ref<string>
|
|
21
|
-
dinamicValues?: Ref<Array<{ value: string; label: string }>>
|
|
22
18
|
default_tags?: Ref<string[]>
|
|
19
|
+
/**
|
|
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
|
metaWabaId?: Ref<string>
|
|
24
|
-
metaAccessToken?: Ref<string>
|
|
25
25
|
isAdmin?: Ref<boolean>
|
|
26
26
|
organizationData?: Ref<OrganizationData>
|
|
27
27
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Automation } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
|
+
import AutomationsCloneModal from '~/components/Automations/CloneModal.vue'
|
|
3
|
+
import { useCloneAutomationMutation } from '~/queries'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Duplicating an Automation, from wherever it is offered: the modal that asks
|
|
7
|
+
* the name of the copy, the clone, and the copy opened on its edit page.
|
|
8
|
+
* Called once, in the setup of the component that offers it.
|
|
9
|
+
*/
|
|
10
|
+
export function useAutomationClone() {
|
|
11
|
+
const { t } = useI18n()
|
|
12
|
+
const toast = useToast()
|
|
13
|
+
const { trackEvent } = useTracking()
|
|
14
|
+
const cloneModal = useOverlay().create(AutomationsCloneModal, { destroyOnClose: true })
|
|
15
|
+
const { mutateAsync: cloneAutomation } = useCloneAutomationMutation()
|
|
16
|
+
|
|
17
|
+
/** Asks the name of the copy, then makes it from the Automation as stored. */
|
|
18
|
+
function askClone(automation: Pick<Automation, 'id' | 'name'>) {
|
|
19
|
+
cloneModal.open({
|
|
20
|
+
defaultName: t('common.copy_of', { name: automation.name }),
|
|
21
|
+
action: async (name) => {
|
|
22
|
+
const copy = await cloneAutomation({ id: automation.id, name })
|
|
23
|
+
trackEvent('automation.clone', { automation_name: name, source_id: automation.id })
|
|
24
|
+
toast.add({ title: t('automations.toast.cloned'), color: 'success' })
|
|
25
|
+
|
|
26
|
+
// In demo mode the answer is not an Automation: there is no copy to open.
|
|
27
|
+
if (copy?.id) await navigateTo({ name: 'automation-edit', params: { id: copy.id } })
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { askClone }
|
|
33
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { Automation } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
|
+
import { EDITOR_ROUTES } from '~/stores/editorTrip'
|
|
3
|
+
import {
|
|
4
|
+
cloneFormData,
|
|
5
|
+
type AutomationFormAction,
|
|
6
|
+
type AutomationFormState,
|
|
7
|
+
} from '~/utils/automations/form'
|
|
8
|
+
|
|
9
|
+
/** The Action in the Action editor. */
|
|
10
|
+
export interface OpenAutomationAction {
|
|
11
|
+
action: AutomationFormAction
|
|
12
|
+
/** Whether the form does not hold it yet. */
|
|
13
|
+
isNew: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** A request to leave for the Message editor: a new Message Group, or the Action's own. */
|
|
17
|
+
export interface AutomationMessageRequest extends OpenAutomationAction {
|
|
18
|
+
target: 'create' | 'edit'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What an Automation page wants back from an editor trip. */
|
|
22
|
+
interface AutomationTripKept {
|
|
23
|
+
/** The unsaved Automation. */
|
|
24
|
+
form: AutomationFormState
|
|
25
|
+
/** The Automation as the Automation Engine holds it; none on the create page. */
|
|
26
|
+
stored?: Automation
|
|
27
|
+
openAction: OpenAutomationAction
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The Automation side of an editor trip: leaving for the Message editor with
|
|
32
|
+
* the unsaved Automation kept, and getting it back on return with the Action
|
|
33
|
+
* reopened and the Message Group just saved selected in it.
|
|
34
|
+
*
|
|
35
|
+
* Called once, in the setup of the component that holds the form: a trip that
|
|
36
|
+
* started on `origin` is consumed there.
|
|
37
|
+
*/
|
|
38
|
+
export function useAutomationEditorTrip(
|
|
39
|
+
origin: 'automation-create' | 'automation-edit',
|
|
40
|
+
automationId?: string,
|
|
41
|
+
) {
|
|
42
|
+
const { t } = useI18n()
|
|
43
|
+
const toast = useToast()
|
|
44
|
+
const editorTrip = useEditorTripStore()
|
|
45
|
+
|
|
46
|
+
const trip = editorTrip.consume<AutomationTripKept>(origin)
|
|
47
|
+
// The edit page of another Automation is not where the trip started.
|
|
48
|
+
const returned = trip && trip.kept.stored?.id === automationId ? trip : undefined
|
|
49
|
+
|
|
50
|
+
let restored: AutomationTripKept | undefined
|
|
51
|
+
if (returned) {
|
|
52
|
+
const { kept, result } = returned
|
|
53
|
+
// Only the Message Group changes: an Action's status is the user's to set.
|
|
54
|
+
const action = result
|
|
55
|
+
? { ...kept.openAction.action, messageGroupId: result.id, messageGroupName: result.name }
|
|
56
|
+
: kept.openAction.action
|
|
57
|
+
restored = { ...kept, openAction: { ...kept.openAction, action } }
|
|
58
|
+
toast.add({ title: t('automations.trip.kept'), color: 'info' })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Leaves for the Message editor, keeping the unsaved Automation and the open Action. */
|
|
62
|
+
function leave(
|
|
63
|
+
unsaved: { form: AutomationFormState; stored?: Automation },
|
|
64
|
+
{ action, isNew, target }: AutomationMessageRequest,
|
|
65
|
+
) {
|
|
66
|
+
editorTrip.start<AutomationTripKept>(
|
|
67
|
+
{ routeName: origin, backLabel: t('automations.trip.back') },
|
|
68
|
+
{ ...cloneFormData(unsaved), openAction: { action: cloneFormData(action), isNew } },
|
|
69
|
+
)
|
|
70
|
+
const name = EDITOR_ROUTES[action.channel][target]
|
|
71
|
+
return navigateTo(
|
|
72
|
+
target === 'edit' ? { name, params: { id: action.messageGroupId } } : { name },
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { restored, leave }
|
|
77
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AutomationCatalog,
|
|
3
|
+
AutomationSaveProblem,
|
|
4
|
+
} from '@dev.smartpricing/message-composer-utils/types'
|
|
5
|
+
import type { MaybeRefOrGetter } from 'vue'
|
|
6
|
+
import type { AutomationFormState } from '~/utils/automations/form'
|
|
7
|
+
|
|
8
|
+
/** One line of the alert: what is wrong and, when it has one, the place to jump to. */
|
|
9
|
+
export interface AutomationProblemLine {
|
|
10
|
+
text: string
|
|
11
|
+
/** The id of the element the line is about. */
|
|
12
|
+
target?: string
|
|
13
|
+
actionKey?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* What a refused save (422 `AUTOMATION_ACTIONS_INVALID`) says at the top of
|
|
18
|
+
* the Automation form, on the create page and on the edit page alike.
|
|
19
|
+
* `AutomationsSaveProblems` renders the lines.
|
|
20
|
+
*/
|
|
21
|
+
export function useAutomationSaveProblems(catalog: MaybeRefOrGetter<AutomationCatalog>) {
|
|
22
|
+
const { t, te } = useI18n()
|
|
23
|
+
|
|
24
|
+
const lines = ref<AutomationProblemLine[]>([])
|
|
25
|
+
const invalidActionKeys = computed(() =>
|
|
26
|
+
lines.value.flatMap(({ actionKey }) => (actionKey ? [actionKey] : [])),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The line of one problem. A problem points at an Action by its position
|
|
31
|
+
* in what was submitted; `undefined` for a problem this version does not
|
|
32
|
+
* know.
|
|
33
|
+
*/
|
|
34
|
+
function toLine(
|
|
35
|
+
problem: AutomationSaveProblem,
|
|
36
|
+
sent: AutomationFormState,
|
|
37
|
+
): AutomationProblemLine | undefined {
|
|
38
|
+
if (problem.target === 'trigger') {
|
|
39
|
+
return {
|
|
40
|
+
text: t('automations.problems.trigger_not_in_catalog'),
|
|
41
|
+
target: 'automation-trigger',
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (problem.target === 'condition') {
|
|
46
|
+
const key = `automations.problems.condition_${problem.reason}`
|
|
47
|
+
const label =
|
|
48
|
+
toValue(catalog)
|
|
49
|
+
.triggers.find(({ type }) => type === sent.triggerType)
|
|
50
|
+
?.condition_fields.find((field) => field.key === problem.field)?.label ?? problem.field
|
|
51
|
+
return te(key)
|
|
52
|
+
? { text: t(key, { field: label }), target: 'automation-conditions' }
|
|
53
|
+
: undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (problem.target === 'action') {
|
|
57
|
+
const key = `automations.problems.action_${problem.reason}`
|
|
58
|
+
const action = sent.actions[problem.position]
|
|
59
|
+
if (!action || !te(key)) return undefined
|
|
60
|
+
return {
|
|
61
|
+
text: t(key, { name: action.messageGroupName }),
|
|
62
|
+
target: `automation-action-${action.key}`,
|
|
63
|
+
actionKey: action.key,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return undefined
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** `sent` is the form as it was submitted: the problems point into it. */
|
|
71
|
+
function show(problems: AutomationSaveProblem[], sent: AutomationFormState) {
|
|
72
|
+
const known = problems.flatMap((problem) => toLine(problem, sent) ?? [])
|
|
73
|
+
// Refused for reasons this version cannot name: still say it was refused.
|
|
74
|
+
lines.value = known.length > 0 ? known : [{ text: t('automations.problems.unknown') }]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function clear() {
|
|
78
|
+
lines.value = []
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { lines, invalidActionKeys, show, clear }
|
|
82
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { FilterField, FiltersReport } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
|
+
import type { AutomationFormAction } from '~/utils/automations/form'
|
|
3
|
+
import {
|
|
4
|
+
actionUnavailableKinds,
|
|
5
|
+
unavailableBlocks,
|
|
6
|
+
type ActionAvailability,
|
|
7
|
+
type AutomationUnavailableItem,
|
|
8
|
+
type AutomationUnavailableKind,
|
|
9
|
+
} from '~/utils/automations/unavailable'
|
|
10
|
+
|
|
11
|
+
export const AUTOMATION_TRIGGER_ELEMENT_ID = 'automation-trigger'
|
|
12
|
+
export const AUTOMATION_CONDITIONS_ELEMENT_ID = 'automation-conditions'
|
|
13
|
+
|
|
14
|
+
export function automationActionElementId(actionKey: string): string {
|
|
15
|
+
return `automation-action-${actionKey}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The unavailable things of an Automation as the form says them: one item
|
|
20
|
+
* each, with where it is, its sentence and whether it blocks the save.
|
|
21
|
+
* `AutomationsUnavailable` lists them, `AutomationsUnavailableBadge` marks
|
|
22
|
+
* one in place.
|
|
23
|
+
*/
|
|
24
|
+
export function useAutomationUnavailable() {
|
|
25
|
+
const { t } = useI18n()
|
|
26
|
+
|
|
27
|
+
function item(
|
|
28
|
+
kind: AutomationUnavailableKind,
|
|
29
|
+
rest: Omit<AutomationUnavailableItem, 'kind' | 'blocks' | 'text'>,
|
|
30
|
+
params: Record<string, string> = {},
|
|
31
|
+
): AutomationUnavailableItem {
|
|
32
|
+
return {
|
|
33
|
+
kind,
|
|
34
|
+
blocks: unavailableBlocks(kind),
|
|
35
|
+
text: t(`automations.unavailable.${kind}`, params),
|
|
36
|
+
...rest,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A Trigger the Automation Catalog no longer lists. */
|
|
41
|
+
function triggerItem(): AutomationUnavailableItem {
|
|
42
|
+
return item('trigger', {
|
|
43
|
+
key: 'trigger',
|
|
44
|
+
where: t('automations.form.trigger'),
|
|
45
|
+
target: AUTOMATION_TRIGGER_ELEMENT_ID,
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** What the filter components report on a list of Conditions (ADR 0018). */
|
|
50
|
+
function conditionItems(
|
|
51
|
+
report: FiltersReport | undefined,
|
|
52
|
+
fields: readonly FilterField[],
|
|
53
|
+
): AutomationUnavailableItem[] {
|
|
54
|
+
if (!report) return []
|
|
55
|
+
|
|
56
|
+
const where = (field: string) =>
|
|
57
|
+
t('automations.unavailable.where.filter', {
|
|
58
|
+
field: fields.find(({ key }) => key === field)?.label ?? field,
|
|
59
|
+
})
|
|
60
|
+
const place = { target: AUTOMATION_CONDITIONS_ELEMENT_ID, inFilters: true }
|
|
61
|
+
|
|
62
|
+
return [
|
|
63
|
+
...report.unavailable.map(({ condition, reason }, index) =>
|
|
64
|
+
item(reason === 'unknown_field' ? 'condition_unknown_field' : 'condition_not_editable', {
|
|
65
|
+
key: `condition-${index}`,
|
|
66
|
+
where: where(condition.field),
|
|
67
|
+
...place,
|
|
68
|
+
}),
|
|
69
|
+
),
|
|
70
|
+
...report.unavailableOptions.map(({ field }, index) =>
|
|
71
|
+
item('option', { key: `option-${index}`, where: where(field), ...place }),
|
|
72
|
+
),
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function actionItems(
|
|
77
|
+
action: AutomationFormAction,
|
|
78
|
+
availability: ActionAvailability,
|
|
79
|
+
): AutomationUnavailableItem[] {
|
|
80
|
+
const channel = t(`automations.channels.${action.channel}`)
|
|
81
|
+
|
|
82
|
+
return actionUnavailableKinds(action, availability).map((kind) =>
|
|
83
|
+
item(
|
|
84
|
+
kind,
|
|
85
|
+
{
|
|
86
|
+
key: `${action.key}-${kind}`,
|
|
87
|
+
where: t('automations.unavailable.where.message', {
|
|
88
|
+
name: action.messageGroupName || channel,
|
|
89
|
+
}),
|
|
90
|
+
target: automationActionElementId(action.key),
|
|
91
|
+
},
|
|
92
|
+
{ channel },
|
|
93
|
+
),
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return { triggerItem, conditionItems, actionItems }
|
|
98
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { AutomationCatalog } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
|
+
import type { AutomationsContext } from './automationsContext'
|
|
3
|
+
|
|
4
|
+
export type AutomationsGate =
|
|
5
|
+
| { state: 'ready'; catalog: AutomationCatalog; context: AutomationsContext }
|
|
6
|
+
| { state: 'loading' }
|
|
7
|
+
| { state: 'error'; title: string; description: string; retry?: () => void }
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What an Automation page needs before it can show anything: the Host's
|
|
11
|
+
* Automations context, an Organization and an Automation Catalog for the
|
|
12
|
+
* Host's Product. Checked by the page, not by the layout, so a Host that
|
|
13
|
+
* replaces the layout keeps it (ADR 0019). `AutomationsPageGate` renders it.
|
|
14
|
+
*/
|
|
15
|
+
export function useAutomationsGate() {
|
|
16
|
+
const { t } = useI18n()
|
|
17
|
+
const context = useAutomationsContext()
|
|
18
|
+
const organization = useEffectiveOrganizationStore()
|
|
19
|
+
const catalogQuery = useAutomationCatalogQuery()
|
|
20
|
+
const { product } = storeToRefs(useAppContextStore())
|
|
21
|
+
|
|
22
|
+
return computed<AutomationsGate>(() => {
|
|
23
|
+
if (!context) {
|
|
24
|
+
return {
|
|
25
|
+
state: 'error',
|
|
26
|
+
title: t('automations.gate.no_context_title'),
|
|
27
|
+
description: t('automations.gate.no_context_description'),
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (organization.status === 'resolving') return { state: 'loading' }
|
|
32
|
+
if (organization.status === 'failed') {
|
|
33
|
+
return {
|
|
34
|
+
state: 'error',
|
|
35
|
+
title: t('common.organization.lookup_failed_title'),
|
|
36
|
+
description: t('common.organization.lookup_failed_description'),
|
|
37
|
+
retry: () => void organization.retry(),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (organization.status === 'none') {
|
|
41
|
+
return {
|
|
42
|
+
state: 'error',
|
|
43
|
+
title: t('automations.gate.no_organization_title'),
|
|
44
|
+
description: t('automations.gate.no_organization_description'),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const response = catalogQuery.data.value
|
|
49
|
+
if (response?.catalog) return { state: 'ready', catalog: response.catalog, context }
|
|
50
|
+
// Answered with no catalog, or nothing to ask for: no Product, no request.
|
|
51
|
+
if (response || !product.value) {
|
|
52
|
+
return {
|
|
53
|
+
state: 'error',
|
|
54
|
+
title: t('automations.gate.no_catalog_title'),
|
|
55
|
+
description: t('automations.gate.no_catalog_description'),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (catalogQuery.status.value === 'error') {
|
|
59
|
+
return {
|
|
60
|
+
state: 'error',
|
|
61
|
+
title: t('automations.gate.catalog_failed_title'),
|
|
62
|
+
description: t('automations.gate.catalog_failed_description'),
|
|
63
|
+
retry: () => void catalogQuery.refetch(),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { state: 'loading' }
|
|
67
|
+
})
|
|
68
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { FilterOption } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
|
+
import countries from '../utils/filters/data/countries.json'
|
|
3
|
+
import languages from '../utils/filters/data/languages.json'
|
|
4
|
+
|
|
5
|
+
/** The name of a code in a language, or the English one where `Intl` has none. */
|
|
6
|
+
function toOptions(
|
|
7
|
+
entries: { code: string; name: string }[],
|
|
8
|
+
type: 'region' | 'language',
|
|
9
|
+
locale: string,
|
|
10
|
+
): FilterOption[] {
|
|
11
|
+
let names: Intl.DisplayNames | undefined
|
|
12
|
+
try {
|
|
13
|
+
names = new Intl.DisplayNames([locale], { type, fallback: 'none' })
|
|
14
|
+
} catch {
|
|
15
|
+
// A locale `Intl` does not know: the English names.
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const options = entries.map(({ code, name }) => {
|
|
19
|
+
let label: string | undefined
|
|
20
|
+
try {
|
|
21
|
+
label = names?.of(type === 'region' ? code.toUpperCase() : code)
|
|
22
|
+
} catch {
|
|
23
|
+
// A code `Intl` rejects keeps its English name.
|
|
24
|
+
}
|
|
25
|
+
return { value: code, label: label ?? name }
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return options.sort((a, b) => a.label.localeCompare(b.label, locale))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Public (ADR 0018): the sets built into the layer, as option lists in the
|
|
33
|
+
* current language, sorted by label. The values are lowercase ISO codes
|
|
34
|
+
* (`it`, `de`), the ones Smartconnect stores. For any caller of the filter
|
|
35
|
+
* components, and for a Host to pass on in `defineAutomationsContext`.
|
|
36
|
+
*/
|
|
37
|
+
export function useBuiltInOptionLists() {
|
|
38
|
+
const { locale } = useI18n()
|
|
39
|
+
|
|
40
|
+
const countryOptions = computed(() => toOptions(countries, 'region', locale.value))
|
|
41
|
+
const languageOptions = computed(() => toOptions(languages, 'language', locale.value))
|
|
42
|
+
|
|
43
|
+
return { countries: countryOptions, languages: languageOptions }
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ButtonProps } from '#ui/types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The back button of an editor page while an editor trip exists; none
|
|
5
|
+
* otherwise. It does what Cancel does, so it is busy whenever Cancel is.
|
|
6
|
+
*/
|
|
7
|
+
export function useEditorTripBack(busy: MaybeRefOrGetter<boolean | undefined>) {
|
|
8
|
+
const editorTrip = useEditorTripStore()
|
|
9
|
+
|
|
10
|
+
return computed<ButtonProps | undefined>(() =>
|
|
11
|
+
editorTrip.backLabel === undefined
|
|
12
|
+
? undefined
|
|
13
|
+
: { label: editorTrip.backLabel, loading: Boolean(toValue(busy)) },
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read-only view of the Organization the layer is working with, for the Host:
|
|
5
|
+
* e.g. to supply per-Organization `organizationData`. On an editor or preview
|
|
6
|
+
* page it is the Organization of the loaded Message Group, whatever the
|
|
7
|
+
* selector says. `organizationId` is `null` until `status` is `resolved`.
|
|
8
|
+
*/
|
|
9
|
+
export function useEffectiveOrganization() {
|
|
10
|
+
const { organizationId, status } = storeToRefs(useEffectiveOrganizationStore())
|
|
11
|
+
return { organizationId, status }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Makes the Organization of the resource a page views or edits the Effective
|
|
16
|
+
* Organization for as long as the calling component lives, so every dependent
|
|
17
|
+
* query (Brands, images, dynamic values) and everything the page creates
|
|
18
|
+
* follows the resource, not the selector (ADR 0014). Pass the Organization
|
|
19
|
+
* of the loaded resource; nothing is claimed while it is still loading.
|
|
20
|
+
*/
|
|
21
|
+
export function useResourceOrganization(
|
|
22
|
+
organizationId: MaybeRefOrGetter<string | null | undefined>,
|
|
23
|
+
) {
|
|
24
|
+
const store = useEffectiveOrganizationStore()
|
|
25
|
+
const claimant = Symbol('resource-organization')
|
|
26
|
+
|
|
27
|
+
// Sync: whatever the same load triggers next must already see the claim.
|
|
28
|
+
watch(
|
|
29
|
+
() => toValue(organizationId),
|
|
30
|
+
(id) => store.claimResource(claimant, id),
|
|
31
|
+
{ immediate: true, flush: 'sync' },
|
|
32
|
+
)
|
|
33
|
+
onScopeDispose(() => store.releaseResource(claimant))
|
|
34
|
+
}
|