@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
package/app/api/compilation.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
GetResolvedParametersResponse,
|
|
6
6
|
CompileMessageRequest,
|
|
7
7
|
CompileEmailResponse,
|
|
8
|
+
CompileMessageResponse,
|
|
8
9
|
PreviewMessageRequest,
|
|
9
10
|
} from '@dev.smartpricing/message-composer-utils/types'
|
|
10
11
|
import { apiClient } from './client'
|
|
@@ -26,11 +27,20 @@ export const compilationApi = {
|
|
|
26
27
|
`/message-groups/${messageGroupId}/parameters/resolved?language=${language}`,
|
|
27
28
|
),
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* WhatsApp responses carry `message`, the Sendable Message (docs/compile-and-send.md).
|
|
32
|
+
* `skipErrorToast` lets a caller with its own inline error surface silence the global toast.
|
|
33
|
+
*/
|
|
34
|
+
compile: (
|
|
35
|
+
messageGroupId: string,
|
|
36
|
+
data: CompileMessageRequest,
|
|
37
|
+
options: { skipErrorToast?: boolean } = {},
|
|
38
|
+
) =>
|
|
39
|
+
apiClient<CompileMessageResponse>(`/message-groups/${messageGroupId}/compile`, {
|
|
31
40
|
method: 'POST',
|
|
32
41
|
body: data,
|
|
33
|
-
|
|
42
|
+
_skipErrorToast: options.skipErrorToast,
|
|
43
|
+
} as Record<string, unknown>),
|
|
34
44
|
|
|
35
45
|
previewEmail: (data: PreviewMessageRequest) =>
|
|
36
46
|
apiClient<CompileEmailResponse>('/message-groups/preview', {
|
package/app/api/dynamicValues.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
DynamicValuesResponse,
|
|
3
|
+
MessageGroupProduct,
|
|
4
|
+
} from '@dev.smartpricing/message-composer-utils/types'
|
|
2
5
|
import { apiClient } from './client'
|
|
3
6
|
|
|
4
7
|
export const dynamicValuesApi = {
|
|
5
|
-
get: (product:
|
|
8
|
+
get: (product: MessageGroupProduct, language: string, organizationId: string) => {
|
|
6
9
|
const params = new URLSearchParams()
|
|
7
10
|
params.set('product', product)
|
|
8
11
|
params.set('language', language)
|
|
12
|
+
params.set('organization_id', organizationId)
|
|
9
13
|
return apiClient<DynamicValuesResponse>(`/dynamic-values?${params.toString()}`)
|
|
10
14
|
},
|
|
11
15
|
}
|
package/app/api/index.ts
CHANGED
package/app/api/media.ts
CHANGED
|
@@ -2,12 +2,15 @@ import type { MediaFromDb } from '@dev.smartpricing/message-composer-utils/types
|
|
|
2
2
|
import { apiClient } from './client'
|
|
3
3
|
|
|
4
4
|
export const mediaApi = {
|
|
5
|
-
list: () =>
|
|
5
|
+
list: (organizationId: string) =>
|
|
6
|
+
apiClient<MediaFromDb[]>(`/media?${new URLSearchParams({ organization_id: organizationId })}`),
|
|
6
7
|
|
|
7
|
-
upload: (file: File) => {
|
|
8
|
+
upload: (file: File, organizationId: string) => {
|
|
8
9
|
const formData = new FormData()
|
|
9
|
-
|
|
10
|
+
// Before the file: the backend reads only the fields that precede it.
|
|
11
|
+
formData.append('organization_id', organizationId)
|
|
10
12
|
formData.append('fileName', file.name)
|
|
13
|
+
formData.append('file', file)
|
|
11
14
|
return apiClient<MediaFromDb>('/media/upload', {
|
|
12
15
|
method: 'POST',
|
|
13
16
|
body: formData,
|
package/app/api/messageGroups.ts
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
MessageGroupFromDb,
|
|
3
|
+
PaginatedResponse,
|
|
3
4
|
MessageGroupWithMessages,
|
|
4
5
|
MessageGroupWithMessageSummary,
|
|
5
6
|
MessageGroupValidationResponse,
|
|
6
7
|
PostEntity,
|
|
7
8
|
MessageGroup,
|
|
8
|
-
RenderType,
|
|
9
9
|
DuplicateMessageGroupBody,
|
|
10
|
+
ListMessageGroupsQuery,
|
|
10
11
|
} from '@dev.smartpricing/message-composer-utils/types'
|
|
11
12
|
import { apiClient } from './client'
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Query params of `GET /message-groups`, straight from the shared schema
|
|
16
|
+
* (ADR 0007): snake_case, as on the wire. `visibility` other than `public`
|
|
17
|
+
* is admin-only (403 otherwise); every field is optional here, the server
|
|
18
|
+
* applies the defaults.
|
|
19
|
+
*/
|
|
20
|
+
export type ListMessageGroupsOptions = Partial<ListMessageGroupsQuery>
|
|
21
|
+
|
|
22
|
+
function listQueryString(options: ListMessageGroupsOptions = {}): string {
|
|
23
|
+
const params = new URLSearchParams()
|
|
24
|
+
for (const [name, value] of Object.entries(options)) {
|
|
25
|
+
if (value !== undefined && value !== '') params.set(name, String(value))
|
|
26
|
+
}
|
|
27
|
+
return params.size ? `?${params.toString()}` : ''
|
|
28
|
+
}
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
export const messageGroupsApi = {
|
|
31
|
+
/** One page of the server-side filtered list, in the Laravel envelope (ADR 0012). */
|
|
32
|
+
list: (options?: ListMessageGroupsOptions) =>
|
|
33
|
+
apiClient<PaginatedResponse<MessageGroupWithMessageSummary>>(
|
|
34
|
+
`/message-groups${listQueryString(options)}`,
|
|
35
|
+
),
|
|
25
36
|
|
|
26
|
-
|
|
37
|
+
/** `skipErrorToast` for a caller that expects some not to be found. */
|
|
38
|
+
getById: (id: string, options: { skipErrorToast?: boolean } = {}) =>
|
|
39
|
+
apiClient<MessageGroupWithMessages>(`/message-groups/${id}`, {
|
|
40
|
+
_skipErrorToast: options.skipErrorToast,
|
|
41
|
+
} as Record<string, unknown>),
|
|
27
42
|
|
|
28
43
|
create: (data: PostEntity<MessageGroup>) =>
|
|
29
44
|
apiClient<MessageGroupFromDb>('/message-groups', {
|
|
@@ -40,10 +55,14 @@ export const messageGroupsApi = {
|
|
|
40
55
|
delete: (id: string) => apiClient(`/message-groups/${id}`, { method: 'DELETE' }),
|
|
41
56
|
|
|
42
57
|
publish: (id: string) =>
|
|
43
|
-
apiClient<MessageGroupFromDb>(`/message-groups/${id}/publish`, {
|
|
58
|
+
apiClient<MessageGroupFromDb>(`/message-groups/${id}/publish`, {
|
|
59
|
+
method: 'PUT',
|
|
60
|
+
}),
|
|
44
61
|
|
|
45
62
|
unpublish: (id: string) =>
|
|
46
|
-
apiClient<MessageGroupFromDb>(`/message-groups/${id}/unpublish`, {
|
|
63
|
+
apiClient<MessageGroupFromDb>(`/message-groups/${id}/unpublish`, {
|
|
64
|
+
method: 'PUT',
|
|
65
|
+
}),
|
|
47
66
|
|
|
48
67
|
validate: (id: string) =>
|
|
49
68
|
apiClient<MessageGroupValidationResponse>(`/message-groups/${id}/validate`),
|
package/app/api/meta.ts
CHANGED
|
@@ -1,22 +1,80 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
MetaImportCheck,
|
|
3
|
+
MetaImportConfirmBody,
|
|
4
|
+
MetaImportProposal,
|
|
5
|
+
MetaImportResult,
|
|
6
|
+
MetaImportScope,
|
|
7
|
+
OrganizationWaba,
|
|
2
8
|
SubmissionJob,
|
|
3
9
|
SubmissionJobResponse,
|
|
10
|
+
SubmitToWabaBody,
|
|
4
11
|
} from '@dev.smartpricing/message-composer-utils/types'
|
|
5
12
|
import { apiClient } from './client'
|
|
6
13
|
|
|
14
|
+
const submitBody = (wabaId?: string): SubmitToWabaBody => (wabaId ? { waba_id: wabaId } : {})
|
|
15
|
+
|
|
16
|
+
/** The Organization, Product and WABA of an Import, as a query string. */
|
|
17
|
+
const importQuery = ({ organization_id, product, waba_id }: MetaImportScope) =>
|
|
18
|
+
new URLSearchParams({ organization_id, product, waba_id }).toString()
|
|
19
|
+
|
|
7
20
|
export const metaApi = {
|
|
8
|
-
|
|
21
|
+
/**
|
|
22
|
+
* How many Meta Templates of the WABA an Import would offer (ADR 0020). No
|
|
23
|
+
* error toast: it runs in the background of the list, and a failure only
|
|
24
|
+
* means no Import button.
|
|
25
|
+
*/
|
|
26
|
+
checkImport: (scope: MetaImportScope) =>
|
|
27
|
+
apiClient<MetaImportCheck>(`/integrations/meta/import/check?${importQuery(scope)}`, {
|
|
28
|
+
_skipErrorToast: true,
|
|
29
|
+
} as Record<string, unknown>),
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What an Import of the WABA would write, read from Meta now. Writes
|
|
33
|
+
* nothing. No error toast: the import dialog says itself that Meta could
|
|
34
|
+
* not be read (a 502).
|
|
35
|
+
*/
|
|
36
|
+
getImportProposal: (scope: MetaImportScope) =>
|
|
37
|
+
apiClient<MetaImportProposal>(`/integrations/meta/import/proposal?${importQuery(scope)}`, {
|
|
38
|
+
_skipErrorToast: true,
|
|
39
|
+
} as Record<string, unknown>),
|
|
40
|
+
|
|
41
|
+
/** Confirms an Import: only Meta Template ids and how they are grouped. */
|
|
42
|
+
confirmImport: (body: MetaImportConfirmBody) =>
|
|
43
|
+
apiClient<MetaImportResult>('/integrations/meta/import', {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
body,
|
|
46
|
+
}),
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The WABAs of an Organization, empty when it has none (ADR 0015). No error
|
|
50
|
+
* toast: a failed lookup leaves the WhatsApp configuration unknown, and the
|
|
51
|
+
* submission itself reports what is wrong.
|
|
52
|
+
*/
|
|
53
|
+
getWabas: (organizationId: string) => {
|
|
54
|
+
const params = new URLSearchParams()
|
|
55
|
+
params.set('organization_id', organizationId)
|
|
56
|
+
return apiClient<OrganizationWaba[]>(`/integrations/meta/wabas?${params.toString()}`, {
|
|
57
|
+
_skipErrorToast: true,
|
|
58
|
+
} as Record<string, unknown>)
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* `wabaId` names the WABA of a first submission, when the user had to pick
|
|
63
|
+
* one. Left out, the backend uses the Message Group's WABA or the
|
|
64
|
+
* Organization's only one.
|
|
65
|
+
*/
|
|
66
|
+
submitGroup: (messageGroupId: string, wabaId?: string) =>
|
|
9
67
|
apiClient<SubmissionJobResponse>(`/integrations/meta/submit-group/${messageGroupId}`, {
|
|
10
68
|
method: 'POST',
|
|
11
|
-
body:
|
|
69
|
+
body: submitBody(wabaId),
|
|
12
70
|
}),
|
|
13
71
|
|
|
14
|
-
submitMessage: (messageId: string) =>
|
|
72
|
+
submitMessage: (messageId: string, wabaId?: string) =>
|
|
15
73
|
apiClient<{ success: boolean; templateId?: string }>(
|
|
16
74
|
`/integrations/meta/submit-message/${messageId}`,
|
|
17
75
|
{
|
|
18
76
|
method: 'POST',
|
|
19
|
-
body:
|
|
77
|
+
body: submitBody(wabaId),
|
|
20
78
|
},
|
|
21
79
|
),
|
|
22
80
|
|
package/app/api/organization.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import type { ReachableOrganization } from '@dev.smartpricing/message-composer-utils/types'
|
|
1
2
|
import { apiClient } from './client'
|
|
2
3
|
|
|
3
4
|
export const organizationApi = {
|
|
4
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The user's Reachable Organizations: the answer is what resolves the
|
|
7
|
+
* Effective Organization. No error toast, the Organization gate renders
|
|
8
|
+
* the failure.
|
|
9
|
+
*/
|
|
10
|
+
getReachable: () =>
|
|
11
|
+
apiClient<ReachableOrganization[]>('/organizations', {
|
|
12
|
+
_skipErrorToast: true,
|
|
13
|
+
} as Record<string, unknown>),
|
|
5
14
|
}
|
package/app/api/tracking.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { apiClient } from './client'
|
|
2
2
|
|
|
3
3
|
export const trackingApi = {
|
|
4
|
-
event: (eventName: string, properties?: Record<string, unknown>) =>
|
|
4
|
+
event: (eventName: string, organizationId: string, properties?: Record<string, unknown>) =>
|
|
5
5
|
apiClient<{ success: boolean }>('/tracking/event', {
|
|
6
6
|
method: 'POST',
|
|
7
|
-
body: { eventName, properties },
|
|
7
|
+
body: { eventName, properties, organization_id: organizationId },
|
|
8
8
|
}),
|
|
9
9
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AppConfigInput } from 'nuxt/schema'
|
|
2
|
+
|
|
3
|
+
// Not through `defineAppConfig`: its input type asks every app config for
|
|
4
|
+
// Nuxt UI's `ui`, which only the design system's own config sets.
|
|
5
|
+
export default {
|
|
6
|
+
composer: {
|
|
7
|
+
tracking: false,
|
|
8
|
+
automations: false,
|
|
9
|
+
},
|
|
10
|
+
} satisfies Pick<AppConfigInput, 'composer'>
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type {
|
|
3
|
+
AutomationChannel,
|
|
4
|
+
AutomationTrigger,
|
|
5
|
+
} from '@dev.smartpricing/message-composer-utils/types'
|
|
6
|
+
import {
|
|
7
|
+
dateReferenceLabel,
|
|
8
|
+
localSendingTime,
|
|
9
|
+
type AutomationFormAction,
|
|
10
|
+
} from '../../utils/automations/form'
|
|
11
|
+
import type {
|
|
12
|
+
AutomationUnavailableItem,
|
|
13
|
+
AutomationUnavailableKind,
|
|
14
|
+
} from '../../utils/automations/unavailable'
|
|
15
|
+
|
|
16
|
+
/** One Action of the form: what it sends and when, its Active switch and its buttons. */
|
|
17
|
+
const props = defineProps<{
|
|
18
|
+
action: AutomationFormAction
|
|
19
|
+
trigger: AutomationTrigger
|
|
20
|
+
/** What the Action holds that is no longer available: each is a badge here. */
|
|
21
|
+
unavailable: AutomationUnavailableItem[]
|
|
22
|
+
/** A refused save pointed at this Action. */
|
|
23
|
+
invalid?: boolean
|
|
24
|
+
/** The Action is not edited or removed here: its Active switch still works. */
|
|
25
|
+
readOnly?: boolean
|
|
26
|
+
}>()
|
|
27
|
+
|
|
28
|
+
const emit = defineEmits<{
|
|
29
|
+
edit: []
|
|
30
|
+
remove: []
|
|
31
|
+
toggle: [active: boolean]
|
|
32
|
+
}>()
|
|
33
|
+
|
|
34
|
+
const { t } = useI18n()
|
|
35
|
+
|
|
36
|
+
const CHANNEL_ICONS: Record<AutomationChannel, string> = {
|
|
37
|
+
email: 'ph:envelope-simple-bold',
|
|
38
|
+
whatsapp: 'ph:whatsapp-logo-bold',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const schedule = computed(() => {
|
|
42
|
+
// `moment` is the name the ported copy gives the Date Reference.
|
|
43
|
+
const moment = dateReferenceLabel(props.action, props.trigger)
|
|
44
|
+
const { days } = props.action
|
|
45
|
+
if (days === 0) return t('automations.immediately', { moment })
|
|
46
|
+
if (days === 1) return t('automations.oneDay', { moment })
|
|
47
|
+
return t('automations.nDays', { count: days, moment })
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
function unavailableOf(...kinds: AutomationUnavailableKind[]) {
|
|
51
|
+
return props.unavailable.find((item) => kinds.includes(item.kind))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const unusableChannel = computed(() => unavailableOf('channel'))
|
|
55
|
+
const unlistedDateReference = computed(() => unavailableOf('date_reference'))
|
|
56
|
+
const unapproved = computed(() => unavailableOf('message_group_inactive', 'message_group_active'))
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Why the Action cannot be turned on: its Channel cannot be used, or its
|
|
60
|
+
* Message Group is not approved. An Active one on an unapproved Message Group
|
|
61
|
+
* keeps a switch that works, so the user can turn it off.
|
|
62
|
+
*/
|
|
63
|
+
const cannotBeActive = computed(
|
|
64
|
+
() => unusableChannel.value ?? unavailableOf('message_group_inactive'),
|
|
65
|
+
)
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
<UCard :class="{ 'ring-error': invalid }">
|
|
70
|
+
<div class="flex items-start gap-4">
|
|
71
|
+
<UAvatar :icon="CHANNEL_ICONS[action.channel]" size="xl" class="shrink-0" />
|
|
72
|
+
|
|
73
|
+
<div class="flex-1 min-w-0">
|
|
74
|
+
<div class="flex items-center gap-2">
|
|
75
|
+
<p class="label-md truncate">
|
|
76
|
+
{{ action.messageGroupName || t(`automations.channels.${action.channel}`) }}
|
|
77
|
+
</p>
|
|
78
|
+
<AutomationsUnavailableBadge v-if="unapproved" :item="unapproved" />
|
|
79
|
+
<AutomationsUnavailableBadge v-if="unusableChannel" :item="unusableChannel" />
|
|
80
|
+
</div>
|
|
81
|
+
<p class="mt-2 paragraph-sm text-muted">
|
|
82
|
+
{{ t('automations.action.itIsSent') }}
|
|
83
|
+
<span class="font-semibold text-default">{{ schedule }}</span>
|
|
84
|
+
<AutomationsUnavailableBadge
|
|
85
|
+
v-if="unlistedDateReference"
|
|
86
|
+
:item="unlistedDateReference"
|
|
87
|
+
class="ml-2"
|
|
88
|
+
/>
|
|
89
|
+
<span class="mx-2">•</span>
|
|
90
|
+
{{ t('automations.action.at') }}
|
|
91
|
+
<span class="font-semibold text-default">
|
|
92
|
+
{{ localSendingTime(action.sendingTimeUTC) }}
|
|
93
|
+
</span>
|
|
94
|
+
<template v-if="action.recurrence">
|
|
95
|
+
<span class="mx-2">•</span>
|
|
96
|
+
<span class="font-semibold text-default">
|
|
97
|
+
{{ t(`automations.recurrence.${action.recurrence}`) }}
|
|
98
|
+
</span>
|
|
99
|
+
</template>
|
|
100
|
+
<template v-if="action.strictDelay">
|
|
101
|
+
<span class="mx-2">•</span>
|
|
102
|
+
<UBadge :label="t('automations.strictDelay.label')" color="neutral" size="sm" />
|
|
103
|
+
</template>
|
|
104
|
+
<template v-if="action.preventDuplicates">
|
|
105
|
+
<span class="mx-2">•</span>
|
|
106
|
+
<UBadge :label="t('automations.preventDuplicates.label')" color="neutral" size="sm" />
|
|
107
|
+
</template>
|
|
108
|
+
</p>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<template #footer>
|
|
113
|
+
<div class="flex items-center gap-1">
|
|
114
|
+
<!-- An Action on a Channel that cannot be used is kept as stored, and shown as not Active. -->
|
|
115
|
+
<UTooltip :text="cannotBeActive?.text" :disabled="!cannotBeActive">
|
|
116
|
+
<!-- A disabled switch takes no hover: the tooltip is on what wraps it. -->
|
|
117
|
+
<span class="inline-flex">
|
|
118
|
+
<USwitch
|
|
119
|
+
:model-value="action.status === 'active' && !unusableChannel"
|
|
120
|
+
:disabled="Boolean(cannotBeActive)"
|
|
121
|
+
size="sm"
|
|
122
|
+
color="secondary"
|
|
123
|
+
:label="t('automations.list.active')"
|
|
124
|
+
:data-testid="automationsTestIds.actionEnabledSwitch"
|
|
125
|
+
@update:model-value="emit('toggle', $event)"
|
|
126
|
+
/>
|
|
127
|
+
</span>
|
|
128
|
+
</UTooltip>
|
|
129
|
+
|
|
130
|
+
<div class="ml-auto flex items-center gap-1">
|
|
131
|
+
<UButton
|
|
132
|
+
v-if="!readOnly"
|
|
133
|
+
color="error"
|
|
134
|
+
variant="ghost"
|
|
135
|
+
size="sm"
|
|
136
|
+
:label="t('common.actions.delete')"
|
|
137
|
+
:data-testid="automationsTestIds.actionDeleteButton"
|
|
138
|
+
@click="emit('remove')"
|
|
139
|
+
/>
|
|
140
|
+
<USlideover
|
|
141
|
+
close-icon="ph:x"
|
|
142
|
+
:close="{ 'data-testid': automationsTestIds.previewSlideoverCloseButton }"
|
|
143
|
+
:title="t('common.preview')"
|
|
144
|
+
:content="dialogTestId(automationsTestIds.previewSlideover)"
|
|
145
|
+
:ui="{ content: 'max-w-2xl', body: 'p-0 sm:p-0' }"
|
|
146
|
+
>
|
|
147
|
+
<UButton
|
|
148
|
+
color="primary"
|
|
149
|
+
variant="outline"
|
|
150
|
+
size="sm"
|
|
151
|
+
:label="t('common.preview')"
|
|
152
|
+
:data-testid="automationsTestIds.actionPreviewButton"
|
|
153
|
+
/>
|
|
154
|
+
|
|
155
|
+
<template #body>
|
|
156
|
+
<CommonPreviewById
|
|
157
|
+
:id="action.messageGroupId"
|
|
158
|
+
class="w-full h-full min-h-[400px]"
|
|
159
|
+
show-subject
|
|
160
|
+
/>
|
|
161
|
+
</template>
|
|
162
|
+
</USlideover>
|
|
163
|
+
<UButton
|
|
164
|
+
v-if="!readOnly"
|
|
165
|
+
size="sm"
|
|
166
|
+
:label="t('common.actions.edit')"
|
|
167
|
+
:data-testid="automationsTestIds.actionEditButton"
|
|
168
|
+
@click="emit('edit')"
|
|
169
|
+
/>
|
|
170
|
+
</div>
|
|
171
|
+
</div>
|
|
172
|
+
</template>
|
|
173
|
+
</UCard>
|
|
174
|
+
</template>
|