@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
package/app/stores/appContext.ts
CHANGED
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computed, watch } from 'vue'
|
|
2
2
|
import {
|
|
3
3
|
MESSAGE_GROUP_PRODUCTS,
|
|
4
4
|
type AppContextConfig,
|
|
5
|
-
type AppContextState,
|
|
6
5
|
} from '@dev.smartpricing/message-composer-utils/types'
|
|
7
6
|
|
|
8
7
|
export const useAppContextStore = defineStore('appContext', () => {
|
|
9
8
|
const ctx = useComposerContext()
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// Proxy from injection with defaults (same interface as before)
|
|
10
|
+
// Proxy from injection with defaults
|
|
14
11
|
const organization_id = computed(() => ctx.organization_id?.value ?? '')
|
|
12
|
+
// A Host that passes the key owns the choice of Organization, even while
|
|
13
|
+
// the value is still empty (ADR 0014). Fixed for the session, like the key.
|
|
14
|
+
const hostOwnsOrganization = ctx.organization_id !== undefined
|
|
15
15
|
// The Product is required by the context type (ADR 0011), but a host can
|
|
16
16
|
// still omit it at runtime: read defensively and list it in
|
|
17
17
|
// `validationErrors` rather than crashing or falling back to a fake Product.
|
|
18
18
|
const product = computed<AppContextConfig['product'] | undefined>(() => ctx.product?.value)
|
|
19
|
-
const strategy = computed<NonNullable<AppContextConfig['strategy']>>(
|
|
20
|
-
() => ctx.strategy?.value ?? 'native',
|
|
21
|
-
)
|
|
22
19
|
const channels = computed<NonNullable<AppContextConfig['channels']>>(
|
|
23
20
|
() => ctx.channels?.value ?? ['email', 'whatsapp'],
|
|
24
21
|
)
|
|
25
22
|
const languages = computed<string[]>(() => ctx.languages?.value ?? ['en', 'de', 'fr', 'it', 'es'])
|
|
26
23
|
const mainLanguage = computed(() => ctx.mainLanguage?.value ?? 'en')
|
|
27
|
-
const dinamicValues = computed<Array<{ value: string; label: string }>>(
|
|
28
|
-
() => ctx.dinamicValues?.value ?? [],
|
|
29
|
-
)
|
|
30
24
|
const default_tags = computed<string[]>(() => ctx.default_tags?.value ?? [])
|
|
31
25
|
const isAdmin = computed(() => ctx.isAdmin?.value ?? false)
|
|
32
|
-
|
|
33
|
-
const
|
|
26
|
+
// The WABA the Host works on: the target of a new Message Group (ADR 0015).
|
|
27
|
+
const metaWabaId = computed(() => ctx.metaWabaId?.value || undefined)
|
|
34
28
|
|
|
35
29
|
// Sync i18n locale when mainLanguage changes
|
|
36
30
|
watch(
|
|
@@ -43,20 +37,6 @@ export const useAppContextStore = defineStore('appContext', () => {
|
|
|
43
37
|
{ immediate: true },
|
|
44
38
|
)
|
|
45
39
|
|
|
46
|
-
// Computed context object for convenience
|
|
47
|
-
const context = computed<AppContextState>(() => ({
|
|
48
|
-
product: product.value,
|
|
49
|
-
strategy: strategy.value,
|
|
50
|
-
channels: channels.value,
|
|
51
|
-
languages: languages.value,
|
|
52
|
-
mainLanguage: mainLanguage.value,
|
|
53
|
-
metaWabaId: metaWabaId.value,
|
|
54
|
-
metaAccessToken: metaAccessToken.value,
|
|
55
|
-
organization_id: organization_id.value,
|
|
56
|
-
default_tags: default_tags.value,
|
|
57
|
-
initializationSource: 'injection',
|
|
58
|
-
}))
|
|
59
|
-
|
|
60
40
|
// Validation
|
|
61
41
|
const validationErrors = computed<Record<string, string>>(() => {
|
|
62
42
|
const errors: Record<string, string> = {}
|
|
@@ -65,36 +45,20 @@ export const useAppContextStore = defineStore('appContext', () => {
|
|
|
65
45
|
errors.product = `Product is required: pass \`product\` (${MESSAGE_GROUP_PRODUCTS.join(' | ')}) in the composer context`
|
|
66
46
|
}
|
|
67
47
|
|
|
68
|
-
if (channels.value?.includes('whatsapp') && !metaWabaId.value) {
|
|
69
|
-
errors.metaConfig = 'Meta WABA ID is required for WhatsApp'
|
|
70
|
-
}
|
|
71
|
-
|
|
72
48
|
return errors
|
|
73
49
|
})
|
|
74
50
|
|
|
75
|
-
// Initialize — parent is responsible for providing valid context
|
|
76
|
-
async function initialize() {
|
|
77
|
-
isInitialized.value = true
|
|
78
|
-
}
|
|
79
|
-
|
|
80
51
|
return {
|
|
81
52
|
product,
|
|
82
|
-
strategy,
|
|
83
53
|
channels,
|
|
84
54
|
languages,
|
|
85
55
|
mainLanguage,
|
|
86
|
-
dinamicValues,
|
|
87
|
-
metaWabaId,
|
|
88
|
-
metaAccessToken,
|
|
89
56
|
organization_id,
|
|
57
|
+
hostOwnsOrganization,
|
|
90
58
|
default_tags,
|
|
91
59
|
isAdmin,
|
|
60
|
+
metaWabaId,
|
|
92
61
|
|
|
93
|
-
isInitialized: computed(() => isInitialized.value),
|
|
94
|
-
|
|
95
|
-
context,
|
|
96
62
|
validationErrors,
|
|
97
|
-
|
|
98
|
-
initialize,
|
|
99
63
|
}
|
|
100
64
|
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** The Message Group an editor saved. */
|
|
2
|
+
export interface EditorTripResult {
|
|
3
|
+
id: string
|
|
4
|
+
name: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface EditorTrip<Kept = unknown> {
|
|
8
|
+
/** Where the trip started: the route it returns to, and the back button's label, already translated. */
|
|
9
|
+
origin: { routeName: string; backLabel: string }
|
|
10
|
+
/** What the opener wants back on its return. The editor never reads it. */
|
|
11
|
+
kept: Kept
|
|
12
|
+
/** The last Message Group saved during the trip; none until a save. */
|
|
13
|
+
result?: EditorTripResult
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The pages a trip goes through, by Channel. */
|
|
17
|
+
export const EDITOR_ROUTES = {
|
|
18
|
+
email: { create: 'email-message-create', edit: 'email-message-edit' },
|
|
19
|
+
whatsapp: { create: 'whatsapp-message-create', edit: 'whatsapp-message-edit' },
|
|
20
|
+
} as const
|
|
21
|
+
|
|
22
|
+
const EDITOR_ROUTE_NAMES: ReadonlySet<string> = new Set(
|
|
23
|
+
Object.values(EDITOR_ROUTES).flatMap((routes) => Object.values(routes)),
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A round trip from a page to the Message editor and back. Layer-internal and
|
|
28
|
+
* in memory only: not Host contract, and a reload loses it.
|
|
29
|
+
*
|
|
30
|
+
* The opener starts it and takes it back on its return. The editor knows a
|
|
31
|
+
* trip, not who opened it: it shows the trip's back button and records what
|
|
32
|
+
* it saves.
|
|
33
|
+
*/
|
|
34
|
+
export const useEditorTripStore = defineStore('editorTrip', () => {
|
|
35
|
+
const trip = shallowRef<EditorTrip>()
|
|
36
|
+
|
|
37
|
+
// A trip ends where the user leaves its path: an editor opened later, from
|
|
38
|
+
// the library, is not part of it.
|
|
39
|
+
useRouter().afterEach((to, _from, failure) => {
|
|
40
|
+
if (failure || !trip.value) return
|
|
41
|
+
const name = String(to.name)
|
|
42
|
+
if (name === trip.value.origin.routeName || EDITOR_ROUTE_NAMES.has(name)) return
|
|
43
|
+
trip.value = undefined
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
function start<Kept>(origin: EditorTrip['origin'], kept: Kept) {
|
|
47
|
+
trip.value = { origin, kept }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The last Message Group saved wins, also if the user then cancels. */
|
|
51
|
+
function recordSaved(saved: EditorTripResult) {
|
|
52
|
+
if (trip.value) trip.value = { ...trip.value, result: saved }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The trip that started on this route, handed over once. */
|
|
56
|
+
function consume<Kept>(routeName: string): EditorTrip<Kept> | undefined {
|
|
57
|
+
const current = trip.value
|
|
58
|
+
if (current?.origin.routeName !== routeName) return undefined
|
|
59
|
+
trip.value = undefined
|
|
60
|
+
return current as EditorTrip<Kept>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The label of the editor's back button; none without a trip. */
|
|
64
|
+
const backLabel = computed(() => trip.value?.origin.backLabel)
|
|
65
|
+
|
|
66
|
+
return { start, recordSaved, consume, backLabel }
|
|
67
|
+
})
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { ReachableOrganization } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
|
+
|
|
3
|
+
/** Local storage key of the Organization last picked in the selector. */
|
|
4
|
+
const REMEMBERED_ORGANIZATION_KEY = 'message-composer:organization'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* - `resolving`: the Reachable Organizations lookup is running, or the Host
|
|
8
|
+
* that owns the choice has not supplied its Organization yet
|
|
9
|
+
* - `resolved`: there is an Organization to work on
|
|
10
|
+
* - `failed`: the lookup failed, `retry()` runs it again
|
|
11
|
+
* - `none`: the user reaches no Organization
|
|
12
|
+
*/
|
|
13
|
+
export type OrganizationResolutionStatus = 'resolving' | 'resolved' | 'failed' | 'none'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The Effective Organization (ADR 0014): the Organization of the resource
|
|
17
|
+
* being viewed or edited while a page claims one, otherwise the resolved one.
|
|
18
|
+
* A Host that passes `organization_id` owns the choice: the resolved one is
|
|
19
|
+
* its value, and nothing is resolved until that value arrives. Otherwise it
|
|
20
|
+
* is the user's only Reachable Organization; else the remembered selection if
|
|
21
|
+
* still reachable; else the first Reachable Organization.
|
|
22
|
+
*/
|
|
23
|
+
export const useEffectiveOrganizationStore = defineStore('effectiveOrganization', () => {
|
|
24
|
+
const appContext = useAppContextStore()
|
|
25
|
+
const { organization_id: hostOrganizationId } = storeToRefs(appContext)
|
|
26
|
+
const { hostOwnsOrganization } = appContext
|
|
27
|
+
const remembered = useLocalStorage(REMEMBERED_ORGANIZATION_KEY, '')
|
|
28
|
+
|
|
29
|
+
/** Undefined until the lookup has answered. */
|
|
30
|
+
const reachable = shallowRef<ReachableOrganization[]>()
|
|
31
|
+
const lookupState = ref<'idle' | 'loading' | 'failed'>('idle')
|
|
32
|
+
|
|
33
|
+
async function lookUp() {
|
|
34
|
+
if (lookupState.value === 'loading') return
|
|
35
|
+
lookupState.value = 'loading'
|
|
36
|
+
try {
|
|
37
|
+
// Imported on demand: the API client reads the runtime config when its
|
|
38
|
+
// module loads, and this store is reachable from plugins that load
|
|
39
|
+
// before the Nuxt app exists (same reason as in `useTracking`).
|
|
40
|
+
const { organizationApi } = await import('~/api/organization')
|
|
41
|
+
reachable.value = await organizationApi.getReachable()
|
|
42
|
+
lookupState.value = 'idle'
|
|
43
|
+
} catch {
|
|
44
|
+
lookupState.value = 'failed'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// A Host that supplies the Organization needs no lookup, however late its
|
|
49
|
+
// value arrives: falling back to a Reachable Organization meanwhile would
|
|
50
|
+
// send requests to one the Host did not mean (PAY-2882). Plain state rather
|
|
51
|
+
// than a query: the store outlives whichever component first asks for it.
|
|
52
|
+
if (!hostOwnsOrganization) void lookUp()
|
|
53
|
+
|
|
54
|
+
const reachableOrganizations = computed(() => reachable.value ?? [])
|
|
55
|
+
|
|
56
|
+
const resolvedOrganizationId = computed<string | null>(() => {
|
|
57
|
+
if (hostOwnsOrganization) return hostOrganizationId.value || null
|
|
58
|
+
|
|
59
|
+
const organizations = reachableOrganizations.value
|
|
60
|
+
// Reading `remembered` here is what validates it on load: a selection that
|
|
61
|
+
// is no longer reachable is ignored.
|
|
62
|
+
const selected =
|
|
63
|
+
organizations.length > 1 ? organizations.find((o) => o.id === remembered.value) : undefined
|
|
64
|
+
return (selected ?? organizations[0])?.id ?? null
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
/** The Organization of the resource on screen, and the component that claimed it. */
|
|
68
|
+
const resourceClaim = shallowRef<{ claimant: symbol; organizationId: string }>()
|
|
69
|
+
|
|
70
|
+
const organizationId = computed<string | null>(
|
|
71
|
+
() => resourceClaim.value?.organizationId ?? resolvedOrganizationId.value,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The Effective Organization for a request that has to name it (ADR 0014).
|
|
76
|
+
* Throws while none is resolved, so a resource request never leaves without
|
|
77
|
+
* its Organization (PAY-2882): callers wait for it to be resolved.
|
|
78
|
+
*/
|
|
79
|
+
function requireOrganizationId(): string {
|
|
80
|
+
if (!organizationId.value) {
|
|
81
|
+
throw new Error('[message-composer] No Organization resolved yet: the request was not sent')
|
|
82
|
+
}
|
|
83
|
+
return organizationId.value
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** See `useResourceOrganization`: pages do not call this directly. */
|
|
87
|
+
function claimResource(claimant: symbol, id: string | null | undefined) {
|
|
88
|
+
if (id) resourceClaim.value = { claimant, organizationId: id }
|
|
89
|
+
else releaseResource(claimant)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Only the claimant releases: a page that mounts before the previous one is
|
|
93
|
+
// gone must not lose its claim to the other's cleanup.
|
|
94
|
+
function releaseResource(claimant: symbol) {
|
|
95
|
+
if (resourceClaim.value?.claimant === claimant) resourceClaim.value = undefined
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const status = computed<OrganizationResolutionStatus>(() => {
|
|
99
|
+
if (organizationId.value) return 'resolved'
|
|
100
|
+
if (lookupState.value === 'failed') return 'failed'
|
|
101
|
+
if (lookupState.value === 'idle' && reachable.value) return 'none'
|
|
102
|
+
return 'resolving'
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
/** The selector is offered only when the choice is the user's to make. */
|
|
106
|
+
const isSelectable = computed(
|
|
107
|
+
() => !hostOwnsOrganization && reachableOrganizations.value.length > 1,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
function select(id: string) {
|
|
111
|
+
if (reachableOrganizations.value.some((o) => o.id === id)) {
|
|
112
|
+
remembered.value = id
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
organizationId,
|
|
118
|
+
requireOrganizationId,
|
|
119
|
+
resolvedOrganizationId,
|
|
120
|
+
reachableOrganizations,
|
|
121
|
+
status,
|
|
122
|
+
isSelectable,
|
|
123
|
+
select,
|
|
124
|
+
retry: lookUp,
|
|
125
|
+
claimResource,
|
|
126
|
+
releaseResource,
|
|
127
|
+
}
|
|
128
|
+
})
|
|
@@ -199,7 +199,11 @@ export const useEmailEditorStore = defineStore('emailEditor', () => {
|
|
|
199
199
|
sort_by?: 'created_at' | 'name'
|
|
200
200
|
direction?: 'asc' | 'desc'
|
|
201
201
|
}) {
|
|
202
|
-
|
|
202
|
+
// The Brands of the Effective Organization: the edited Message Group's.
|
|
203
|
+
brands.value = await brandsApi.getAll({
|
|
204
|
+
...options,
|
|
205
|
+
organization_id: useEffectiveOrganizationStore().requireOrganizationId(),
|
|
206
|
+
})
|
|
203
207
|
return brands.value
|
|
204
208
|
}
|
|
205
209
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { SubmissionJob } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
2
|
import { metaApi } from '~/api/meta'
|
|
3
3
|
import { useQueryCache } from '@pinia/colada'
|
|
4
|
-
import { useAppContextStore } from './appContext'
|
|
5
4
|
|
|
6
5
|
interface ActiveJob {
|
|
7
6
|
jobId: string
|
|
@@ -12,21 +11,17 @@ interface ActiveJob {
|
|
|
12
11
|
export const useMetaSubmissionStore = () => {
|
|
13
12
|
const toast = useToast()
|
|
14
13
|
const queryCache = useQueryCache()
|
|
15
|
-
const appContext = useAppContextStore()
|
|
16
14
|
const { t } = useI18n()
|
|
17
15
|
|
|
18
16
|
const activeJobs = useState<Map<string, ActiveJob>>('meta-submission-jobs', () => new Map())
|
|
19
17
|
const pollingInterval = useState<NodeJS.Timeout | null>('meta-polling-interval', () => null)
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const submitToMeta = async (messageGroupId: string) => {
|
|
24
|
-
if (!isConfigured.value) {
|
|
25
|
-
throw new Error('Meta configuration not available')
|
|
26
|
-
}
|
|
27
|
-
|
|
19
|
+
// `wabaId` is the WABA the user picked for a first submission, if any.
|
|
20
|
+
const submitToMeta = async (messageGroupId: string, wabaId?: string) => {
|
|
28
21
|
try {
|
|
29
|
-
const response = await metaApi.submitGroup(messageGroupId)
|
|
22
|
+
const response = await metaApi.submitGroup(messageGroupId, wabaId)
|
|
23
|
+
// The Message Group is on its WABA from now on: read it again.
|
|
24
|
+
queryCache.invalidateQueries({ key: ['message-groups', messageGroupId] })
|
|
30
25
|
startBackgroundPolling(response.jobId, messageGroupId)
|
|
31
26
|
return response
|
|
32
27
|
} catch (error) {
|
|
@@ -38,13 +33,9 @@ export const useMetaSubmissionStore = () => {
|
|
|
38
33
|
// Submit a single message (one language) for Meta review. Synchronous:
|
|
39
34
|
// the endpoint submits inline and flips the message to `pending`, so there
|
|
40
35
|
// is no job to poll — unlike the group flow.
|
|
41
|
-
const submitMessageToMeta = async (messageId: string) => {
|
|
42
|
-
if (!isConfigured.value) {
|
|
43
|
-
throw new Error('Meta configuration not available')
|
|
44
|
-
}
|
|
45
|
-
|
|
36
|
+
const submitMessageToMeta = async (messageId: string, wabaId?: string) => {
|
|
46
37
|
try {
|
|
47
|
-
const response = await metaApi.submitMessage(messageId)
|
|
38
|
+
const response = await metaApi.submitMessage(messageId, wabaId)
|
|
48
39
|
toast.add({
|
|
49
40
|
color: 'success',
|
|
50
41
|
title: t('meta_submission.message_success'),
|
|
@@ -133,7 +124,6 @@ export const useMetaSubmissionStore = () => {
|
|
|
133
124
|
return {
|
|
134
125
|
activeJobs,
|
|
135
126
|
hasActiveJobs,
|
|
136
|
-
isConfigured,
|
|
137
127
|
submitToMeta,
|
|
138
128
|
submitMessageToMeta,
|
|
139
129
|
startBackgroundPolling,
|
|
@@ -2,11 +2,14 @@ declare module 'nuxt/schema' {
|
|
|
2
2
|
interface AppConfigInput {
|
|
3
3
|
composer?: {
|
|
4
4
|
tracking?: boolean
|
|
5
|
+
/** Turns the Automation pages on (ADR 0019). Off, their routes answer 404. */
|
|
6
|
+
automations?: boolean
|
|
5
7
|
}
|
|
6
8
|
}
|
|
7
9
|
interface AppConfig {
|
|
8
10
|
composer: {
|
|
9
11
|
tracking: boolean
|
|
12
|
+
automations: boolean
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
}
|
package/app/types/tracking.ts
CHANGED
|
@@ -76,6 +76,39 @@ export interface TrackingEventMap {
|
|
|
76
76
|
// === Global ===
|
|
77
77
|
'Page View': { page_name: string }
|
|
78
78
|
|
|
79
|
+
// === Automation_list ===
|
|
80
|
+
'automation_list.delete': { automation_name: string; automation_id: string }
|
|
81
|
+
'automation_list.duplicate': { automation_name: string; automation_id: string }
|
|
82
|
+
'automation_list.edit': { automation_name: string; automation_id: string }
|
|
83
|
+
'automation_list.filter_changed': {
|
|
84
|
+
search_term: string
|
|
85
|
+
/** A Trigger type, a status, a Channel; `all` when not narrowed. */
|
|
86
|
+
trigger_type: string
|
|
87
|
+
status: string
|
|
88
|
+
channel: string
|
|
89
|
+
}
|
|
90
|
+
'automation_list.sort_changed': { column: string; direction: 'asc' | 'desc' }
|
|
91
|
+
|
|
92
|
+
// === Automation create / edit ===
|
|
93
|
+
'Automation setup': {
|
|
94
|
+
automation_sender: string
|
|
95
|
+
automation_name: string
|
|
96
|
+
automation_trigger: string
|
|
97
|
+
automation_type: string
|
|
98
|
+
automation_rules_audience: 'all' | 'segmented'
|
|
99
|
+
automation_subject: string
|
|
100
|
+
automation_moment: string
|
|
101
|
+
automation_channel: string
|
|
102
|
+
automation_status: string
|
|
103
|
+
automation_days: number
|
|
104
|
+
created_by: 'user'
|
|
105
|
+
}
|
|
106
|
+
'automation.clone': { automation_name: string; source_id: string }
|
|
107
|
+
'automation.trigger_changed': { from: string; to: string }
|
|
108
|
+
'automation.action_added': { channel: string }
|
|
109
|
+
'automation.action_deleted': { channel: string }
|
|
110
|
+
'automation.action_toggled': { channel: string; new_status: string }
|
|
111
|
+
|
|
79
112
|
// === Brand ===
|
|
80
113
|
brand_create: BrandBaseProperties & { has_logo: boolean }
|
|
81
114
|
brand_update: BrandBaseProperties & { changed_fields: string[] }
|