@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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { OrganizationWaba } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
|
+
import WabaSelectModal from '~/components/Composer/WabaSelectModal.vue'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The WABA of the Message Group in the WhatsApp editor (ADR 0015): chosen at
|
|
6
|
+
* the first submission and fixed from then on.
|
|
7
|
+
*
|
|
8
|
+
* `storedWabaId` is the WABA the loaded Message Group is on, if any.
|
|
9
|
+
*/
|
|
10
|
+
export function useMessageGroupWaba(storedWabaId: MaybeRefOrGetter<string | null | undefined>) {
|
|
11
|
+
const { data: wabas, refresh } = useOrganizationWabasQuery()
|
|
12
|
+
const { metaWabaId } = storeToRefs(useAppContextStore())
|
|
13
|
+
const modal = useOverlay().create(WabaSelectModal)
|
|
14
|
+
|
|
15
|
+
// A submission of one language does not read the Message Group again: its
|
|
16
|
+
// WABA is remembered here until it does.
|
|
17
|
+
const submittedWabaId = ref<string>()
|
|
18
|
+
|
|
19
|
+
const wabaId = computed(() => toValue(storedWabaId) ?? submittedWabaId.value ?? null)
|
|
20
|
+
|
|
21
|
+
/** The WABA the Message Group is on, by id alone when it is not listed. */
|
|
22
|
+
const waba = computed<OrganizationWaba | null>(() => {
|
|
23
|
+
if (!wabaId.value) return null
|
|
24
|
+
return (
|
|
25
|
+
wabas.value?.find((candidate) => candidate.id === wabaId.value) ?? {
|
|
26
|
+
id: wabaId.value,
|
|
27
|
+
name: '',
|
|
28
|
+
phone_numbers: [],
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The Message Group is on a WABA that is no longer one of its
|
|
35
|
+
* Organization's: it cannot be submitted any more. Never true while the
|
|
36
|
+
* lookup is running or failed.
|
|
37
|
+
*/
|
|
38
|
+
const isDetached = computed(
|
|
39
|
+
() =>
|
|
40
|
+
!!wabaId.value &&
|
|
41
|
+
!!wabas.value &&
|
|
42
|
+
!wabas.value.some((candidate) => candidate.id === wabaId.value),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The WABA to name in a submission. At the first submission of a Message
|
|
47
|
+
* Group whose Organization has several WABAs, it is the Host's when the
|
|
48
|
+
* Host passed one of them, otherwise the user is asked. In every other
|
|
49
|
+
* case none is named and the backend resolves it. A lookup that has not
|
|
50
|
+
* answered yet is waited for; one that failed leaves it to the backend.
|
|
51
|
+
* Returns null when the user gives up.
|
|
52
|
+
*/
|
|
53
|
+
async function chooseWaba(): Promise<{ wabaId?: string } | null> {
|
|
54
|
+
if (wabaId.value) return {}
|
|
55
|
+
if (!wabas.value) await refresh()
|
|
56
|
+
const candidates = wabas.value
|
|
57
|
+
if (!candidates || candidates.length < 2) return {}
|
|
58
|
+
|
|
59
|
+
const hostWabaId = metaWabaId.value
|
|
60
|
+
if (hostWabaId && candidates.some((candidate) => candidate.id === hostWabaId)) {
|
|
61
|
+
return { wabaId: hostWabaId }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const chosen = await modal.open({ wabas: candidates }).result
|
|
65
|
+
|
|
66
|
+
return chosen ? { wabaId: chosen } : null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** After a submission went through, with the WABA it named, if any. */
|
|
70
|
+
function markSubmitted(chosen?: string) {
|
|
71
|
+
if (wabaId.value) return
|
|
72
|
+
submittedWabaId.value = chosen ?? (wabas.value?.length === 1 ? wabas.value[0]!.id : undefined)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return { waba, isDetached, chooseWaba, markSubmitted }
|
|
76
|
+
}
|
|
@@ -17,6 +17,7 @@ import { useTracking } from '~/composables/useTracking'
|
|
|
17
17
|
/** Codes a host receives on `error`; the backend ones pass through unchanged. */
|
|
18
18
|
export type MessageSendFlowErrorCode =
|
|
19
19
|
| 'NOT_SENDABLE'
|
|
20
|
+
| 'NOT_OFFERED'
|
|
20
21
|
| 'MISSING_PARAMETERS'
|
|
21
22
|
| 'TEMPLATE_NOT_SUBMITTED'
|
|
22
23
|
| 'TEMPLATE_NOT_APPROVED'
|
|
@@ -64,11 +65,15 @@ export function useMessageSendFlow(options: {
|
|
|
64
65
|
preferredLanguage: MaybeRefOrGetter<string | undefined>
|
|
65
66
|
prefill: MaybeRefOrGetter<Record<string, string> | undefined>
|
|
66
67
|
brandId: MaybeRefOrGetter<string | undefined>
|
|
68
|
+
/** The Organization the flow works on; unset, the one the layer resolved. */
|
|
69
|
+
organizationId?: MaybeRefOrGetter<string | undefined>
|
|
70
|
+
/** The WABA the Host sends from: only WhatsApp groups on it are offered (ADR 0015). */
|
|
71
|
+
wabaId?: MaybeRefOrGetter<string | undefined>
|
|
67
72
|
emit: <K extends keyof MessageSendFlowEmits>(event: K, ...args: MessageSendFlowEmits[K]) => void
|
|
68
73
|
}) {
|
|
69
74
|
const { groupId, emit } = options
|
|
70
75
|
const { t } = useI18n()
|
|
71
|
-
const { trackEvent } = useTracking()
|
|
76
|
+
const { trackEvent } = useTracking({ organizationId: options.organizationId })
|
|
72
77
|
|
|
73
78
|
// --- Group -------------------------------------------------------------
|
|
74
79
|
const { data: group, isLoading: groupLoading } = useMessageGroupQuery(() => groupId.value ?? '', {
|
|
@@ -87,7 +92,23 @@ export function useMessageSendFlow(options: {
|
|
|
87
92
|
})),
|
|
88
93
|
)
|
|
89
94
|
|
|
90
|
-
|
|
95
|
+
// A group reaches the flow by id too (the Host's preselection): one of
|
|
96
|
+
// another Organization, or on another WABA, is not the picker's to offer.
|
|
97
|
+
const offered = computed(() => {
|
|
98
|
+
if (!group.value) return true
|
|
99
|
+
const organizationId = toValue(options.organizationId)
|
|
100
|
+
if (
|
|
101
|
+
organizationId &&
|
|
102
|
+
group.value.organization_id?.toLowerCase() !== organizationId.toLowerCase()
|
|
103
|
+
)
|
|
104
|
+
return false
|
|
105
|
+
const wabaId = toValue(options.wabaId)
|
|
106
|
+
return (
|
|
107
|
+
!wabaId || toValue(options.renderType) !== 'whatsapp_v1' || group.value.waba_id === wabaId
|
|
108
|
+
)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
const sendable = computed(() => offered.value && languages.value.some((l) => l.approved))
|
|
91
112
|
const notSendable = computed(
|
|
92
113
|
() => !!groupId.value && !!group.value && !groupLoading.value && !sendable.value,
|
|
93
114
|
)
|
|
@@ -114,9 +135,16 @@ export function useMessageSendFlow(options: {
|
|
|
114
135
|
|
|
115
136
|
// --- Parameters ----------------------------------------------------------
|
|
116
137
|
const parametersEnabled = () => !!groupId.value && !!selectedLanguage.value
|
|
138
|
+
const organization = useEffectiveOrganizationStore()
|
|
117
139
|
|
|
118
140
|
const { data: parametersData, isLoading: parametersLoading } = useQuery({
|
|
119
|
-
key: () => [
|
|
141
|
+
key: () => [
|
|
142
|
+
'send-flow',
|
|
143
|
+
'parameters',
|
|
144
|
+
groupId.value ?? '',
|
|
145
|
+
selectedLanguage.value ?? '',
|
|
146
|
+
organization.organizationId,
|
|
147
|
+
],
|
|
120
148
|
query: () => compilationApi.getParameters(groupId.value ?? '', selectedLanguage.value ?? ''),
|
|
121
149
|
enabled: parametersEnabled,
|
|
122
150
|
})
|
|
@@ -170,17 +198,26 @@ export function useMessageSendFlow(options: {
|
|
|
170
198
|
emit('error', error)
|
|
171
199
|
}
|
|
172
200
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
201
|
+
// The reason a picked group cannot enter the flow. Watched with the group,
|
|
202
|
+
// so another group, or another reason for the same one, is reported anew.
|
|
203
|
+
const groupError = computed<MessageSendFlowErrorCode | undefined>(() => {
|
|
204
|
+
if (!notSendable.value) return undefined
|
|
205
|
+
return offered.value ? 'NOT_SENDABLE' : 'NOT_OFFERED'
|
|
206
|
+
})
|
|
207
|
+
watch([groupError, () => group.value?.id], ([code]) => {
|
|
208
|
+
if (code) {
|
|
209
|
+
fail(code)
|
|
210
|
+
} else if (
|
|
211
|
+
flowError.value?.code === 'NOT_SENDABLE' ||
|
|
212
|
+
flowError.value?.code === 'NOT_OFFERED'
|
|
213
|
+
) {
|
|
177
214
|
flowError.value = undefined
|
|
178
215
|
}
|
|
179
216
|
})
|
|
180
217
|
|
|
181
218
|
// --- Compile (once, on Confirm) --------------------------------------------
|
|
182
219
|
const compiling = ref(false)
|
|
183
|
-
const canConfirm = computed(() => !!selectedMessage.value && !compiling.value)
|
|
220
|
+
const canConfirm = computed(() => sendable.value && !!selectedMessage.value && !compiling.value)
|
|
184
221
|
|
|
185
222
|
async function confirm() {
|
|
186
223
|
flowError.value = undefined
|
|
@@ -242,5 +279,6 @@ export function useMessageSendFlow(options: {
|
|
|
242
279
|
compiling,
|
|
243
280
|
canConfirm,
|
|
244
281
|
confirm,
|
|
282
|
+
trackEvent,
|
|
245
283
|
}
|
|
246
284
|
}
|
|
@@ -23,6 +23,8 @@ export interface PagedMessageGroupsOptions {
|
|
|
23
23
|
resetOn?: WatchSource[]
|
|
24
24
|
/** When false no request is made (the query stays pending). */
|
|
25
25
|
enabled?: MaybeRefOrGetter<boolean>
|
|
26
|
+
/** Lists this Organization instead of the resolved one. */
|
|
27
|
+
organizationId?: MaybeRefOrGetter<string | undefined>
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -42,12 +44,22 @@ export function usePagedMessageGroups(options: PagedMessageGroupsOptions) {
|
|
|
42
44
|
per_page: options.perPage,
|
|
43
45
|
}))
|
|
44
46
|
|
|
45
|
-
const query = useMessageGroupListQuery(listOptions, {
|
|
47
|
+
const query = useMessageGroupListQuery(listOptions, {
|
|
48
|
+
enabled: options.enabled,
|
|
49
|
+
organizationId: options.organizationId,
|
|
50
|
+
})
|
|
46
51
|
|
|
47
52
|
// The reset happens in the same tick as the change (sync flush) so the query
|
|
48
53
|
// sees one key change, not two, and the user never opens an empty page.
|
|
54
|
+
const organization = useEffectiveOrganizationStore()
|
|
49
55
|
watch(
|
|
50
|
-
[
|
|
56
|
+
[
|
|
57
|
+
debouncedSearch,
|
|
58
|
+
() => toValue(options.renderType),
|
|
59
|
+
// Another Organization is another list: its page N may not exist.
|
|
60
|
+
() => toValue(options.organizationId) || organization.resolvedOrganizationId,
|
|
61
|
+
...(options.resetOn ?? []),
|
|
62
|
+
],
|
|
51
63
|
() => {
|
|
52
64
|
options.page.value = 1
|
|
53
65
|
},
|
|
@@ -21,7 +21,8 @@ interface TemplateData<T = Message | PostEntity<Message>> {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
interface UseTemplateOperationsOptions {
|
|
24
|
-
|
|
24
|
+
/** Called with the Message Group that was saved, before anything navigates. */
|
|
25
|
+
onSuccess?: (saved?: { id: string; name: string }) => void
|
|
25
26
|
onError?: (error: Error) => void
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -29,6 +30,7 @@ export function useTemplateOperations(options: UseTemplateOperationsOptions = {}
|
|
|
29
30
|
const saving = ref(false)
|
|
30
31
|
const saved = ref(false)
|
|
31
32
|
const appContext = useAppContextStore()
|
|
33
|
+
const organization = useEffectiveOrganizationStore()
|
|
32
34
|
|
|
33
35
|
// Hoist composables to setup scope (they use inject() internally)
|
|
34
36
|
const { mutateAsync: createMessageGroup } = useCreateMessageGroupMutation()
|
|
@@ -51,6 +53,9 @@ export function useTemplateOperations(options: UseTemplateOperationsOptions = {}
|
|
|
51
53
|
const createdMessageGroup = await createMessageGroup({
|
|
52
54
|
...data.messageGroup,
|
|
53
55
|
product,
|
|
56
|
+
// The Effective Organization (ADR 0014): the selected one, or the
|
|
57
|
+
// edited group's on "save as new".
|
|
58
|
+
organization_id: organization.requireOrganizationId(),
|
|
54
59
|
} as PostEntity<MessageGroup>)
|
|
55
60
|
|
|
56
61
|
if (createdMessageGroup?.id) {
|
|
@@ -63,7 +68,11 @@ export function useTemplateOperations(options: UseTemplateOperationsOptions = {}
|
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
saved.value = true
|
|
66
|
-
options.onSuccess?.(
|
|
71
|
+
options.onSuccess?.(
|
|
72
|
+
createdMessageGroup?.id
|
|
73
|
+
? { id: String(createdMessageGroup.id), name: createdMessageGroup.name }
|
|
74
|
+
: undefined,
|
|
75
|
+
)
|
|
67
76
|
return createdMessageGroup
|
|
68
77
|
} catch (error) {
|
|
69
78
|
options.onError?.(error as Error)
|
|
@@ -97,7 +106,7 @@ export function useTemplateOperations(options: UseTemplateOperationsOptions = {}
|
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
saved.value = true
|
|
100
|
-
options.onSuccess?.()
|
|
109
|
+
options.onSuccess?.({ id, name: data.messageGroup.name })
|
|
101
110
|
} catch (error) {
|
|
102
111
|
options.onError?.(error as Error)
|
|
103
112
|
throw error
|
|
@@ -112,7 +121,12 @@ export function useTemplateOperations(options: UseTemplateOperationsOptions = {}
|
|
|
112
121
|
try {
|
|
113
122
|
const result = await duplicateMessageGroup({
|
|
114
123
|
id: sourceId,
|
|
115
|
-
data:
|
|
124
|
+
data: {
|
|
125
|
+
...(newName && { name: newName }),
|
|
126
|
+
// The Effective Organization (ADR 0014): the selected one, or the
|
|
127
|
+
// edited group's on "save as new".
|
|
128
|
+
organization_id: organization.requireOrganizationId(),
|
|
129
|
+
},
|
|
116
130
|
})
|
|
117
131
|
|
|
118
132
|
saved.value = true
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue'
|
|
1
2
|
import type { TrackingEventMap } from '~/types/tracking'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
/** `organizationId` names the Organization of the events instead of the Effective one. */
|
|
5
|
+
export function useTracking(
|
|
6
|
+
options: { organizationId?: MaybeRefOrGetter<string | undefined> } = {},
|
|
7
|
+
) {
|
|
4
8
|
const { product, mainLanguage, isAdmin } = storeToRefs(useAppContextStore())
|
|
9
|
+
const effectiveOrganization = useEffectiveOrganizationStore()
|
|
10
|
+
const organizationId = computed(
|
|
11
|
+
() => toValue(options.organizationId) || effectiveOrganization.organizationId,
|
|
12
|
+
)
|
|
5
13
|
|
|
6
14
|
function getDefaultProperties(): Record<string, unknown> {
|
|
7
15
|
return {
|
|
@@ -17,12 +25,13 @@ export function useTracking() {
|
|
|
17
25
|
properties?: TrackingEventMap[T],
|
|
18
26
|
): Promise<void> {
|
|
19
27
|
if (!useAppConfig().composer?.tracking) return
|
|
28
|
+
const payload = { ...getDefaultProperties(), ...properties }
|
|
20
29
|
try {
|
|
30
|
+
// The tracking route needs an Organization: an event fired while it is
|
|
31
|
+
// still being resolved (the first page view) waits instead of being lost.
|
|
32
|
+
const organization = await until(organizationId).toBeTruthy()
|
|
21
33
|
const { trackingApi } = await import('@/api/tracking')
|
|
22
|
-
await trackingApi.event(eventName,
|
|
23
|
-
...getDefaultProperties(),
|
|
24
|
-
...properties,
|
|
25
|
-
})
|
|
34
|
+
await trackingApi.event(eventName, organization, payload)
|
|
26
35
|
} catch {
|
|
27
36
|
if (import.meta.dev) {
|
|
28
37
|
console.warn(`[Tracking] Failed to track "${eventName}"`, properties)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* - `unavailable`: the Host's channels do not include WhatsApp
|
|
3
|
+
* - `checking`: the WABA lookup of the Effective Organization is running
|
|
4
|
+
* - `configured`: the Effective Organization has at least one WABA
|
|
5
|
+
* - `not_configured`: the lookup answered, the Organization has no WABA
|
|
6
|
+
* - `failed`: the lookup failed, so whether there is a WABA is not known
|
|
7
|
+
*/
|
|
8
|
+
export type WhatsappConfigurationStatus =
|
|
9
|
+
| 'unavailable'
|
|
10
|
+
| 'checking'
|
|
11
|
+
| 'configured'
|
|
12
|
+
| 'not_configured'
|
|
13
|
+
| 'failed'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether WhatsApp is configured: the Host's channels include WhatsApp and
|
|
17
|
+
* the Effective Organization has at least one WABA (ADR 0015). The WABAs
|
|
18
|
+
* follow the Organization, so the answer changes with it.
|
|
19
|
+
* A lookup still running or failed is never read as "no WABA".
|
|
20
|
+
*/
|
|
21
|
+
export function useWhatsappConfiguration() {
|
|
22
|
+
const { hasWhatsapp } = useChannels()
|
|
23
|
+
const { data, status: lookupStatus } = useOrganizationWabasQuery()
|
|
24
|
+
|
|
25
|
+
const status = computed<WhatsappConfigurationStatus>(() => {
|
|
26
|
+
if (!hasWhatsapp.value) return 'unavailable'
|
|
27
|
+
if (data.value) return data.value.length > 0 ? 'configured' : 'not_configured'
|
|
28
|
+
return lookupStatus.value === 'error' ? 'failed' : 'checking'
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return { status }
|
|
32
|
+
}
|
package/app/layouts/default.vue
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<SNavigationPage :panel-props="{ ui: { body: 'p-0 sm:p-0 gap-0 sm:gap-0 overflow-hidden' } }">
|
|
3
3
|
<CommonAppContextErrors />
|
|
4
|
-
<
|
|
4
|
+
<CommonWhatsappNotConfigured />
|
|
5
|
+
<CommonOrganizationGate>
|
|
6
|
+
<slot />
|
|
7
|
+
</CommonOrganizationGate>
|
|
5
8
|
</SNavigationPage>
|
|
6
9
|
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Automation pages are off until a Host sets `composer.automations`
|
|
3
|
+
* (ADR 0019): their routes always exist, and answer 404 while it is off.
|
|
4
|
+
*/
|
|
5
|
+
export default defineNuxtRouteMiddleware(() => {
|
|
6
|
+
if (useAppConfig().composer?.automations) return
|
|
7
|
+
|
|
8
|
+
// Fatal, or a navigation inside the app would be cancelled without a word.
|
|
9
|
+
return abortNavigation(
|
|
10
|
+
createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true }),
|
|
11
|
+
)
|
|
12
|
+
})
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
definePageMeta({
|
|
3
|
+
name: 'automation-edit',
|
|
4
|
+
middleware: 'automations-enabled',
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const { t } = useI18n()
|
|
8
|
+
const route = useRoute()
|
|
9
|
+
const gate = useAutomationsGate()
|
|
10
|
+
const { goBackOrFallback } = useGoBack()
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
data: automation,
|
|
14
|
+
error,
|
|
15
|
+
status,
|
|
16
|
+
refetch,
|
|
17
|
+
} = useAutomationQuery(() => String(route.params.id))
|
|
18
|
+
const notFound = computed(() => (error.value as { status?: number } | null)?.status === 404)
|
|
19
|
+
|
|
20
|
+
const edit = useTemplateRef('edit')
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<template>
|
|
24
|
+
<LayoutBasePage :title="t('automations.editTitle')" :test-id="automationsTestIds.editPage">
|
|
25
|
+
<template #actions>
|
|
26
|
+
<UButton
|
|
27
|
+
variant="ghost"
|
|
28
|
+
size="lg"
|
|
29
|
+
:label="t('common.actions.cancel')"
|
|
30
|
+
:data-testid="automationsTestIds.editPageCancelButton"
|
|
31
|
+
@click="goBackOrFallback({ name: 'automations-list' })"
|
|
32
|
+
/>
|
|
33
|
+
<UButton
|
|
34
|
+
v-if="edit"
|
|
35
|
+
size="lg"
|
|
36
|
+
:loading="edit.saving"
|
|
37
|
+
:label="t('common.actions.save')"
|
|
38
|
+
:data-testid="automationsTestIds.editPageCreateButton"
|
|
39
|
+
@click="edit.submit()"
|
|
40
|
+
/>
|
|
41
|
+
</template>
|
|
42
|
+
|
|
43
|
+
<AutomationsPageGate v-slot="{ catalog, context }" :gate="gate">
|
|
44
|
+
<AutomationsEdit
|
|
45
|
+
v-if="automation"
|
|
46
|
+
ref="edit"
|
|
47
|
+
:key="automation.id"
|
|
48
|
+
:catalog="catalog"
|
|
49
|
+
:automation="automation"
|
|
50
|
+
:context="context"
|
|
51
|
+
/>
|
|
52
|
+
<UAlert
|
|
53
|
+
v-else-if="status === 'error'"
|
|
54
|
+
color="error"
|
|
55
|
+
variant="subtle"
|
|
56
|
+
icon="i-lucide-alert-triangle"
|
|
57
|
+
:title="
|
|
58
|
+
notFound ? t('automations.gate.not_found_title') : t('automations.gate.load_failed_title')
|
|
59
|
+
"
|
|
60
|
+
:description="
|
|
61
|
+
notFound
|
|
62
|
+
? t('automations.gate.not_found_description')
|
|
63
|
+
: t('automations.gate.load_failed_description')
|
|
64
|
+
"
|
|
65
|
+
:actions="
|
|
66
|
+
notFound
|
|
67
|
+
? undefined
|
|
68
|
+
: [
|
|
69
|
+
{
|
|
70
|
+
label: t('common.organization.retry'),
|
|
71
|
+
color: 'error',
|
|
72
|
+
variant: 'outline',
|
|
73
|
+
onClick: () => void refetch(),
|
|
74
|
+
},
|
|
75
|
+
]
|
|
76
|
+
"
|
|
77
|
+
/>
|
|
78
|
+
<div
|
|
79
|
+
v-else
|
|
80
|
+
class="flex flex-1 flex-col items-center justify-center gap-3 py-12 text-muted"
|
|
81
|
+
role="status"
|
|
82
|
+
>
|
|
83
|
+
<UIcon name="i-heroicons-arrow-path" class="animate-spin h-8 w-8" />
|
|
84
|
+
</div>
|
|
85
|
+
</AutomationsPageGate>
|
|
86
|
+
</LayoutBasePage>
|
|
87
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
definePageMeta({
|
|
3
|
+
name: 'automations-list',
|
|
4
|
+
middleware: 'automations-enabled',
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const { t } = useI18n()
|
|
8
|
+
const gate = useAutomationsGate()
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<LayoutBasePage :title="t('automations.title')" :test-id="automationsTestIds.page">
|
|
13
|
+
<template #actions>
|
|
14
|
+
<CommonOrganizationSelect />
|
|
15
|
+
<UButton
|
|
16
|
+
v-if="gate.state === 'ready'"
|
|
17
|
+
icon="ph:plus-bold"
|
|
18
|
+
:label="t('automations.new')"
|
|
19
|
+
:to="{ name: 'automation-create' }"
|
|
20
|
+
:data-testid="automationsTestIds.newButton"
|
|
21
|
+
/>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<AutomationsPageGate v-slot="{ catalog }" :gate="gate">
|
|
25
|
+
<AutomationsList :catalog="catalog" />
|
|
26
|
+
</AutomationsPageGate>
|
|
27
|
+
</LayoutBasePage>
|
|
28
|
+
</template>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
definePageMeta({
|
|
3
|
+
name: 'automation-create',
|
|
4
|
+
middleware: 'automations-enabled',
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const { t } = useI18n()
|
|
8
|
+
const gate = useAutomationsGate()
|
|
9
|
+
const { goBackOrFallback } = useGoBack()
|
|
10
|
+
|
|
11
|
+
const create = useTemplateRef('create')
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<LayoutBasePage :title="t('automations.newTitle')" :test-id="automationsTestIds.newPage">
|
|
16
|
+
<template #actions>
|
|
17
|
+
<UButton
|
|
18
|
+
variant="ghost"
|
|
19
|
+
size="lg"
|
|
20
|
+
:label="t('common.actions.cancel')"
|
|
21
|
+
:data-testid="automationsTestIds.newPageCancelButton"
|
|
22
|
+
@click="goBackOrFallback({ name: 'automations-list' })"
|
|
23
|
+
/>
|
|
24
|
+
<UButton
|
|
25
|
+
v-if="create"
|
|
26
|
+
size="lg"
|
|
27
|
+
:loading="create.saving"
|
|
28
|
+
:label="t('automations.form.create')"
|
|
29
|
+
:data-testid="automationsTestIds.newPageCreateButton"
|
|
30
|
+
@click="create.submit()"
|
|
31
|
+
/>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<AutomationsPageGate v-slot="{ catalog, context }" :gate="gate">
|
|
35
|
+
<AutomationsCreate
|
|
36
|
+
v-if="catalog.triggers[0]"
|
|
37
|
+
ref="create"
|
|
38
|
+
:catalog="catalog"
|
|
39
|
+
:initial-trigger="catalog.triggers[0]"
|
|
40
|
+
:context="context"
|
|
41
|
+
/>
|
|
42
|
+
<!-- A catalog with no Trigger has nothing to build an Automation from. -->
|
|
43
|
+
<UAlert
|
|
44
|
+
v-else
|
|
45
|
+
color="error"
|
|
46
|
+
variant="subtle"
|
|
47
|
+
icon="i-lucide-alert-triangle"
|
|
48
|
+
:title="t('automations.gate.no_catalog_title')"
|
|
49
|
+
:description="t('automations.gate.no_catalog_description')"
|
|
50
|
+
/>
|
|
51
|
+
</AutomationsPageGate>
|
|
52
|
+
</LayoutBasePage>
|
|
53
|
+
</template>
|
package/app/pages/brands.vue
CHANGED
package/app/pages/images.vue
CHANGED
|
@@ -8,6 +8,10 @@ const { t } = useI18n()
|
|
|
8
8
|
|
|
9
9
|
<template>
|
|
10
10
|
<LayoutBasePage :title="t('pages.images.title')" :test-id="imagesPageTestIds.navbar">
|
|
11
|
+
<template #actions>
|
|
12
|
+
<CommonOrganizationSelect />
|
|
13
|
+
</template>
|
|
14
|
+
|
|
11
15
|
<ComposerImageGallery />
|
|
12
16
|
</LayoutBasePage>
|
|
13
17
|
</template>
|
package/app/pages/index.vue
CHANGED
|
@@ -25,6 +25,9 @@ watch(renderType, (newType) => {
|
|
|
25
25
|
trackEvent('change_tab', { messages_kind: newType === 'email_v1' ? 'email' : 'whatsapp' })
|
|
26
26
|
})
|
|
27
27
|
|
|
28
|
+
// The Import from Meta check waits for the list: it must never slow it down.
|
|
29
|
+
const listLoaded = ref(false)
|
|
30
|
+
|
|
28
31
|
const tabItems = computed(() => {
|
|
29
32
|
const items = []
|
|
30
33
|
if (hasWhatsapp.value) {
|
|
@@ -54,9 +57,11 @@ const tabItems = computed(() => {
|
|
|
54
57
|
@tab-change="renderType = $event as RenderType"
|
|
55
58
|
>
|
|
56
59
|
<template #actions>
|
|
60
|
+
<CommonOrganizationSelect />
|
|
61
|
+
<MetaImportButton :enabled="listLoaded" @imported="renderType = 'whatsapp_v1'" />
|
|
57
62
|
<CreateTemplateButton />
|
|
58
63
|
</template>
|
|
59
64
|
|
|
60
|
-
<ComposerMessageLibrary v-model:render-type="renderType" />
|
|
65
|
+
<ComposerMessageLibrary v-model:render-type="renderType" @loaded="listLoaded = true" />
|
|
61
66
|
</LayoutBasePage>
|
|
62
67
|
</template>
|
|
@@ -13,6 +13,8 @@ definePageMeta({
|
|
|
13
13
|
const route = useRoute()
|
|
14
14
|
const { locale } = useI18n()
|
|
15
15
|
const { data: messageGroup } = useMessageGroupQuery(() => route.params.id as string)
|
|
16
|
+
// The preview works on the Organization of the Message Group it shows.
|
|
17
|
+
useResourceOrganization(() => messageGroup.value?.organization_id)
|
|
16
18
|
|
|
17
19
|
const selectedMessage = computed(() => {
|
|
18
20
|
if (!messageGroup.value?.messages.length) return undefined
|
|
@@ -8,6 +8,9 @@ definePageMeta({
|
|
|
8
8
|
const route = useRoute()
|
|
9
9
|
const composerRef = useTemplateRef('composerRef')
|
|
10
10
|
const store = useEmailComposerStore()
|
|
11
|
+
const tripBack = useEditorTripBack(
|
|
12
|
+
() => composerRef.value?.saving || composerRef.value?.isTranslating,
|
|
13
|
+
)
|
|
11
14
|
</script>
|
|
12
15
|
|
|
13
16
|
<template>
|
|
@@ -25,6 +28,8 @@ const store = useEmailComposerStore()
|
|
|
25
28
|
]"
|
|
26
29
|
:active-tab="store.activeTab"
|
|
27
30
|
:test-id="templateEmailEditTestIds.navbar"
|
|
31
|
+
:back="tripBack"
|
|
32
|
+
@back="composerRef?.handleCancel()"
|
|
28
33
|
@tab-change="store.activeTab = $event as 'content' | 'translations'"
|
|
29
34
|
>
|
|
30
35
|
<template #actions>
|
|
@@ -7,6 +7,9 @@ definePageMeta({
|
|
|
7
7
|
|
|
8
8
|
const composerRef = useTemplateRef('composerRef')
|
|
9
9
|
const store = useEmailComposerStore()
|
|
10
|
+
const tripBack = useEditorTripBack(
|
|
11
|
+
() => composerRef.value?.saving || composerRef.value?.isTranslating,
|
|
12
|
+
)
|
|
10
13
|
</script>
|
|
11
14
|
|
|
12
15
|
<template>
|
|
@@ -24,6 +27,8 @@ const store = useEmailComposerStore()
|
|
|
24
27
|
]"
|
|
25
28
|
:active-tab="store.activeTab"
|
|
26
29
|
:test-id="templateEmailCreateTestIds.navbar"
|
|
30
|
+
:back="tripBack"
|
|
31
|
+
@back="composerRef?.handleCancel()"
|
|
27
32
|
@tab-change="store.activeTab = $event as 'content' | 'translations'"
|
|
28
33
|
>
|
|
29
34
|
<template #actions>
|
|
@@ -8,6 +8,9 @@ definePageMeta({
|
|
|
8
8
|
const route = useRoute()
|
|
9
9
|
const composerRef = useTemplateRef('composerRef')
|
|
10
10
|
const store = useWhatsappComposerStore()
|
|
11
|
+
const tripBack = useEditorTripBack(
|
|
12
|
+
() => composerRef.value?.saving || composerRef.value?.isTranslating,
|
|
13
|
+
)
|
|
11
14
|
</script>
|
|
12
15
|
|
|
13
16
|
<template>
|
|
@@ -19,6 +22,8 @@ const store = useWhatsappComposerStore()
|
|
|
19
22
|
]"
|
|
20
23
|
:active-tab="store.activeTab"
|
|
21
24
|
:test-id="templateWhatsappEditTestIds.navbar"
|
|
25
|
+
:back="tripBack"
|
|
26
|
+
@back="composerRef?.handleCancel()"
|
|
22
27
|
@tab-change="store.activeTab = $event as 'content' | 'translations'"
|
|
23
28
|
>
|
|
24
29
|
<template #actions>
|
|
@@ -55,6 +60,7 @@ const store = useWhatsappComposerStore()
|
|
|
55
60
|
:label="$t('pages.whatsapp.create_message_group.request_approval')"
|
|
56
61
|
color="primary"
|
|
57
62
|
:loading="composerRef?.saving || composerRef?.isTranslating"
|
|
63
|
+
:disabled="composerRef?.isWabaDetached"
|
|
58
64
|
:data-testid="templateWhatsappEditTestIds.requestApprovalButton"
|
|
59
65
|
/>
|
|
60
66
|
</template>
|