@dev.smartpricing/message-composer-layer 4.5.1-next.4 → 4.5.1-next.5

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 (81) hide show
  1. package/README.md +4 -133
  2. package/app/api/index.ts +0 -1
  3. package/app/api/messageGroups.ts +1 -5
  4. package/app/api/meta.ts +36 -0
  5. package/app/components/Common/MessageGroupSelect.vue +1 -30
  6. package/app/components/Composer/EmailComposer.vue +1 -5
  7. package/app/components/Composer/MessageLibrary.vue +8 -0
  8. package/app/components/Composer/WabaSelectModal.vue +1 -3
  9. package/app/components/Composer/WhatsappComposer.vue +1 -5
  10. package/app/components/Layout/BasePage.vue +0 -2
  11. package/app/components/MetaImport/Button.vue +50 -0
  12. package/app/components/MetaImport/Dialog.vue +261 -0
  13. package/app/components/MetaImport/Outcome.vue +136 -0
  14. package/app/components/MetaImport/ProposalList.vue +192 -0
  15. package/app/components/TemplateList/BaseTable.vue +22 -1
  16. package/app/composables/apiErrorMessages.ts +0 -1
  17. package/app/composables/composerContext.ts +3 -3
  18. package/app/composables/useMessageGroupWaba.ts +10 -7
  19. package/app/composables/useTemplateOperations.ts +3 -8
  20. package/app/pages/index.vue +5 -1
  21. package/app/pages/template/email/[id].vue +0 -5
  22. package/app/pages/template/email/create.vue +0 -5
  23. package/app/pages/template/whatsapp/[id].vue +0 -5
  24. package/app/pages/template/whatsapp/create.vue +0 -5
  25. package/app/queries/index.ts +0 -1
  26. package/app/queries/messageGroups.ts +29 -20
  27. package/app/queries/meta.ts +91 -1
  28. package/app/stores/appContext.ts +1 -1
  29. package/app/types/app-config.d.ts +0 -3
  30. package/app/types/tracking.ts +0 -33
  31. package/app/utils/testIds.const.ts +1 -107
  32. package/app.config.ts +5 -0
  33. package/i18n/locales/de.ts +64 -269
  34. package/i18n/locales/en.ts +61 -255
  35. package/i18n/locales/es.ts +62 -258
  36. package/i18n/locales/fr.ts +63 -264
  37. package/i18n/locales/it.ts +65 -260
  38. package/package.json +4 -4
  39. package/app/api/automations.ts +0 -74
  40. package/app/app.config.ts +0 -10
  41. package/app/components/Automations/ActionCard.vue +0 -174
  42. package/app/components/Automations/ActionEditor.vue +0 -398
  43. package/app/components/Automations/Actions.vue +0 -148
  44. package/app/components/Automations/CloneModal.vue +0 -78
  45. package/app/components/Automations/Conditions.vue +0 -155
  46. package/app/components/Automations/Create.vue +0 -114
  47. package/app/components/Automations/Data.vue +0 -46
  48. package/app/components/Automations/DeleteModal.vue +0 -80
  49. package/app/components/Automations/Edit.vue +0 -145
  50. package/app/components/Automations/Form.vue +0 -282
  51. package/app/components/Automations/List.vue +0 -370
  52. package/app/components/Automations/PageGate.vue +0 -50
  53. package/app/components/Automations/SaveProblems.vue +0 -54
  54. package/app/components/Automations/Unavailable.vue +0 -71
  55. package/app/components/Automations/UnavailableBadge.vue +0 -35
  56. package/app/components/Filters/DateInput.vue +0 -57
  57. package/app/components/Filters/Editor.vue +0 -163
  58. package/app/components/Filters/Row.vue +0 -119
  59. package/app/components/Filters/Summary.vue +0 -215
  60. package/app/components/Filters/UnavailableRow.vue +0 -74
  61. package/app/components/Filters/ValueInput.vue +0 -215
  62. package/app/composables/automationsContext.ts +0 -42
  63. package/app/composables/useAutomationClone.ts +0 -33
  64. package/app/composables/useAutomationEditorTrip.ts +0 -77
  65. package/app/composables/useAutomationSaveProblems.ts +0 -82
  66. package/app/composables/useAutomationUnavailable.ts +0 -98
  67. package/app/composables/useAutomationsGate.ts +0 -68
  68. package/app/composables/useBuiltInOptionLists.ts +0 -44
  69. package/app/composables/useEditorTripBack.ts +0 -15
  70. package/app/middleware/automations-enabled.ts +0 -12
  71. package/app/pages/automations/[id].vue +0 -87
  72. package/app/pages/automations/index.vue +0 -28
  73. package/app/pages/automations/new.vue +0 -53
  74. package/app/queries/automations.ts +0 -206
  75. package/app/stores/editorTrip.ts +0 -67
  76. package/app/utils/automations/form.ts +0 -389
  77. package/app/utils/automations/metadata.ts +0 -71
  78. package/app/utils/automations/unavailable.ts +0 -90
  79. package/app/utils/filters/data/countries.json +0 -998
  80. package/app/utils/filters/data/languages.json +0 -754
  81. package/app/utils/filters/rows.ts +0 -367
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The Message Composer as a [Nuxt layer](https://nuxt.com/docs/getting-started/layers). A host app extends it and gets the composer pages (message library, editor, preview, brands, images) plus embeddable components such as the **Message Send Flow**.
4
4
 
5
- The layer is published on the private Smartpricing npm registry together with `@dev.smartpricing/message-composer-utils` (shared types, helpers and Zod schemas, subpath exports `/types`, `/utils` and `/schemas`). Both packages share one version number.
5
+ The layer is published on the private Smartpricing npm registry together with `@dev.smartpricing/message-composer-utils` (shared types and helpers, subpath exports `/types` and `/utils`). Both packages share one version number.
6
6
 
7
7
  ## Host setup
8
8
 
@@ -55,7 +55,7 @@ The layer is published on the private Smartpricing npm registry together with `@
55
55
 
56
56
  4. Tracking is opt-in: set `composer.tracking: true` in the host's `app.config.ts` to have the layer post its events to `POST /tracking/event`.
57
57
 
58
- The layer's pages are mounted at root (`/`, `/template/...`, `/preview/...`, `/brands`, `/images`). Remap them with `pages:extend` if the host already owns those routes. The Automation pages (`/automations/...`) are mounted too and answer 404 until the Host turns them on: see "Automation pages" below.
58
+ The layer's pages are mounted at root (`/`, `/template/...`, `/preview/...`, `/brands`, `/images`). Remap them with `pages:extend` if the host already owns those routes.
59
59
 
60
60
  ## Organization and WABA
61
61
 
@@ -85,14 +85,14 @@ watch(
85
85
  )
86
86
  ```
87
87
 
88
- **WABA.** The Host does not supply the WABA: the WABAs follow the Organization and the backend resolves them (ADR [0015](../../docs/adr/0015-message-group-waba-fixed-at-first-submission.md)). WhatsApp is configured when the Host's `channels` include `whatsapp` and the Organization has at least one WABA. A Message Group is submitted to one WABA, chosen at its first submission and fixed from then on; with several WABAs the user picks one when requesting approval. `metaWabaId` in the context is optional and is only the preselection in that picker.
88
+ **WABA.** The Host does not have to supply the WABA: the WABAs follow the Organization and the backend resolves them (ADR [0015](../../docs/adr/0015-message-group-waba-fixed-at-first-submission.md)). WhatsApp is configured when the Host's `channels` include `whatsapp` and the Organization has at least one WABA. A Message Group is submitted to one WABA, chosen at its first submission and fixed from then on; with several WABAs it is the `metaWabaId` the Host passed, when that is one of them, and otherwise the user picks one when requesting approval. `metaWabaId` in the context is optional.
89
89
 
90
90
  ### Upgrading to 4.5.0
91
91
 
92
92
  Nothing is required: a Host that keeps passing `organization_id` and `metaWabaId` behaves as before.
93
93
 
94
94
  - **Removed** from `ComposerContext` and from `AppContextConfig` in utils (no code read them): `authenticationToken`, `strategy`, `metaAccessToken`, `dinamicValues`. Remove them from the `defineComposerContext()` call. The utils types `AppContextState` and `ContextSource` are gone too.
95
- - **Changed**: `metaWabaId` no longer decides where a WhatsApp submission goes and is no longer required for the WhatsApp channel; it preselects the WABA when the user has to pick one.
95
+ - **Changed**: `metaWabaId` no longer decides where a WhatsApp submission goes and is no longer required for the WhatsApp channel; with several WABAs on the Organization it names the one a new Message Group is submitted to, and the user is asked only without it.
96
96
  - **Deprecated**, removed in 5.0.0: the `sm-organization-id` and `x-meta-waba-id` request headers. The layer no longer sends them; the backend still accepts them from Hosts on an older layer.
97
97
  - **New**: `organization_id` is optional, the Organization selector, `useEffectiveOrganization()`, and the `organizationId` and `wabaId` props of the Message Send Flow.
98
98
 
@@ -237,135 +237,6 @@ With tracking enabled the flow reports `send_flow.confirm` (`message_name`, `mes
237
237
 
238
238
  `apps/frontend` (this monorepo's standalone host) has a permanent `/debug/send-flow` page that plays the host: preselect, preferred language, prefill JSON, brand id, the flow's own Organization and WABA, inline or modal container, remount, and a log of every emit.
239
239
 
240
- ## Automation pages
241
-
242
- Three pages list, create and edit the Automations of the Host's Product. The Automations live in the Automation Engine and the composer backend is the only way to them (ADR [0016](../../docs/adr/0016-automations-live-in-the-automation-engine.md)). The pages are off until a Host turns them on (ADR [0019](../../docs/adr/0019-automation-pages-off-until-a-host-turns-them-on.md)): an upgrade changes nothing for a Host that does not set the flag.
243
-
244
- 1. Turn them on in the Host's `app.config.ts`, next to `composer.tracking`:
245
-
246
- ```ts
247
- export default defineAppConfig({
248
- composer: { automations: true },
249
- })
250
- ```
251
-
252
- The routes always exist. While the flag is off, a layer middleware on those pages answers 404. The flag is static: a Host that wants the pages for some Organizations only does it with its own guard.
253
-
254
- 2. Provide the Automations context before an Automation page renders (`app.vue` or a plugin), as `defineComposerContext()` and apart from it:
255
-
256
- ```vue
257
- <script setup lang="ts">
258
- const { countries, languages } = useBuiltInOptionLists()
259
- const tags = ref<AutomationOption[]>([]) // fetched and kept current by the Host
260
-
261
- defineAutomationsContext({
262
- optionLists: computed(() => ({
263
- countries: countries.value,
264
- languages: languages.value,
265
- tags: tags.value,
266
- })),
267
- currency: ref('EUR'),
268
- })
269
- </script>
270
- ```
271
-
272
- ### Routes
273
-
274
- | Route name | Path | Page |
275
- | ------------------- | ------------------ | ------------------------------------------------------------------------------------- |
276
- | `automations-list` | `/automations` | The Automations of the Host's Product. Clone and delete are actions here, not routes. |
277
- | `automation-create` | `/automations/new` | A new Automation. |
278
- | `automation-edit` | `/automations/:id` | An existing Automation; a clone opens here. |
279
-
280
- Link to them by name. The paths are the Host's to remap in `pages:extend`, and the Automation pages may sit under a different prefix than the Message pages: every link between them and the Message editor is by route name.
281
-
282
- ### `defineAutomationsContext(context)`
283
-
284
- `AutomationsContext` and `AutomationOption` live in `app/composables/automationsContext.ts`.
285
-
286
- | Key | Type | Description |
287
- | ------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
288
- | `optionLists` | `Ref<Record<string, AutomationOption[]>>` | Required. The option lists, by the name the Automation Catalog gives them (the `option_list` of a Condition Field). An `AutomationOption` is `{ value: string \| number, label: string }`, label already translated. A list that is not there shows as empty. |
289
- | `currency` | `Ref<string \| undefined>` | Optional. ISO code of the currency `price` fields show; EUR when absent. Never a conversion. |
290
-
291
- The Automation Catalog holds no option: every list is the Host's (ADR [0017](../../docs/adr/0017-automation-catalog-served-by-the-backend.md)). There are no loader callbacks: the Host fetches the lists and keeps the refs current. Countries and languages can come from `useBuiltInOptionLists()`.
292
-
293
- ### What a page needs to work
294
-
295
- An Automation page checks three things inside the page, not in the layout, so a Host that replaces the layout keeps the check:
296
-
297
- 1. **The Automations context**: `defineAutomationsContext()` was called.
298
- 2. **An Automation Catalog for the Host's Product**: the backend serves one for the `product` of the composer context.
299
- 3. **An Organization**: the layer resolved one (see "Organization and WABA").
300
-
301
- With the flag on and one of them missing, the page keeps its header and shows an error alert in place of its content. A failed Organization lookup or a failed catalog request shows the same alert with a retry.
302
-
303
- The layer ships **no permission check** on these pages: the Host guards them as it guards the Message pages.
304
-
305
- A Host sees only the Automations of its own Product. The Channels an Action can send over are the ones the catalog gives its Trigger, limited to the `channels` of the composer context, and WhatsApp only when the Organization has a WABA.
306
-
307
- ### Public and stable
308
-
309
- This is the host contract for Automations:
310
-
311
- - the `composer.automations` flag;
312
- - the three route names: `automations-list`, `automation-create`, `automation-edit`;
313
- - `defineAutomationsContext()` and the shape of `AutomationsContext`;
314
- - `FiltersEditor` and `FiltersSummary`, with their props and emits;
315
- - the `fields` shape and the report: `FilterField`, `FilterOption`, `FiltersReport`;
316
- - `useBuiltInOptionLists()`;
317
- - the shared schemas in `@dev.smartpricing/message-composer-utils/schemas`: the Condition schemas (`conditionSchema`, `conditionOperatorSchema`, `conditionFieldTypeSchema`), the request and response schemas of the Automation routes and of the Automation Catalog, and with them the operator table `CONDITION_OPERATORS_BY_FIELD_TYPE` (in `/types`).
318
-
319
- The semver promise (ADRs [0018](../../docs/adr/0018-filter-components-speak-conditions-and-know-no-catalog.md) and [0019](../../docs/adr/0019-automation-pages-off-until-a-host-turns-them-on.md)):
320
-
321
- - **Major**: renaming or removing a route name; removing or renaming a prop of a filter component; changing the shape of the value (`Condition[]`); dropping a field type or an operator.
322
- - **Minor**: adding a prop, a field type or an operator.
323
- - **No promise**: the paths (the Host's to remap), everything else under `app/components/Filters/` and `app/utils/filters/`, and the test-id pattern. They can change in any release. The components and utils of the pages themselves (`app/components/Automations/`, `app/utils/automations/`) are not on the list above.
324
-
325
- The flag, the context and the shared schemas are host contract with no rule of their own in the ADRs: the general one applies (see "Release": a change to the host contract is a major).
326
-
327
- ## Filter components
328
-
329
- Two props-only components edit and show a list of Conditions in the Automation Engine's shape (`{ field, operator, value? }`), on any page: they read neither the Automation Catalog nor the Host's context ([ADR 0018](../../docs/adr/0018-filter-components-speak-conditions-and-know-no-catalog.md)). The slideover, Save and Cancel around the editor belong to the page.
330
-
331
- ```vue
332
- <script setup lang="ts">
333
- import type {
334
- Condition,
335
- FilterField,
336
- FiltersReport,
337
- } from '@dev.smartpricing/message-composer-utils/types'
338
-
339
- const { countries } = useBuiltInOptionLists()
340
-
341
- const fields = computed<FilterField[]>(() => [
342
- { key: 'guest.country', label: t('country'), type: 'multiselect', options: countries.value },
343
- { key: 'totalPrice', label: t('total_price'), type: 'price' },
344
- ])
345
- const conditions = ref<Condition[]>([])
346
- const report = ref<FiltersReport>()
347
- </script>
348
-
349
- <template>
350
- <FiltersEditor v-model="conditions" :fields="fields" title="Audience" @report="report = $event" />
351
- <FiltersSummary :model-value="conditions" :fields="fields" />
352
- </template>
353
- ```
354
-
355
- | Auto-import name | Props | Emits |
356
- | ------------------------- | -------------------------------------------------------------------------------------------------------------- | ----------------------------- |
357
- | `FiltersEditor` | `v-model` (`Condition[]`), `fields`, `currency?`, `title?`, `subtitle?`, `testIdPrefix?` | `update:modelValue`, `report` |
358
- | `FiltersSummary` | `modelValue` (`Condition[]`), `fields`, `currency?`, `preview?` (lines before "View more", 3), `testIdPrefix?` | `report` |
359
- | `useBuiltInOptionLists()` | returns `countries` and `languages`: option lists in the current language, values are lowercase ISO codes | - |
360
-
361
- - **`fields`** is one reactive list of `{ key, label, type, options? }`, labels and options already resolved, in display order. `type` is one of `select`, `multiselect`, `number`, `price`, `date`, `text`; the operators of each are `CONDITION_OPERATORS_BY_FIELD_TYPE` in `message-composer-utils`. A field can be picked once.
362
- - **Values**: a `price` is stored in cents and shown in `currency` (EUR when absent, never converted); a `date` is `YYYY-MM-DD`. "Between" is a `gte` and an `lte` on the same field. There is no "not between": the Automation Engine holds all the Conditions of a list together, so no pair of them can say "outside this range". A stored `lte` below a `gte` on one field shows as one editable row and one unavailable row.
363
- - **Nothing is dropped.** A Condition on a field that is not in `fields`, with an operator or a value that does not fit the field's type, or one too many on a field, shows as an unavailable row: emitted as it came in until the user removes it. A selected option that is not in `options` shows as unavailable and is kept the same way. A row the user did not touch is emitted exactly as stored.
364
- - **`report`** (`FiltersReport`, emitted on mount and on every change): `unknownFields`, `unavailable` (each Condition with its reason, `unknown_field` or `not_editable`), `unavailableOptions`, and `halfFilled`, the rows with a field and no complete value. A half-filled row is never in the emitted value. The components block nothing: the caller decides what stops a save.
365
- - **Rows in progress** live in the editor only. It reads its rows again when the Conditions change from outside or when the keys or types in `fields` change, and rows in progress are then lost. Setting `v-model` to the value it already has does not reset them: to start over, remount the editor with a `key`.
366
- - **Stability**: the two components, the `fields` shape, the report (`FilterField`, `FilterOption` and `FiltersReport`, in `message-composer-utils/types`), `useBuiltInOptionLists()` and the Condition schemas are host contract, usable before the Automation pages are turned on. What is a major and what is a minor is in "Public and stable" above.
367
- - **Dev harness**: `/debug/filters` in `apps/frontend`.
368
-
369
240
  ## Development
370
241
 
371
242
  Run from `apps/layer`:
package/app/api/index.ts CHANGED
@@ -10,4 +10,3 @@ export * from './tracking'
10
10
  export * from './dynamicValues'
11
11
  export * from './brands'
12
12
  export * from './organization'
13
- export * from './automations'
@@ -34,11 +34,7 @@ export const messageGroupsApi = {
34
34
  `/message-groups${listQueryString(options)}`,
35
35
  ),
36
36
 
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>),
37
+ getById: (id: string) => apiClient<MessageGroupWithMessages>(`/message-groups/${id}`),
42
38
 
43
39
  create: (data: PostEntity<MessageGroup>) =>
44
40
  apiClient<MessageGroupFromDb>('/message-groups', {
package/app/api/meta.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  import type {
2
+ MetaImportCheck,
3
+ MetaImportConfirmBody,
4
+ MetaImportProposal,
5
+ MetaImportResult,
6
+ MetaImportScope,
2
7
  OrganizationWaba,
3
8
  SubmissionJob,
4
9
  SubmissionJobResponse,
@@ -8,7 +13,38 @@ import { apiClient } from './client'
8
13
 
9
14
  const submitBody = (wabaId?: string): SubmitToWabaBody => (wabaId ? { waba_id: wabaId } : {})
10
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
+
11
20
  export const metaApi = {
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
+
12
48
  /**
13
49
  * The WABAs of an Organization, empty when it has none (ADR 0015). No error
14
50
  * toast: a failed lookup leaves the WhatsApp configuration unknown, and the
@@ -35,8 +35,6 @@ const ELIGIBILITY_RULES: Record<
35
35
  * menu's search input; pages of 100 load on demand through "Load more".
36
36
  * The selected group stays in the menu even when the loaded pages no longer
37
37
  * contain it (search cleared, paging reset, or preselected beyond page one).
38
- * A selected group that cannot be picked is still shown, with its status and
39
- * whatever the hide filter says: it was selected elsewhere, not offered here.
40
38
  */
41
39
  const props = withDefaults(
42
40
  defineProps<{
@@ -188,7 +186,7 @@ const items = computed(() => {
188
186
  const externalReason = props.disabledGroupReasons?.[group.id]
189
187
  const eligible = rule.value.isEligible(group.messages)
190
188
  const disabled = !eligible || externalReason != null
191
- if (hideIneligible.value && disabled && group.id !== modelValue.value) return acc
189
+ if (hideIneligible.value && disabled) return acc
192
190
  // External reason wins over the mode's own tooltip when both apply.
193
191
  let tooltip: string | undefined
194
192
  if (externalReason != null) tooltip = externalReason
@@ -204,21 +202,6 @@ const items = computed(() => {
204
202
  }, [])
205
203
  })
206
204
 
207
- // What keeps a group from being eligible, worst first.
208
- const BLOCKING_STATUSES = ['rejected', 'pending', 'draft'] as const
209
- const STATUS_COLORS = { rejected: 'error', pending: 'warning', draft: 'neutral' } as const
210
-
211
- /** The selected group when it fails the mode's rule, with the status that says why. */
212
- const selectedIneligible = computed(() => {
213
- const group = messageGroups.value.find((g) => g.id === modelValue.value)
214
- if (!group || rule.value.isEligible(group.messages)) return undefined
215
- // A group with no Message has nothing past a draft.
216
- const status =
217
- BLOCKING_STATUSES.find((candidate) => group.messages.some((m) => m.status === candidate)) ??
218
- 'draft'
219
- return { name: group.name, status, color: STATUS_COLORS[status] }
220
- })
221
-
222
205
  function handleUpdate(value: string) {
223
206
  modelValue.value = value
224
207
  const group = messageGroups.value.find((g) => g.id === value)
@@ -241,18 +224,6 @@ function handleUpdate(value: string) {
241
224
  :data-testid="messageGroupSelectTestIds.root"
242
225
  @update:model-value="handleUpdate"
243
226
  >
244
- <template v-if="selectedIneligible" #default>
245
- <span class="truncate">{{ selectedIneligible.name }}</span>
246
- <UBadge
247
- leading-icon="ph:circle-fill"
248
- :label="t(`status.${selectedIneligible.status}`)"
249
- size="sm"
250
- :color="selectedIneligible.color"
251
- variant="outline"
252
- class="shrink-0"
253
- />
254
- </template>
255
-
256
227
  <template #item-label="{ item }">
257
228
  <UTooltip v-if="item.disabled" :text="item.tooltip">
258
229
  <span class="text-muted">{{ item.label }}</span>
@@ -165,12 +165,8 @@ const { formState, draftSchema, validationErrors, validateDraft, validateFull, c
165
165
  // ── Template operations ───────────────────────────────────────────
166
166
  const successFlag = ref(false)
167
167
 
168
- const editorTrip = useEditorTripStore()
169
-
170
168
  const { saving, createTemplate, updateTemplate } = useTemplateOperations({
171
- onSuccess: (saved) => {
172
- // Recorded before the editor navigates: whoever opened it reads it on landing.
173
- if (saved) editorTrip.recordSaved(saved)
169
+ onSuccess: () => {
174
170
  successFlag.value = true
175
171
  goBackOrFallback()
176
172
  },
@@ -19,6 +19,8 @@ const emit = defineEmits<{
19
19
  duplicated: [result: { id: string | number; sourceId: string | number; name: string }]
20
20
  published: [row: MessageGroupWithMessageSummary]
21
21
  unpublished: [row: MessageGroupWithMessageSummary]
22
+ /** Once, when the list has loaded for the first time. */
23
+ loaded: []
22
24
  }>()
23
25
 
24
26
  const { trackEvent } = useTracking()
@@ -36,6 +38,12 @@ const {
36
38
  refetch: execute,
37
39
  } = useMessageGroupList(renderType)
38
40
 
41
+ whenever(
42
+ () => !isFetching.value,
43
+ () => emit('loaded'),
44
+ { immediate: true, once: true },
45
+ )
46
+
39
47
  // Polling
40
48
  const interval = setInterval(() => execute(), 15000)
41
49
  onBeforeUnmount(() => clearInterval(interval))
@@ -8,13 +8,11 @@ import type { OrganizationWaba } from '@dev.smartpricing/message-composer-utils/
8
8
  */
9
9
  const props = defineProps<{
10
10
  wabas: OrganizationWaba[]
11
- /** The Host's WABA, already checked to be one of `wabas`. */
12
- preselected?: string
13
11
  }>()
14
12
 
15
13
  const emit = defineEmits<{ close: [wabaId?: string] }>()
16
14
 
17
- const selected = ref<string | undefined>(props.preselected)
15
+ const selected = ref<string>()
18
16
 
19
17
  const items = computed(() =>
20
18
  props.wabas.map((waba) => ({
@@ -134,12 +134,8 @@ const { formState, draftSchema, validationErrors, validateDraft, validateFull, c
134
134
  // ── Template operations ───────────────────────────────────────────
135
135
  const successFlag = ref(false)
136
136
 
137
- const editorTrip = useEditorTripStore()
138
-
139
137
  const { saving, createTemplate, updateTemplate } = useTemplateOperations({
140
- onSuccess: (saved) => {
141
- // Recorded before the editor navigates: whoever opened it reads it on landing.
142
- if (saved) editorTrip.recordSaved(saved)
138
+ onSuccess: () => {
143
139
  successFlag.value = true
144
140
  changeTracking.clearAllChanges()
145
141
  if (props.mode === 'create') {
@@ -11,7 +11,6 @@ const props = defineProps<{
11
11
 
12
12
  const emit = defineEmits<{
13
13
  tabChange: [value: string | number]
14
- back: []
15
14
  }>()
16
15
 
17
16
  watchEffect(() => {
@@ -29,7 +28,6 @@ watchEffect(() => {
29
28
  :data-testid="testId"
30
29
  class="bg-white sticky top-0 z-10"
31
30
  @tab-change="emit('tabChange', $event)"
32
- @back="emit('back')"
33
31
  >
34
32
  <template #actions>
35
33
  <div class="flex items-center gap-1.5">
@@ -0,0 +1,50 @@
1
+ <script setup lang="ts">
2
+ import MetaImportDialog from '~/components/MetaImport/Dialog.vue'
3
+ import { useMetaImportCheckQuery } from '~/queries'
4
+
5
+ /**
6
+ * The Import from Meta button of the Message Group list (ADR 0020). It is
7
+ * there only when a WABA of the Organization holds Meta Templates the
8
+ * composer does not, and says how many. The check behind it runs on its own:
9
+ * the list never waits for it.
10
+ */
11
+ const props = defineProps<{
12
+ /** False until the list has loaded: the check is asked only after it. */
13
+ enabled: boolean
14
+ }>()
15
+
16
+ const emit = defineEmits<{
17
+ /** An Import was confirmed: the list holds new WhatsApp Message Groups. */
18
+ imported: []
19
+ }>()
20
+
21
+ const appContext = useAppContextStore()
22
+ const organization = useEffectiveOrganizationStore()
23
+
24
+ const { data: checks } = useMetaImportCheckQuery({ enabled: () => props.enabled })
25
+
26
+ const count = computed(() => (checks.value ?? []).reduce((sum, check) => sum + check.count, 0))
27
+
28
+ const dialog = useOverlay().create(MetaImportDialog)
29
+
30
+ async function openDialog() {
31
+ const organizationId = organization.organizationId
32
+ const product = appContext.product
33
+ if (!checks.value?.length || !organizationId || !product) return
34
+
35
+ const imported = await dialog.open({ checks: checks.value, organizationId, product }).result
36
+ if (imported) emit('imported')
37
+ }
38
+ </script>
39
+
40
+ <template>
41
+ <UButton
42
+ v-if="count > 0"
43
+ :label="$t('pages.message_library.import_from_meta', { count })"
44
+ icon="ph:download-simple"
45
+ color="neutral"
46
+ variant="outline"
47
+ data-testid="meta-import-button"
48
+ @click="openDialog"
49
+ />
50
+ </template>