@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.
Files changed (112) hide show
  1. package/README.md +182 -7
  2. package/app/api/automations.ts +74 -0
  3. package/app/api/brands.ts +20 -13
  4. package/app/api/client.ts +3 -6
  5. package/app/api/dynamicValues.ts +2 -1
  6. package/app/api/index.ts +1 -0
  7. package/app/api/media.ts +6 -3
  8. package/app/api/messageGroups.ts +11 -3
  9. package/app/api/meta.ts +62 -4
  10. package/app/api/organization.ts +10 -1
  11. package/app/api/tracking.ts +2 -2
  12. package/app/app.config.ts +10 -0
  13. package/app/components/Automations/ActionCard.vue +174 -0
  14. package/app/components/Automations/ActionEditor.vue +398 -0
  15. package/app/components/Automations/Actions.vue +158 -0
  16. package/app/components/Automations/CloneModal.vue +78 -0
  17. package/app/components/Automations/Conditions.vue +155 -0
  18. package/app/components/Automations/Create.vue +114 -0
  19. package/app/components/Automations/Data.vue +46 -0
  20. package/app/components/Automations/DeleteModal.vue +80 -0
  21. package/app/components/Automations/Edit.vue +145 -0
  22. package/app/components/Automations/Form.vue +282 -0
  23. package/app/components/Automations/List.vue +370 -0
  24. package/app/components/Automations/PageGate.vue +50 -0
  25. package/app/components/Automations/SaveProblems.vue +54 -0
  26. package/app/components/Automations/Unavailable.vue +71 -0
  27. package/app/components/Automations/UnavailableBadge.vue +35 -0
  28. package/app/components/Common/AppContextErrors.vue +2 -2
  29. package/app/components/Common/MessageGroupSelect.vue +43 -3
  30. package/app/components/Common/OrganizationGate.vue +51 -0
  31. package/app/components/Common/OrganizationSelect.vue +27 -0
  32. package/app/components/Common/WhatsappNotConfigured.vue +20 -0
  33. package/app/components/Composer/EmailComposer.vue +9 -1
  34. package/app/components/Composer/MessageLibrary.vue +8 -0
  35. package/app/components/Composer/WabaSelectModal.vue +73 -0
  36. package/app/components/Composer/WhatsappComposer.vue +83 -4
  37. package/app/components/Editor/RichTextEditor.vue +14 -2
  38. package/app/components/Filters/DateInput.vue +57 -0
  39. package/app/components/Filters/Editor.vue +163 -0
  40. package/app/components/Filters/Row.vue +119 -0
  41. package/app/components/Filters/Summary.vue +215 -0
  42. package/app/components/Filters/UnavailableRow.vue +74 -0
  43. package/app/components/Filters/ValueInput.vue +215 -0
  44. package/app/components/Layout/BasePage.vue +2 -0
  45. package/app/components/MessageSendFlow/EmailPreview.vue +3 -0
  46. package/app/components/MessageSendFlow/MessageSendFlow.vue +15 -2
  47. package/app/components/MetaImport/Button.vue +50 -0
  48. package/app/components/MetaImport/Dialog.vue +261 -0
  49. package/app/components/MetaImport/Outcome.vue +136 -0
  50. package/app/components/MetaImport/ProposalList.vue +192 -0
  51. package/app/components/TemplateList/BaseTable.vue +22 -1
  52. package/app/components/Whatsapp/Preview.vue +5 -12
  53. package/app/components/Whatsapp/Translator/Header.vue +4 -19
  54. package/app/composables/apiErrorMessages.ts +1 -0
  55. package/app/composables/automationsContext.ts +42 -0
  56. package/app/composables/composerContext.ts +5 -5
  57. package/app/composables/useAutomationClone.ts +33 -0
  58. package/app/composables/useAutomationEditorTrip.ts +77 -0
  59. package/app/composables/useAutomationSaveProblems.ts +82 -0
  60. package/app/composables/useAutomationUnavailable.ts +98 -0
  61. package/app/composables/useAutomationsGate.ts +68 -0
  62. package/app/composables/useBuiltInOptionLists.ts +44 -0
  63. package/app/composables/useEditorTripBack.ts +15 -0
  64. package/app/composables/useEffectiveOrganization.ts +34 -0
  65. package/app/composables/useMessageGroupWaba.ts +76 -0
  66. package/app/composables/useMessageSendFlow.ts +46 -8
  67. package/app/composables/usePagedMessageGroups.ts +14 -2
  68. package/app/composables/useTemplateOperations.ts +18 -4
  69. package/app/composables/useTracking.ts +14 -5
  70. package/app/composables/useWhatsappConfiguration.ts +32 -0
  71. package/app/layouts/default.vue +4 -1
  72. package/app/middleware/automations-enabled.ts +12 -0
  73. package/app/pages/automations/[id].vue +87 -0
  74. package/app/pages/automations/index.vue +28 -0
  75. package/app/pages/automations/new.vue +53 -0
  76. package/app/pages/brands.vue +1 -0
  77. package/app/pages/images.vue +4 -0
  78. package/app/pages/index.vue +6 -1
  79. package/app/pages/preview/[id].vue +2 -0
  80. package/app/pages/template/email/[id].vue +5 -0
  81. package/app/pages/template/email/create.vue +5 -0
  82. package/app/pages/template/whatsapp/[id].vue +6 -0
  83. package/app/pages/template/whatsapp/create.vue +5 -0
  84. package/app/queries/automations.ts +206 -0
  85. package/app/queries/brands.ts +27 -7
  86. package/app/queries/compilation.ts +15 -2
  87. package/app/queries/dynamicValues.ts +13 -2
  88. package/app/queries/index.ts +1 -0
  89. package/app/queries/media.ts +8 -3
  90. package/app/queries/messageGroups.ts +60 -25
  91. package/app/queries/meta.ts +100 -5
  92. package/app/stores/appContext.ts +9 -45
  93. package/app/stores/editorTrip.ts +67 -0
  94. package/app/stores/effectiveOrganization.ts +128 -0
  95. package/app/stores/emailEditor.ts +5 -1
  96. package/app/stores/metaSubmission.ts +7 -17
  97. package/app/types/app-config.d.ts +3 -0
  98. package/app/types/tracking.ts +33 -0
  99. package/app/utils/automations/form.ts +389 -0
  100. package/app/utils/automations/metadata.ts +71 -0
  101. package/app/utils/automations/unavailable.ts +90 -0
  102. package/app/utils/filters/data/countries.json +998 -0
  103. package/app/utils/filters/data/languages.json +754 -0
  104. package/app/utils/filters/rows.ts +367 -0
  105. package/app/utils/testIds.const.ts +108 -0
  106. package/i18n/locales/de.ts +363 -0
  107. package/i18n/locales/en.ts +345 -0
  108. package/i18n/locales/es.ts +349 -0
  109. package/i18n/locales/fr.ts +357 -0
  110. package/i18n/locales/it.ts +354 -0
  111. package/package.json +4 -4
  112. package/app.config.ts +0 -5
@@ -0,0 +1,158 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ AutomationChannel,
4
+ AutomationTrigger,
5
+ } from '@dev.smartpricing/message-composer-utils/types'
6
+ import type {
7
+ AutomationMessageRequest,
8
+ OpenAutomationAction,
9
+ } from '~/composables/useAutomationEditorTrip'
10
+ import { automationActionElementId } from '~/composables/useAutomationUnavailable'
11
+ import { newAutomationFormAction, type AutomationFormAction } from '../../utils/automations/form'
12
+ import type { AutomationUnavailableItem } from '../../utils/automations/unavailable'
13
+
14
+ /** The Actions of an Automation: their cards, "add", and the editor of one. */
15
+ const props = defineProps<{
16
+ trigger: AutomationTrigger
17
+ /** The Channels an Action can be on here. */
18
+ channels: AutomationChannel[]
19
+ /** The Channels the Organization cannot use: an Action on one is kept, and not sent. */
20
+ unusableChannels: AutomationChannel[]
21
+ /** What each Action holds that is no longer available, by the Action's key. */
22
+ unavailable: Map<string, AutomationUnavailableItem[]>
23
+ /** The keys of the Actions a refused save pointed at. */
24
+ invalidKeys?: string[]
25
+ /** The form was submitted: having no Action shows as an error. */
26
+ submitted?: boolean
27
+ /** The Action the editor starts open on: the one an editor trip left from. */
28
+ openAction?: OpenAutomationAction
29
+ /** No Action is added, edited or removed: only the Active switch works. */
30
+ readOnly?: boolean
31
+ }>()
32
+
33
+ const emit = defineEmits<{
34
+ /** The user leaves for the Message editor from the Action in the editor. */
35
+ editMessage: [request: AutomationMessageRequest]
36
+ }>()
37
+
38
+ const actions = defineModel<AutomationFormAction[]>({ required: true })
39
+
40
+ const { t } = useI18n()
41
+ const { trackEvent } = useTracking()
42
+ const { confirm } = useConfirm()
43
+
44
+ /** The Action in the editor: a copy of one of the form's, or one not added yet. */
45
+ const editing = ref<AutomationFormAction | undefined>(props.openAction?.action)
46
+ const editingIsNew = ref(props.openAction?.isNew ?? false)
47
+
48
+ function add() {
49
+ const [channel] = props.channels
50
+ if (!channel) return
51
+ editingIsNew.value = true
52
+ editing.value = newAutomationFormAction(props.trigger, channel)
53
+ }
54
+
55
+ function saveEdited(edited: AutomationFormAction) {
56
+ const index = actions.value.findIndex((action) => action.key === edited.key)
57
+ if (index === -1) {
58
+ actions.value = [...actions.value, edited]
59
+ trackEvent('automation.action_added', { channel: edited.channel })
60
+ } else {
61
+ actions.value = actions.value.with(index, edited)
62
+ }
63
+ editing.value = undefined
64
+ }
65
+
66
+ function toggle(action: AutomationFormAction, active: boolean) {
67
+ const status = active ? 'active' : 'inactive'
68
+ trackEvent('automation.action_toggled', { channel: action.channel, new_status: status })
69
+ actions.value = actions.value.map((current) =>
70
+ current.key === action.key ? { ...current, status } : current,
71
+ )
72
+ }
73
+
74
+ function edit(action: AutomationFormAction) {
75
+ editingIsNew.value = false
76
+ editing.value = action
77
+ }
78
+
79
+ async function remove(action: AutomationFormAction) {
80
+ const confirmed = await confirm({
81
+ title: t('automations.form.actions.deleteConfirm'),
82
+ message: t('automations.form.actions.deleteConfirmDescription'),
83
+ modalProps: {
84
+ close: { 'data-testid': automationsTestIds.deleteModalCloseButton },
85
+ content: dialogTestId(automationsTestIds.deleteModal),
86
+ },
87
+ confirmProps: {
88
+ label: t('common.actions.delete'),
89
+ 'data-testid': automationsTestIds.deleteModalConfirm,
90
+ },
91
+ cancelProps: {
92
+ label: t('common.actions.cancel'),
93
+ 'data-testid': automationsTestIds.deleteModalCancel,
94
+ },
95
+ destructive: true,
96
+ })
97
+ if (!confirmed) return
98
+
99
+ trackEvent('automation.action_deleted', { channel: action.channel })
100
+ actions.value = actions.value.filter((current) => current.key !== action.key)
101
+ }
102
+ </script>
103
+
104
+ <template>
105
+ <UFormField
106
+ :label="t('automations.form.messages')"
107
+ :error="submitted && actions.length === 0 ? t('automations.form.required') : undefined"
108
+ >
109
+ <div class="space-y-4">
110
+ <p
111
+ v-if="actions.length === 0"
112
+ class="paragraph-sm text-muted"
113
+ :data-testid="automationsTestIds.actionsEmpty"
114
+ >
115
+ {{ t('automations.form.actions.empty') }}
116
+ </p>
117
+
118
+ <div v-else class="space-y-3">
119
+ <AutomationsActionCard
120
+ v-for="action in actions"
121
+ :id="automationActionElementId(action.key)"
122
+ :key="action.key"
123
+ :action="action"
124
+ :trigger="trigger"
125
+ :unavailable="unavailable.get(action.key) ?? []"
126
+ :invalid="invalidKeys?.includes(action.key)"
127
+ :read-only="readOnly"
128
+ :data-testid="`${automationsTestIds.actionCard}-${action.key}`"
129
+ :data-testvalue="action.key"
130
+ @edit="edit(action)"
131
+ @remove="remove(action)"
132
+ @toggle="toggle(action, $event)"
133
+ />
134
+ </div>
135
+
136
+ <UButton
137
+ v-if="!readOnly"
138
+ color="primary"
139
+ variant="outline"
140
+ :label="t('automations.actions.addChannel')"
141
+ :disabled="channels.length === 0"
142
+ :data-testid="automationsTestIds.addChannelButton"
143
+ @click="add"
144
+ />
145
+ </div>
146
+
147
+ <AutomationsActionEditor
148
+ :action="editing"
149
+ :is-new="editingIsNew"
150
+ :trigger="trigger"
151
+ :channels="channels"
152
+ :unusable-channels="unusableChannels"
153
+ @save="saveEdited"
154
+ @close="editing = undefined"
155
+ @edit-message="emit('editMessage', { ...$event, isNew: editingIsNew })"
156
+ />
157
+ </UFormField>
158
+ </template>
@@ -0,0 +1,78 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Asks the name of the copy before an Automation is duplicated. Opened
4
+ * through `useOverlay`; `action` makes the copy while the modal shows it
5
+ * running, and the modal closes once it is made.
6
+ */
7
+ const props = defineProps<{
8
+ defaultName: string
9
+ action: (name: string) => Promise<void>
10
+ }>()
11
+
12
+ const emit = defineEmits<{ close: [] }>()
13
+
14
+ const { t } = useI18n()
15
+
16
+ const name = ref(props.defaultName)
17
+ const trimmedName = computed(() => name.value.trim())
18
+ const cloning = ref(false)
19
+
20
+ async function confirmClone() {
21
+ if (!trimmedName.value || cloning.value) return
22
+
23
+ cloning.value = true
24
+ try {
25
+ await props.action(trimmedName.value)
26
+ emit('close')
27
+ } catch {
28
+ // Already said by the request's own error toast; the modal stays open
29
+ // with the name, for another try.
30
+ } finally {
31
+ cloning.value = false
32
+ }
33
+ }
34
+ </script>
35
+
36
+ <template>
37
+ <UModal
38
+ :title="t('automations.clone.title')"
39
+ close-icon="ph:x"
40
+ :close="{ disabled: cloning, onClick: () => emit('close') }"
41
+ :dismissible="false"
42
+ :content="dialogTestId(automationsTestIds.cloneModal)"
43
+ >
44
+ <template #body>
45
+ <UFormField :label="t('automations.form.name')">
46
+ <UInput
47
+ v-model="name"
48
+ :placeholder="t('automations.clone.namePlaceholder')"
49
+ :disabled="cloning"
50
+ autofocus
51
+ class="w-full"
52
+ :data-testid="automationsTestIds.cloneModalNameInput"
53
+ @keyup.enter="confirmClone"
54
+ />
55
+ </UFormField>
56
+ </template>
57
+
58
+ <template #footer>
59
+ <div class="flex gap-2 justify-end w-full">
60
+ <UButton
61
+ variant="outline"
62
+ color="neutral"
63
+ :label="t('common.actions.cancel')"
64
+ :disabled="cloning"
65
+ :data-testid="automationsTestIds.cloneModalCancel"
66
+ @click="emit('close')"
67
+ />
68
+ <UButton
69
+ :label="t('common.actions.duplicate')"
70
+ :loading="cloning"
71
+ :disabled="!trimmedName"
72
+ :data-testid="automationsTestIds.cloneModalConfirm"
73
+ @click="confirmClone"
74
+ />
75
+ </div>
76
+ </template>
77
+ </UModal>
78
+ </template>
@@ -0,0 +1,155 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ AutomationTrigger,
4
+ Condition,
5
+ FilterField,
6
+ FiltersReport,
7
+ } from '@dev.smartpricing/message-composer-utils/types'
8
+ import type { AutomationOption } from '~/composables/automationsContext'
9
+ import { cloneFormData } from '../../utils/automations/form'
10
+
11
+ /**
12
+ * The Conditions of an Automation: shown with `FiltersSummary`, edited with
13
+ * `FiltersEditor` in a slideover that changes nothing until its Save
14
+ * (ADR 0018). The fields are the Trigger's Condition Fields, each with the
15
+ * option list the Host supplies under the name the field declares (ADR 0017).
16
+ */
17
+ const props = defineProps<{
18
+ trigger: AutomationTrigger
19
+ /** The Host's option lists, by name. One that is not there shows as empty. */
20
+ optionLists: Record<string, AutomationOption[]>
21
+ /** ISO code of the currency `price` fields show; EUR when absent. */
22
+ currency?: string
23
+ /** The Conditions are only shown: there is no way into the filter editor. */
24
+ readOnly?: boolean
25
+ }>()
26
+
27
+ const conditions = defineModel<Condition[]>({ required: true })
28
+ /** Whether the filter editor is open. */
29
+ const open = defineModel<boolean>('open', { default: false })
30
+
31
+ const emit = defineEmits<{
32
+ /** What is wrong with the Conditions as they stand; `undefined` when there is none. */
33
+ report: [report: FiltersReport | undefined]
34
+ }>()
35
+
36
+ const { t } = useI18n()
37
+ const unavailable = useAutomationUnavailable()
38
+
39
+ const fields = computed<FilterField[]>(() =>
40
+ props.trigger.condition_fields.map(({ key, label, type, option_list }) => ({
41
+ key,
42
+ label,
43
+ type,
44
+ options: option_list ? (props.optionLists[option_list] ?? []) : undefined,
45
+ })),
46
+ )
47
+
48
+ // On screen a Condition is a "filter", and a "between" is one of them.
49
+ const filterCount = computed(() => new Set(conditions.value.map(({ field }) => field)).size)
50
+
51
+ // `FiltersSummary` is not there without Conditions, and then reports nothing.
52
+ watch(
53
+ () => conditions.value.length,
54
+ (count) => {
55
+ if (count === 0) emit('report', undefined)
56
+ },
57
+ )
58
+
59
+ /** What the slideover edits: the Conditions change only on its Save. */
60
+ const edited = ref<Condition[]>([])
61
+ const report = ref<FiltersReport>()
62
+
63
+ /** The alert of the slideover: what is unavailable in the Conditions being edited. */
64
+ const editedUnavailable = computed(() => unavailable.conditionItems(report.value, fields.value))
65
+
66
+ watch(open, (isOpen) => {
67
+ if (isOpen) edited.value = cloneFormData(conditions.value)
68
+ })
69
+
70
+ function save() {
71
+ conditions.value = edited.value
72
+ open.value = false
73
+ }
74
+ </script>
75
+
76
+ <template>
77
+ <UFormField
78
+ :label="t('automations.form.sendTotitle')"
79
+ :description="t('automations.form.sendToHint')"
80
+ >
81
+ <div class="flex items-center gap-1" :data-testid="automationsTestIds.sendToSummary">
82
+ <p class="paragraph-sm text-primary-800">
83
+ {{
84
+ filterCount > 0
85
+ ? t('filters.applied', { count: filterCount })
86
+ : t('automations.form.sendTo_all')
87
+ }}
88
+ </p>
89
+
90
+ <USlideover
91
+ v-if="!readOnly"
92
+ v-model:open="open"
93
+ close-icon="ph:x"
94
+ :close="{ 'data-testid': automationsTestIds.filtersSlideoverCloseButton }"
95
+ :title="t('automations.form.create_specific_audience')"
96
+ :description="t('automations.form.create_specific_audience_hint')"
97
+ :ui="{ content: 'max-w-4xl', footer: 'justify-end' }"
98
+ :content="dialogTestId(automationsTestIds.filtersSlideover)"
99
+ >
100
+ <UButton
101
+ color="secondary"
102
+ variant="ghost"
103
+ size="sm"
104
+ :icon="filterCount > 0 ? 'ph:pencil-simple-line-bold' : 'ph:plus-bold'"
105
+ :label="filterCount > 0 ? t('common.actions.edit') : t('automations.form.addFilters')"
106
+ :data-testid="
107
+ filterCount > 0
108
+ ? automationsTestIds.editFiltersButton
109
+ : automationsTestIds.addFiltersButton
110
+ "
111
+ />
112
+
113
+ <template #body>
114
+ <AutomationsUnavailable :items="editedUnavailable" in-place class="mb-4" />
115
+ <FiltersEditor
116
+ v-model="edited"
117
+ :fields="fields"
118
+ :currency="currency"
119
+ :title="t('automations.form.includeIf')"
120
+ test-id-prefix="audience"
121
+ @report="report = $event"
122
+ />
123
+ </template>
124
+
125
+ <template #footer>
126
+ <UButton
127
+ color="primary"
128
+ variant="outline"
129
+ :label="t('common.actions.cancel')"
130
+ :data-testid="automationsTestIds.filtersSlideoverCancel"
131
+ @click="open = false"
132
+ />
133
+ <!-- A half-filled row is in no Condition: saving would drop it without a word. -->
134
+ <UButton
135
+ color="primary"
136
+ :label="t('common.actions.save')"
137
+ :disabled="Boolean(report?.halfFilled)"
138
+ :data-testid="automationsTestIds.filtersSlideoverSave"
139
+ @click="save"
140
+ />
141
+ </template>
142
+ </USlideover>
143
+ </div>
144
+
145
+ <FiltersSummary
146
+ v-if="conditions.length > 0"
147
+ :model-value="conditions"
148
+ :fields="fields"
149
+ :currency="currency"
150
+ test-id-prefix="audience"
151
+ class="mt-3"
152
+ @report="emit('report', $event)"
153
+ />
154
+ </UFormField>
155
+ </template>
@@ -0,0 +1,114 @@
1
+ <script setup lang="ts">
2
+ import type {
3
+ AutomationCatalog,
4
+ AutomationTrigger,
5
+ } from '@dev.smartpricing/message-composer-utils/types'
6
+ import { resolveErrorToast } from '~/composables/apiErrorMessages'
7
+ import type { AutomationsContext } from '~/composables/automationsContext'
8
+ import { useCreateAutomationMutation } from '~/queries'
9
+ import {
10
+ automationEngineRejected,
11
+ automationSaveProblems,
12
+ automationSetupProperties,
13
+ cloneFormData,
14
+ newAutomationForm,
15
+ toCreateAutomationBody,
16
+ type AutomationFormState,
17
+ } from '../../utils/automations/form'
18
+
19
+ /**
20
+ * A new Automation: the form, its save, and what a refused save says. The
21
+ * page around it holds the header and calls `submit`.
22
+ */
23
+ const props = defineProps<{
24
+ catalog: AutomationCatalog
25
+ /** The Trigger a new Automation starts on. */
26
+ initialTrigger: AutomationTrigger
27
+ context: AutomationsContext
28
+ }>()
29
+
30
+ const { t } = useI18n()
31
+ const toast = useToast()
32
+ const { trackEvent } = useTracking()
33
+
34
+ const trip = useAutomationEditorTrip('automation-create')
35
+
36
+ const form = ref<AutomationFormState>(
37
+ trip.restored?.form ?? newAutomationForm(props.initialTrigger),
38
+ )
39
+ const submitted = ref(false)
40
+ const formElement = useTemplateRef('formElement')
41
+
42
+ const incomplete = computed(() => !form.value.name.trim() || form.value.actions.length === 0)
43
+
44
+ const problems = useAutomationSaveProblems(() => props.catalog)
45
+
46
+ const { mutateAsync: createAutomation, isLoading: saving } = useCreateAutomationMutation()
47
+
48
+ async function submit() {
49
+ submitted.value = true
50
+ problems.clear()
51
+ // Something unavailable stops the save: nothing is sent, the alert says what to fix.
52
+ if (formElement.value?.blocked) {
53
+ formElement.value.showUnavailable()
54
+ return
55
+ }
56
+ if (incomplete.value || saving.value) return
57
+
58
+ const sent = cloneFormData(form.value)
59
+ let created
60
+ try {
61
+ created = await createAutomation(toCreateAutomationBody(sent))
62
+ } catch (error) {
63
+ const refused = automationSaveProblems(error)
64
+ const rejected = automationEngineRejected(error)
65
+ if (refused) {
66
+ problems.show(refused, sent)
67
+ } else if (rejected !== undefined) {
68
+ toast.add({
69
+ title: t('automations.toast.engine_rejected'),
70
+ description: rejected,
71
+ color: 'error',
72
+ })
73
+ } else {
74
+ // The request carries no error toast of its own, so a 422 gets none.
75
+ const { data, status = 0 } = error as { data?: { code?: string }; status?: number }
76
+ toast.add({ ...resolveErrorToast({ status, code: data?.code }, t), color: 'error' })
77
+ }
78
+ return
79
+ }
80
+
81
+ trackEvent(
82
+ 'Automation setup',
83
+ automationSetupProperties(
84
+ sent,
85
+ props.catalog.triggers.find(({ type }) => type === sent.triggerType),
86
+ ),
87
+ )
88
+ toast.add({ title: t('automations.toast.created'), color: 'success' })
89
+ // A body that is not an Automation (ADR 0016) has no Automation to open.
90
+ await navigateTo(
91
+ created?.id
92
+ ? { name: 'automation-edit', params: { id: created.id } }
93
+ : { name: 'automations-list' },
94
+ { replace: true },
95
+ )
96
+ }
97
+
98
+ defineExpose({ submit, saving })
99
+ </script>
100
+
101
+ <template>
102
+ <AutomationsSaveProblems :lines="problems.lines.value" :incomplete="submitted && incomplete" />
103
+
104
+ <AutomationsForm
105
+ ref="formElement"
106
+ v-model="form"
107
+ :catalog="catalog"
108
+ :context="context"
109
+ :submitted="submitted"
110
+ :invalid-action-keys="problems.invalidActionKeys.value"
111
+ :open-action="trip.restored?.openAction"
112
+ @edit-message="trip.leave({ form }, $event)"
113
+ />
114
+ </template>
@@ -0,0 +1,46 @@
1
+ <script setup lang="ts">
2
+ import type { AutomationMetadataForm } from '../../utils/automations/metadata'
3
+
4
+ /**
5
+ * The values an Automation asks its user for: one text field per field of
6
+ * its stored `metadata.form`, whatever the Automation. Description and labels
7
+ * are its Host's words, not the layer's: one that is a key of the Host's own
8
+ * translations is shown translated, any other as stored.
9
+ */
10
+ defineProps<{ form: AutomationMetadataForm }>()
11
+
12
+ /** The values, by the key of their field. */
13
+ const data = defineModel<Record<string, string>>({ required: true })
14
+
15
+ const { t, te } = useI18n()
16
+
17
+ /** Smartconnect seeds its labels as keys of its own locale files. */
18
+ function hostText(stored: string): string {
19
+ return te(stored) ? t(stored) : stored
20
+ }
21
+ </script>
22
+
23
+ <template>
24
+ <div class="space-y-3">
25
+ <div class="flex items-center gap-2">
26
+ <h3 class="heading-sm">{{ t('automations.form.data.title') }}</h3>
27
+ <UBadge
28
+ v-if="form.fields.some((field) => field.required)"
29
+ :label="t('automations.form.data.requiredBadge')"
30
+ color="info"
31
+ variant="subtle"
32
+ />
33
+ </div>
34
+
35
+ <p v-if="form.description" class="paragraph-sm text-muted">{{ hostText(form.description) }}</p>
36
+
37
+ <UFormField
38
+ v-for="field in form.fields"
39
+ :key="field.key"
40
+ :label="hostText(field.label)"
41
+ :required="field.required"
42
+ >
43
+ <UInput v-model="data[field.key]" class="w-full" />
44
+ </UFormField>
45
+ </div>
46
+ </template>
@@ -0,0 +1,80 @@
1
+ <script setup lang="ts">
2
+ import type { Automation } from '@dev.smartpricing/message-composer-utils/types'
3
+ import { useAutomationMessageGroupsQuery } from '~/queries'
4
+
5
+ /**
6
+ * Asks before an Automation is deleted, and which of its Message Groups go
7
+ * with it: none unless the user checks it (ADR 0016). Opened through
8
+ * `useOverlay`; `action` does the delete while the modal shows it running.
9
+ */
10
+ const props = defineProps<{
11
+ automation: Automation
12
+ action: (messageGroupIds: string[]) => Promise<void>
13
+ }>()
14
+
15
+ const { t } = useI18n()
16
+
17
+ const { data: messageGroups, isPending } = useAutomationMessageGroupsQuery(() => props.automation)
18
+
19
+ const items = computed(() =>
20
+ (messageGroups.value ?? []).map(({ id, name }) => ({ value: id, label: name })),
21
+ )
22
+ const selected = ref<string[]>([])
23
+ const deleting = ref(false)
24
+
25
+ async function confirmDelete() {
26
+ deleting.value = true
27
+ try {
28
+ await props.action(selected.value)
29
+ } catch {
30
+ // Already said by the request's own error toast; the modal closes.
31
+ } finally {
32
+ deleting.value = false
33
+ }
34
+ }
35
+ </script>
36
+
37
+ <template>
38
+ <SConfirmModal
39
+ :modal-props="{
40
+ title: t('automations.delete.title'),
41
+ close: { 'data-testid': automationsTestIds.deleteModalCloseButton },
42
+ content: dialogTestId(automationsTestIds.deleteModal),
43
+ }"
44
+ :confirm-props="{
45
+ label: t('common.actions.delete'),
46
+ disabled: isPending,
47
+ 'data-testid': automationsTestIds.deleteModalConfirm,
48
+ }"
49
+ :cancel-props="{
50
+ label: t('common.actions.cancel'),
51
+ 'data-testid': automationsTestIds.deleteModalCancel,
52
+ }"
53
+ :loading="deleting"
54
+ :action="confirmDelete"
55
+ destructive
56
+ >
57
+ <template #body>
58
+ <div class="space-y-4">
59
+ <p class="my-0 text-muted">{{ t('automations.delete.confirm') }}</p>
60
+
61
+ <!-- No delete before the choice is on screen: it would skip it. -->
62
+ <USkeleton v-if="isPending" class="h-12 w-full" />
63
+
64
+ <template v-else-if="items.length > 0">
65
+ <UCheckboxGroup
66
+ v-model="selected"
67
+ :items="items"
68
+ :legend="t('automations.delete.messages')"
69
+ :disabled="deleting"
70
+ :data-testid="automationsTestIds.deleteModalMessages"
71
+ />
72
+ <p class="my-0 flex items-start gap-1.5 paragraph-sm text-warning">
73
+ <UIcon name="ph:warning" class="mt-0.5 shrink-0" />
74
+ {{ t('automations.delete.warning') }}
75
+ </p>
76
+ </template>
77
+ </div>
78
+ </template>
79
+ </SConfirmModal>
80
+ </template>