@dev.smartpricing/message-composer-layer 4.3.2-fix.1 → 4.5.1-automation.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +357 -46
- package/app/api/automations.ts +74 -0
- package/app/api/brands.ts +20 -13
- package/app/api/client.ts +15 -6
- package/app/api/compilation.ts +13 -3
- package/app/api/dynamicValues.ts +6 -2
- package/app/api/index.ts +1 -0
- package/app/api/media.ts +6 -3
- package/app/api/messageGroups.ts +34 -15
- package/app/api/meta.ts +62 -4
- package/app/api/organization.ts +10 -1
- package/app/api/tracking.ts +2 -2
- package/app/app.config.ts +10 -0
- package/app/components/Automations/ActionCard.vue +174 -0
- package/app/components/Automations/ActionEditor.vue +398 -0
- package/app/components/Automations/Actions.vue +158 -0
- package/app/components/Automations/CloneModal.vue +78 -0
- package/app/components/Automations/Conditions.vue +155 -0
- package/app/components/Automations/Create.vue +114 -0
- package/app/components/Automations/Data.vue +46 -0
- package/app/components/Automations/DeleteModal.vue +80 -0
- package/app/components/Automations/Edit.vue +145 -0
- package/app/components/Automations/Form.vue +282 -0
- package/app/components/Automations/List.vue +370 -0
- package/app/components/Automations/PageGate.vue +50 -0
- package/app/components/Automations/SaveProblems.vue +54 -0
- package/app/components/Automations/Unavailable.vue +71 -0
- package/app/components/Automations/UnavailableBadge.vue +35 -0
- package/app/components/Common/AppContextErrors.vue +30 -0
- package/app/components/Common/HtmlPreviewIframe.vue +17 -3
- package/app/components/Common/MessageGroupSelect.vue +193 -26
- package/app/components/Common/MessagePreviewSlideover.vue +3 -0
- package/app/components/Common/OrganizationGate.vue +51 -0
- package/app/components/Common/OrganizationSelect.vue +27 -0
- package/app/components/Common/WhatsappNotConfigured.vue +20 -0
- package/app/components/Composer/EmailComposer.vue +9 -1
- package/app/components/Composer/MessageLibrary.vue +25 -7
- package/app/components/Composer/WabaSelectModal.vue +73 -0
- package/app/components/Composer/WhatsappComposer.vue +83 -4
- package/app/components/Editor/RichTextEditor.vue +14 -2
- package/app/components/Filters/DateInput.vue +57 -0
- package/app/components/Filters/Editor.vue +163 -0
- package/app/components/Filters/Row.vue +119 -0
- package/app/components/Filters/Summary.vue +215 -0
- package/app/components/Filters/UnavailableRow.vue +74 -0
- package/app/components/Filters/ValueInput.vue +215 -0
- package/app/components/Layout/BasePage.vue +2 -0
- package/app/components/MessageSendFlow/EmailPreview.vue +81 -0
- package/app/components/MessageSendFlow/LanguageSelect.vue +39 -0
- package/app/components/MessageSendFlow/MessageSendFlow.vue +265 -0
- package/app/components/MessageSendFlow/ParametersForm.vue +51 -0
- package/app/components/MetaImport/Button.vue +50 -0
- package/app/components/MetaImport/Dialog.vue +261 -0
- package/app/components/MetaImport/Outcome.vue +136 -0
- package/app/components/MetaImport/ProposalList.vue +192 -0
- package/app/components/TemplateList/BaseTable.vue +177 -108
- package/app/components/Whatsapp/Preview.vue +17 -16
- package/app/components/Whatsapp/PreviewPanel.vue +7 -1
- package/app/components/Whatsapp/Translator/Header.vue +4 -19
- package/app/composables/apiErrorMessages.ts +1 -0
- package/app/composables/automationsContext.ts +42 -0
- package/app/composables/composerContext.ts +9 -7
- package/app/composables/useAutomationClone.ts +33 -0
- package/app/composables/useAutomationEditorTrip.ts +77 -0
- package/app/composables/useAutomationSaveProblems.ts +82 -0
- package/app/composables/useAutomationUnavailable.ts +98 -0
- package/app/composables/useAutomationsGate.ts +68 -0
- package/app/composables/useBuiltInOptionLists.ts +44 -0
- package/app/composables/useEditorTripBack.ts +15 -0
- package/app/composables/useEffectiveOrganization.ts +34 -0
- package/app/composables/useMessageGroupList.ts +186 -0
- package/app/composables/useMessageGroupWaba.ts +76 -0
- package/app/composables/useMessageSendFlow.ts +284 -0
- package/app/composables/usePagedMessageGroups.ts +78 -0
- package/app/composables/useTemplateOperations.ts +31 -7
- package/app/composables/useTracking.ts +14 -5
- package/app/composables/useWhatsappConfiguration.ts +32 -0
- package/app/layouts/default.vue +5 -1
- package/app/middleware/automations-enabled.ts +12 -0
- package/app/pages/automations/[id].vue +87 -0
- package/app/pages/automations/index.vue +28 -0
- package/app/pages/automations/new.vue +53 -0
- package/app/pages/brands.vue +1 -0
- package/app/pages/images.vue +4 -0
- package/app/pages/index.vue +6 -1
- package/app/pages/preview/[id].vue +2 -0
- package/app/pages/template/email/[id].vue +5 -0
- package/app/pages/template/email/create.vue +5 -0
- package/app/pages/template/whatsapp/[id].vue +6 -0
- package/app/pages/template/whatsapp/create.vue +5 -0
- package/app/queries/automations.ts +206 -0
- package/app/queries/brands.ts +27 -7
- package/app/queries/compilation.ts +16 -3
- package/app/queries/dynamicValues.ts +19 -2
- package/app/queries/index.ts +1 -0
- package/app/queries/media.ts +8 -3
- package/app/queries/messageGroups.ts +84 -36
- package/app/queries/meta.ts +100 -5
- package/app/stores/appContext.ts +18 -48
- package/app/stores/editorTrip.ts +67 -0
- package/app/stores/effectiveOrganization.ts +128 -0
- package/app/stores/emailEditor.ts +5 -1
- package/app/stores/metaSubmission.ts +7 -17
- package/app/types/app-config.d.ts +3 -0
- package/app/types/tracking.ts +50 -0
- package/app/utils/automations/form.ts +389 -0
- package/app/utils/automations/metadata.ts +71 -0
- package/app/utils/automations/unavailable.ts +90 -0
- package/app/utils/filters/data/countries.json +998 -0
- package/app/utils/filters/data/languages.json +754 -0
- package/app/utils/filters/rows.ts +367 -0
- package/app/utils/testIds.const.ts +137 -0
- package/i18n/locales/de.ts +419 -2
- package/i18n/locales/en.ts +398 -2
- package/i18n/locales/es.ts +403 -2
- package/i18n/locales/fr.ts +410 -2
- package/i18n/locales/it.ts +409 -2
- package/package.json +4 -4
- package/app.config.ts +0 -5
|
@@ -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>
|
|
@@ -7,6 +7,9 @@ definePageMeta({
|
|
|
7
7
|
|
|
8
8
|
const composerRef = useTemplateRef('composerRef')
|
|
9
9
|
const store = useWhatsappComposerStore()
|
|
10
|
+
const tripBack = useEditorTripBack(
|
|
11
|
+
() => composerRef.value?.saving || composerRef.value?.isTranslating,
|
|
12
|
+
)
|
|
10
13
|
</script>
|
|
11
14
|
|
|
12
15
|
<template>
|
|
@@ -18,6 +21,8 @@ const store = useWhatsappComposerStore()
|
|
|
18
21
|
]"
|
|
19
22
|
:active-tab="store.activeTab"
|
|
20
23
|
:test-id="templateWhatsappCreateTestIds.navbar"
|
|
24
|
+
:back="tripBack"
|
|
25
|
+
@back="composerRef?.handleCancel()"
|
|
21
26
|
@tab-change="store.activeTab = $event as 'content' | 'translations'"
|
|
22
27
|
>
|
|
23
28
|
<template #actions>
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryCache } from '@pinia/colada'
|
|
2
|
+
import {
|
|
3
|
+
AUTOMATION_CATALOG_LANGUAGES,
|
|
4
|
+
type Automation,
|
|
5
|
+
type AutomationCatalogLanguage,
|
|
6
|
+
type CreateAutomationBody,
|
|
7
|
+
} from '@dev.smartpricing/message-composer-utils/types'
|
|
8
|
+
import type { MaybeRefOrGetter } from 'vue'
|
|
9
|
+
import { toValue } from 'vue'
|
|
10
|
+
import { automationsApi, messageGroupsApi } from '~/api'
|
|
11
|
+
import type { AutomationChanges } from '~/utils/automations/form'
|
|
12
|
+
|
|
13
|
+
function isCatalogLanguage(language: string): language is AutomationCatalogLanguage {
|
|
14
|
+
return (AUTOMATION_CATALOG_LANGUAGES as readonly string[]).includes(language)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The Automations of the Effective Organization for the Host's Product. */
|
|
18
|
+
export function useAutomationsQuery() {
|
|
19
|
+
const { product } = storeToRefs(useAppContextStore())
|
|
20
|
+
const organization = useEffectiveOrganizationStore()
|
|
21
|
+
|
|
22
|
+
return useQuery({
|
|
23
|
+
key: () => ['automations', product.value ?? '', organization.organizationId],
|
|
24
|
+
query: () =>
|
|
25
|
+
automationsApi.getAll({
|
|
26
|
+
organization_id: organization.requireOrganizationId(),
|
|
27
|
+
product: product.value!,
|
|
28
|
+
}),
|
|
29
|
+
enabled: () => Boolean(product.value && organization.organizationId),
|
|
30
|
+
staleTime: 2 * 60 * 1000,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* One Automation of the Host's Product, read once for the page that edits it:
|
|
36
|
+
* nothing is kept for the next visit, and no refetch replaces what the user
|
|
37
|
+
* is editing. Its key is not under the list's, so a save does not refetch it.
|
|
38
|
+
*/
|
|
39
|
+
export function useAutomationQuery(id: MaybeRefOrGetter<string>) {
|
|
40
|
+
const { product } = storeToRefs(useAppContextStore())
|
|
41
|
+
const organization = useEffectiveOrganizationStore()
|
|
42
|
+
|
|
43
|
+
return useQuery({
|
|
44
|
+
key: () => ['automation', product.value ?? '', organization.organizationId, toValue(id)],
|
|
45
|
+
query: () => automationsApi.getById(toValue(id), { product: product.value! }),
|
|
46
|
+
enabled: () => Boolean(product.value && organization.organizationId),
|
|
47
|
+
staleTime: 0,
|
|
48
|
+
gcTime: 0,
|
|
49
|
+
refetchOnWindowFocus: false,
|
|
50
|
+
refetchOnReconnect: false,
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The Automation Catalog of the Host's Product, with its labels in the
|
|
56
|
+
* language of the interface (ADR 0017).
|
|
57
|
+
*/
|
|
58
|
+
export function useAutomationCatalogQuery() {
|
|
59
|
+
const { product } = storeToRefs(useAppContextStore())
|
|
60
|
+
const organization = useEffectiveOrganizationStore()
|
|
61
|
+
const { locale } = useI18n()
|
|
62
|
+
const language = computed(() => (isCatalogLanguage(locale.value) ? locale.value : 'en'))
|
|
63
|
+
|
|
64
|
+
return useQuery({
|
|
65
|
+
key: () => [
|
|
66
|
+
'automation-catalog',
|
|
67
|
+
product.value ?? '',
|
|
68
|
+
language.value,
|
|
69
|
+
organization.organizationId,
|
|
70
|
+
],
|
|
71
|
+
query: () =>
|
|
72
|
+
automationsApi.getCatalog({
|
|
73
|
+
organization_id: organization.requireOrganizationId(),
|
|
74
|
+
product: product.value!,
|
|
75
|
+
language: language.value,
|
|
76
|
+
}),
|
|
77
|
+
enabled: () => Boolean(product.value && organization.organizationId),
|
|
78
|
+
staleTime: 30 * 60 * 1000,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A new Automation names its Organization and its Product (ADR 0014, ADR 0019). */
|
|
83
|
+
export function useCreateAutomationMutation() {
|
|
84
|
+
const queryCache = useQueryCache()
|
|
85
|
+
const { product } = storeToRefs(useAppContextStore())
|
|
86
|
+
const organization = useEffectiveOrganizationStore()
|
|
87
|
+
|
|
88
|
+
return useMutation({
|
|
89
|
+
mutation: (automation: Omit<CreateAutomationBody, 'organization_id' | 'product'>) =>
|
|
90
|
+
automationsApi.create({
|
|
91
|
+
...automation,
|
|
92
|
+
organization_id: organization.requireOrganizationId(),
|
|
93
|
+
product: product.value!,
|
|
94
|
+
}),
|
|
95
|
+
onSuccess: () => {
|
|
96
|
+
queryCache.invalidateQueries({ key: ['automations'] })
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** An update names its Product; the Organization is the stored one (ADR 0016). */
|
|
102
|
+
export function useUpdateAutomationMutation() {
|
|
103
|
+
const queryCache = useQueryCache()
|
|
104
|
+
const { product } = storeToRefs(useAppContextStore())
|
|
105
|
+
|
|
106
|
+
return useMutation({
|
|
107
|
+
mutation: ({ id, ...changes }: AutomationChanges & { id: string }) =>
|
|
108
|
+
automationsApi.update(id, { ...changes, product: product.value! }),
|
|
109
|
+
// After a failure too: an update can be saved in part.
|
|
110
|
+
onSettled: () => {
|
|
111
|
+
queryCache.invalidateQueries({ key: ['automations'] })
|
|
112
|
+
},
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A clone names its Product; the copy stays in the source's Organization (ADR 0016). */
|
|
117
|
+
export function useCloneAutomationMutation() {
|
|
118
|
+
const queryCache = useQueryCache()
|
|
119
|
+
const { product } = storeToRefs(useAppContextStore())
|
|
120
|
+
|
|
121
|
+
return useMutation({
|
|
122
|
+
mutation: ({ id, name }: { id: string; name: string }) =>
|
|
123
|
+
automationsApi.clone(id, { name, product: product.value! }),
|
|
124
|
+
// The copy comes with Message Groups of its own. After a failure too: it
|
|
125
|
+
// can be made when the answer is lost.
|
|
126
|
+
onSettled: () => {
|
|
127
|
+
queryCache.invalidateQueries({ key: ['automations'] })
|
|
128
|
+
queryCache.invalidateQueries({ key: ['message-groups'] })
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The Message Groups the Actions of an Automation use, each once, by their
|
|
135
|
+
* current name. One that cannot be read (deleted, or of an Organization the
|
|
136
|
+
* user cannot reach) is left out: it could not be deleted either.
|
|
137
|
+
*/
|
|
138
|
+
export function useAutomationMessageGroupsQuery(automation: MaybeRefOrGetter<Automation>) {
|
|
139
|
+
const ids = computed(() => [
|
|
140
|
+
...new Set(toValue(automation).actions.map((action) => action.config.template.toLowerCase())),
|
|
141
|
+
])
|
|
142
|
+
|
|
143
|
+
return useQuery({
|
|
144
|
+
key: () => ['automation-message-groups', toValue(automation).id, ...ids.value],
|
|
145
|
+
query: async () => {
|
|
146
|
+
const results = await Promise.allSettled(
|
|
147
|
+
ids.value.map((id) => messageGroupsApi.getById(id, { skipErrorToast: true })),
|
|
148
|
+
)
|
|
149
|
+
return results.flatMap((result) =>
|
|
150
|
+
result.status === 'fulfilled' ? [{ id: result.value.id, name: result.value.name }] : [],
|
|
151
|
+
)
|
|
152
|
+
},
|
|
153
|
+
staleTime: 0,
|
|
154
|
+
gcTime: 0,
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Whether each of these Message Groups is approved in every language, by its
|
|
160
|
+
* id in lower case. One that cannot be read is left out: it is not known to
|
|
161
|
+
* be unapproved. Under `message-groups`, so a change to any of them asks again.
|
|
162
|
+
*/
|
|
163
|
+
export function useMessageGroupApprovalsQuery(messageGroupIds: MaybeRefOrGetter<string[]>) {
|
|
164
|
+
const ids = computed(() =>
|
|
165
|
+
[...new Set(toValue(messageGroupIds).map((id) => id.toLowerCase()))].filter(Boolean).sort(),
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
return useQuery({
|
|
169
|
+
key: () => ['message-groups', 'approvals', ...ids.value],
|
|
170
|
+
query: async () => {
|
|
171
|
+
const requested = ids.value
|
|
172
|
+
const results = await Promise.allSettled(
|
|
173
|
+
requested.map((id) => messageGroupsApi.getById(id, { skipErrorToast: true })),
|
|
174
|
+
)
|
|
175
|
+
return new Map(
|
|
176
|
+
results.flatMap((result, index) => {
|
|
177
|
+
if (result.status !== 'fulfilled') return []
|
|
178
|
+
const { messages } = result.value
|
|
179
|
+
const approved =
|
|
180
|
+
messages.length > 0 && messages.every((message) => message.status === 'approved')
|
|
181
|
+
return [[requested[index]!, approved] as const]
|
|
182
|
+
}),
|
|
183
|
+
)
|
|
184
|
+
},
|
|
185
|
+
enabled: () => ids.value.length > 0,
|
|
186
|
+
// The set changes with every Action added or re-pointed: what was known stays while it loads.
|
|
187
|
+
placeholderData: (previous) => previous,
|
|
188
|
+
staleTime: 2 * 60 * 1000,
|
|
189
|
+
})
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** A delete names its Product, and the Message Groups that go with the Automation (ADR 0016). */
|
|
193
|
+
export function useDeleteAutomationMutation() {
|
|
194
|
+
const queryCache = useQueryCache()
|
|
195
|
+
const { product } = storeToRefs(useAppContextStore())
|
|
196
|
+
|
|
197
|
+
return useMutation({
|
|
198
|
+
mutation: ({ id, messageGroupIds }: { id: string; messageGroupIds: string[] }) =>
|
|
199
|
+
automationsApi.delete(id, { product: product.value!, message_group_ids: messageGroupIds }),
|
|
200
|
+
// After a failure too: the Automation can be gone when the answer is lost.
|
|
201
|
+
onSettled: (_result, _error, { messageGroupIds }) => {
|
|
202
|
+
queryCache.invalidateQueries({ key: ['automations'] })
|
|
203
|
+
if (messageGroupIds.length > 0) queryCache.invalidateQueries({ key: ['message-groups'] })
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
}
|
package/app/queries/brands.ts
CHANGED
|
@@ -3,20 +3,32 @@ import type {
|
|
|
3
3
|
BrandCreateBody,
|
|
4
4
|
BrandUpdateBody,
|
|
5
5
|
} from '@dev.smartpricing/message-composer-utils/types'
|
|
6
|
-
import { brandsApi, propertiesApi } from '~/api'
|
|
6
|
+
import { brandsApi, propertiesApi, type BrandPreviewRequest } from '~/api'
|
|
7
7
|
|
|
8
8
|
// QUERIES
|
|
9
9
|
export function useBrandsQuery(options?: {
|
|
10
10
|
sort_by?: 'created_at' | 'name'
|
|
11
11
|
direction?: 'asc' | 'desc'
|
|
12
12
|
}) {
|
|
13
|
+
const organization = useEffectiveOrganizationStore()
|
|
14
|
+
|
|
13
15
|
return useQuery({
|
|
14
|
-
key: () => [
|
|
15
|
-
|
|
16
|
+
key: () => [
|
|
17
|
+
'brands',
|
|
18
|
+
options?.sort_by ?? '',
|
|
19
|
+
options?.direction ?? '',
|
|
20
|
+
organization.organizationId,
|
|
21
|
+
],
|
|
22
|
+
query: () =>
|
|
23
|
+
brandsApi.getAll({ ...options, organization_id: organization.requireOrganizationId() }),
|
|
16
24
|
staleTime: 2 * 60 * 1000,
|
|
17
25
|
})
|
|
18
26
|
}
|
|
19
27
|
|
|
28
|
+
/**
|
|
29
|
+
* A Brand by id. No Organization in the key: the request names none, it acts
|
|
30
|
+
* on the Organization of the Brand itself (ADR 0014).
|
|
31
|
+
*/
|
|
20
32
|
export function useBrandQuery(id: MaybeRefOrGetter<string>) {
|
|
21
33
|
return useQuery({
|
|
22
34
|
key: () => ['brands', toValue(id)],
|
|
@@ -27,19 +39,24 @@ export function useBrandQuery(id: MaybeRefOrGetter<string>) {
|
|
|
27
39
|
}
|
|
28
40
|
|
|
29
41
|
export function usePropertiesQuery() {
|
|
42
|
+
const organization = useEffectiveOrganizationStore()
|
|
43
|
+
|
|
30
44
|
return useQuery({
|
|
31
|
-
key: () => ['properties'],
|
|
32
|
-
query: () => propertiesApi.getAll(),
|
|
45
|
+
key: () => ['properties', organization.organizationId],
|
|
46
|
+
query: () => propertiesApi.getAll(organization.requireOrganizationId()),
|
|
33
47
|
staleTime: 10 * 60 * 1000,
|
|
34
48
|
})
|
|
35
49
|
}
|
|
36
50
|
|
|
37
51
|
// MUTATIONS
|
|
52
|
+
/** A new Brand names its Organization (ADR 0014): the Effective one. */
|
|
38
53
|
export function useCreateBrandMutation() {
|
|
39
54
|
const queryCache = useQueryCache()
|
|
55
|
+
const organization = useEffectiveOrganizationStore()
|
|
40
56
|
|
|
41
57
|
return useMutation({
|
|
42
|
-
mutation: (data: BrandCreateBody) =>
|
|
58
|
+
mutation: (data: BrandCreateBody) =>
|
|
59
|
+
brandsApi.create({ ...data, organization_id: organization.requireOrganizationId() }),
|
|
43
60
|
onSuccess: () => {
|
|
44
61
|
queryCache.invalidateQueries({ key: ['brands'] })
|
|
45
62
|
},
|
|
@@ -70,7 +87,10 @@ export function useDeleteBrandMutation() {
|
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
export function useBrandPreviewMutation() {
|
|
90
|
+
const organization = useEffectiveOrganizationStore()
|
|
91
|
+
|
|
73
92
|
return useMutation({
|
|
74
|
-
mutation:
|
|
93
|
+
mutation: (data: BrandPreviewRequest) =>
|
|
94
|
+
brandsApi.preview({ ...data, organization_id: organization.requireOrganizationId() }),
|
|
75
95
|
})
|
|
76
96
|
}
|
|
@@ -5,11 +5,18 @@ import { compilationApi } from '~/api'
|
|
|
5
5
|
import type {
|
|
6
6
|
CompileMessageRequest,
|
|
7
7
|
PreviewMessageRequest,
|
|
8
|
+
TestEmailRequest,
|
|
8
9
|
} from '@dev.smartpricing/message-composer-utils/types'
|
|
9
10
|
|
|
10
11
|
export function useSendTestEmailMutation() {
|
|
12
|
+
const organization = useEffectiveOrganizationStore()
|
|
13
|
+
|
|
11
14
|
return useMutation({
|
|
12
|
-
mutation:
|
|
15
|
+
mutation: (data: TestEmailRequest) =>
|
|
16
|
+
compilationApi.sendTestEmail({
|
|
17
|
+
...data,
|
|
18
|
+
organization_id: organization.requireOrganizationId(),
|
|
19
|
+
}),
|
|
13
20
|
})
|
|
14
21
|
}
|
|
15
22
|
|
|
@@ -37,12 +44,18 @@ export function useResolvedParametersQuery(
|
|
|
37
44
|
export function useCompileEmailMutation() {
|
|
38
45
|
return useMutation({
|
|
39
46
|
mutation: ({ messageGroupId, data }: { messageGroupId: string; data: CompileMessageRequest }) =>
|
|
40
|
-
compilationApi.
|
|
47
|
+
compilationApi.compile(messageGroupId, data),
|
|
41
48
|
})
|
|
42
49
|
}
|
|
43
50
|
|
|
44
51
|
export function usePreviewEmailMutation() {
|
|
52
|
+
const organization = useEffectiveOrganizationStore()
|
|
53
|
+
|
|
45
54
|
return useMutation({
|
|
46
|
-
mutation: (data: PreviewMessageRequest) =>
|
|
55
|
+
mutation: (data: PreviewMessageRequest) =>
|
|
56
|
+
compilationApi.previewEmail({
|
|
57
|
+
...data,
|
|
58
|
+
organization_id: organization.requireOrganizationId(),
|
|
59
|
+
}),
|
|
47
60
|
})
|
|
48
61
|
}
|
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import { useQuery } from '@pinia/colada'
|
|
2
|
+
import type { DynamicValuesResponse } from '@dev.smartpricing/message-composer-utils/types'
|
|
2
3
|
import { dynamicValuesApi } from '~/api'
|
|
3
4
|
import { useAppContextStore } from '~/stores/appContext'
|
|
4
5
|
|
|
5
6
|
export function useDynamicValuesQuery() {
|
|
6
7
|
const { product, mainLanguage } = storeToRefs(useAppContextStore())
|
|
7
8
|
|
|
9
|
+
const organization = useEffectiveOrganizationStore()
|
|
10
|
+
|
|
8
11
|
return useQuery({
|
|
9
|
-
key: () => [
|
|
10
|
-
|
|
12
|
+
key: () => [
|
|
13
|
+
'dynamic-values',
|
|
14
|
+
product.value ?? '',
|
|
15
|
+
mainLanguage.value,
|
|
16
|
+
organization.organizationId,
|
|
17
|
+
],
|
|
18
|
+
// No Product, no request: the picker stays empty and the store lists the
|
|
19
|
+
// missing Product in `validationErrors`.
|
|
20
|
+
query: () => {
|
|
21
|
+
if (!product.value) return Promise.resolve<DynamicValuesResponse>({})
|
|
22
|
+
return dynamicValuesApi.get(
|
|
23
|
+
product.value,
|
|
24
|
+
mainLanguage.value || 'en',
|
|
25
|
+
organization.requireOrganizationId(),
|
|
26
|
+
)
|
|
27
|
+
},
|
|
11
28
|
staleTime: 30 * 60 * 1000,
|
|
12
29
|
})
|
|
13
30
|
}
|
package/app/queries/index.ts
CHANGED
package/app/queries/media.ts
CHANGED
|
@@ -2,15 +2,20 @@ import { useMutation, useQuery } from '@pinia/colada'
|
|
|
2
2
|
import { mediaApi } from '~/api'
|
|
3
3
|
|
|
4
4
|
export function useMediaQuery() {
|
|
5
|
+
const organization = useEffectiveOrganizationStore()
|
|
6
|
+
|
|
5
7
|
return useQuery({
|
|
6
|
-
key: ['media'],
|
|
7
|
-
query: mediaApi.list,
|
|
8
|
+
key: () => ['media', organization.organizationId],
|
|
9
|
+
query: () => mediaApi.list(organization.requireOrganizationId()),
|
|
8
10
|
})
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
/** An uploaded image names its Organization (ADR 0014): the Effective one. */
|
|
11
14
|
export function useUploadMediaMutation() {
|
|
15
|
+
const organization = useEffectiveOrganizationStore()
|
|
16
|
+
|
|
12
17
|
return useMutation({
|
|
13
|
-
mutation: mediaApi.upload,
|
|
18
|
+
mutation: (file: File) => mediaApi.upload(file, organization.requireOrganizationId()),
|
|
14
19
|
})
|
|
15
20
|
}
|
|
16
21
|
|