@dev.smartpricing/message-composer-layer 4.2.9 → 4.2.11-ux.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/app/api/brands.ts CHANGED
@@ -30,13 +30,16 @@ export const brandsApi = {
30
30
  apiClient<BrandCreateResponse>('/brands', {
31
31
  method: 'POST',
32
32
  body: data,
33
- }),
33
+
34
+ _skipErrorToast: true,
35
+ } as Record<string, unknown>),
34
36
 
35
37
  update: (id: string, data: BrandUpdateBody) =>
36
38
  apiClient<BrandFromDb>(`/brands/${id}`, {
37
39
  method: 'PUT',
38
40
  body: data,
39
- }),
41
+ _skipErrorToast: true,
42
+ } as Record<string, unknown>),
40
43
 
41
44
  delete: (id: string) => apiClient<BrandDeleteResponse>(`/brands/${id}`, { method: 'DELETE' }),
42
45
 
package/app/api/client.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { AppError } from '@dev.smartpricing/message-composer-utils/types'
2
2
  import { useAppContextStore } from '@/stores/appContext'
3
+ import { resolveErrorToast } from '~/composables/apiErrorMessages'
3
4
 
4
5
  function assertAppError(data: unknown): data is AppError {
5
6
  if (typeof data !== 'object' || data === null) {
@@ -41,20 +42,12 @@ export const apiClient = createApiClient({
41
42
  options.headers.set('sm-default-tags', store.default_tags.join(','))
42
43
  }
43
44
  },
44
- onResponseError({ response }) {
45
- const error = response._data
46
- if (assertAppError(error)) {
47
- useToast().add({
48
- color: 'error',
49
- title: error.code,
50
- description: error.message,
51
- })
52
- } else {
53
- useToast().add({
54
- color: 'error',
55
- title: 'Error',
56
- description: 'An error occurred',
57
- })
58
- }
45
+ onResponseError({ response, options }) {
46
+ if ((options as { _skipErrorToast?: boolean })._skipErrorToast) return
47
+
48
+ const t = useNuxtApp().$i18n.t
49
+ const code = assertAppError(response._data) ? response._data.code : undefined
50
+ const toast = resolveErrorToast({ status: response.status, code }, t)
51
+ useToast().add({ ...toast, color: 'error' })
59
52
  },
60
53
  })
@@ -1,17 +1,29 @@
1
1
  <script setup lang="ts">
2
- import type { RenderType } from '@dev.smartpricing/message-composer-utils/types'
2
+ import type { RenderType, MessageStatus } from '@dev.smartpricing/message-composer-utils/types'
3
3
  import { useMessageGroupsQuery } from '~/queries/messageGroups'
4
4
 
5
- defineOptions({ name: 'TemplateSelect' })
5
+ defineOptions({ name: 'MessageGroupSelect' })
6
6
 
7
7
  const props = withDefaults(
8
8
  defineProps<{
9
9
  renderType?: RenderType
10
10
  placeholder?: string
11
11
  searchPlaceholder?: string
12
+ /**
13
+ * Map of message-group id -> reason text explaining why the group is not
14
+ * selectable (e.g. already linked to another newsletter by an external
15
+ * system). Presence of a key disables the group; the value is shown verbatim
16
+ * as the tooltip, so it must already be localized by the caller.
17
+ *
18
+ * NOTE: the caller is responsible for excluding the currently-selected group
19
+ * when editing, otherwise the current selection will render as disabled.
20
+ */
21
+ disabledGroupReasons?: Record<string, string>
22
+ /** Overrides the "hide inactive" filter label. Defaults to the built-in translation. */
23
+ hideFilterLabel?: string
12
24
  }>(),
13
25
  {
14
- placeholder: 'Select a template',
26
+ placeholder: 'Select a message group',
15
27
  searchPlaceholder: 'Search...',
16
28
  },
17
29
  )
@@ -22,16 +34,48 @@ const emit = defineEmits<{
22
34
  select: [item: { id: string; name: string }]
23
35
  }>()
24
36
 
37
+ const { t } = useI18n()
38
+
25
39
  const { data: messageGroups, isLoading } = useMessageGroupsQuery(() => ({
26
40
  renderType: props.renderType,
27
41
  }))
28
42
 
43
+ const hideInactive = ref(false)
44
+
45
+ function isGroupActive(messages: Array<{ status: MessageStatus }>): boolean {
46
+ return messages.length > 0 && messages.every((m) => m.status === 'approved')
47
+ }
48
+
29
49
  const items = computed(() => {
30
50
  if (!messageGroups.value) return []
31
- return messageGroups.value.map((group) => ({
32
- label: group.name,
33
- value: group.id,
34
- }))
51
+ return messageGroups.value.reduce<
52
+ Array<{
53
+ label: string
54
+ value: string
55
+ disabled: boolean
56
+ tooltip?: string
57
+ chip: { color: 'success' | 'neutral' }
58
+ }>
59
+ >((acc, group) => {
60
+ const externalReason = props.disabledGroupReasons?.[group.id]
61
+ const externallyUsed = externalReason != null
62
+ const active = isGroupActive(group.messages)
63
+ const disabled = !active || externallyUsed
64
+ if (hideInactive.value && disabled) return acc
65
+ acc.push({
66
+ label: group.name,
67
+ value: group.id,
68
+ disabled,
69
+ // External reason wins over the inactive tooltip when both apply.
70
+ tooltip: externallyUsed
71
+ ? externalReason
72
+ : !active
73
+ ? t('common.messageGroupSelect.inactive_tooltip')
74
+ : undefined,
75
+ chip: { color: disabled ? 'neutral' : 'success' },
76
+ })
77
+ return acc
78
+ }, [])
35
79
  })
36
80
 
37
81
  function handleUpdate(value: string) {
@@ -50,7 +94,23 @@ function handleUpdate(value: string) {
50
94
  searchable
51
95
  :placeholder="placeholder"
52
96
  :search-input="{ placeholder: searchPlaceholder }"
53
- :data-testid="templateSelectTestIds.root"
97
+ :data-testid="messageGroupSelectTestIds.root"
54
98
  @update:model-value="handleUpdate"
55
- />
99
+ >
100
+ <template #item-label="{ item }">
101
+ <UTooltip v-if="item.disabled" :text="item.tooltip">
102
+ <span class="text-muted">{{ item.label }}</span>
103
+ </UTooltip>
104
+ <span v-else>{{ item.label }}</span>
105
+ </template>
106
+
107
+ <template #content-top>
108
+ <div class="flex items-center gap-2 px-2 py-1.5 border-b border-default">
109
+ <USwitch v-model="hideInactive" size="xs" />
110
+ <span class="text-xs text-muted">
111
+ {{ hideFilterLabel ?? t('common.messageGroupSelect.hide_inactive') }}
112
+ </span>
113
+ </div>
114
+ </template>
115
+ </USelectMenu>
56
116
  </template>
@@ -0,0 +1,26 @@
1
+ const CODE_TO_KEY: Record<string, string> = {
2
+ 'session.missing': 'common.errors.session_expired',
3
+ 'session.expired': 'common.errors.session_expired',
4
+ }
5
+
6
+ function descriptionKeyByStatus(status: number): string {
7
+ if (status === 403) return 'common.errors.forbidden'
8
+ if (status === 404) return 'common.errors.not_found'
9
+ if (status === 503) return 'common.errors.service_unavailable'
10
+ if (status >= 500) return 'common.errors.server_error'
11
+ return 'common.errors.generic'
12
+ }
13
+
14
+ export function resolveErrorToast(
15
+ error: { status: number; code?: string },
16
+ t: (key: string) => string,
17
+ ): { title: string; description: string; id: string } {
18
+ const descriptionKey =
19
+ (error.code && CODE_TO_KEY[error.code]) || descriptionKeyByStatus(error.status)
20
+
21
+ return {
22
+ title: t('common.error'),
23
+ description: t(descriptionKey),
24
+ id: `api-error-${error.status}-${error.code || 'unknown'}`,
25
+ }
26
+ }
@@ -738,6 +738,9 @@ export const previewByIdTestIds = {
738
738
  loading: 'preview-by-id-loading',
739
739
  } as const
740
740
 
741
- export const templateSelectTestIds = {
742
- root: 'template-select-root',
741
+ export const messageGroupSelectTestIds = {
742
+ root: 'message-group-select-root',
743
743
  } as const
744
+
745
+ /** @deprecated Use `messageGroupSelectTestIds` instead */
746
+ export const templateSelectTestIds = messageGroupSelectTestIds
@@ -21,6 +21,15 @@ export default {
21
21
  desktop: 'Desktop',
22
22
  error: 'Fehler',
23
23
  errore: 'Fehler',
24
+ errors: {
25
+ forbidden: 'Sie haben keine Berechtigung, diese Aktion auszuführen.',
26
+ generic: 'Ein unerwarteter Fehler ist aufgetreten. Bitte versuchen Sie es erneut.',
27
+ not_found: 'Die angeforderte Ressource wurde nicht gefunden.',
28
+ server_error: 'Ein Serverfehler ist aufgetreten. Bitte versuchen Sie es später erneut.',
29
+ service_unavailable:
30
+ 'Der Dienst ist vorübergehend nicht verfügbar. Bitte versuchen Sie es später erneut.',
31
+ session_expired: 'Ihre Sitzung ist abgelaufen. Bitte melden Sie sich erneut an.',
32
+ },
24
33
  imageUpload: {
25
34
  imageJpgPngOnly: 'Es werden nur JPG- und PNG-Bilddateien unterstützt.',
26
35
  mediaFileTooLarge: 'Die Datei ist zu groß. Maximale Größe: {maxSize}MB.',
@@ -45,6 +54,11 @@ export default {
45
54
  search: 'Suchen...',
46
55
  success: 'Erfolg',
47
56
  translation_failed: 'Übersetzung fehlgeschlagen',
57
+ messageGroupSelect: {
58
+ inactive_tooltip:
59
+ 'Diese Nachrichtengruppe enthält nicht genehmigte oder fehlende Nachrichten',
60
+ hide_inactive: 'Inaktive ausblenden',
61
+ },
48
62
  view_less: 'Weniger anzeigen',
49
63
  view_more: 'Mehr anzeigen',
50
64
  },
@@ -654,6 +668,7 @@ export default {
654
668
  button_bg_color: 'Hintergrund',
655
669
  button_text_color: 'Text',
656
670
  change_logo: 'Logo ändern',
671
+ colors: 'Farben',
657
672
  contact_address: 'Adresse',
658
673
  contact_address_placeholder: 'Z.B. Via Roma 1, 39100 Bolzano',
659
674
  contact_email: 'E-Mail',
@@ -664,7 +679,6 @@ export default {
664
679
  contact_telephone_placeholder: 'Z.B. +39 0471 123456',
665
680
  contact_website: 'Webseite',
666
681
  contact_website_placeholder: 'Z.B. https://www.hotel.com',
667
- colors: 'Farben',
668
682
  default_button_colors: 'Standard-Schaltflächen-Farben',
669
683
  default_email_colors: 'Standard-E-Mail-Farben',
670
684
  default_font: 'Standardschriftart',
@@ -21,6 +21,14 @@ export default {
21
21
  desktop: 'Desktop',
22
22
  error: 'Error',
23
23
  errore: 'Error',
24
+ errors: {
25
+ forbidden: "You don't have permission to perform this action.",
26
+ generic: 'An unexpected error occurred. Please try again.',
27
+ not_found: 'The requested resource was not found.',
28
+ server_error: 'A server error occurred. Please try again later.',
29
+ service_unavailable: 'The service is temporarily unavailable. Please try again later.',
30
+ session_expired: 'Your session has expired. Please log in again.',
31
+ },
24
32
  imageUpload: {
25
33
  imageJpgPngOnly: 'Only JPG and PNG image files are supported.',
26
34
  mediaFileTooLarge: 'File is too large. Maximum size: {maxSize}MB.',
@@ -45,6 +53,10 @@ export default {
45
53
  search: 'Search...',
46
54
  success: 'Success',
47
55
  translation_failed: 'Translation failed',
56
+ messageGroupSelect: {
57
+ inactive_tooltip: 'This message group has unapproved or missing messages',
58
+ hide_inactive: 'Hide inactive',
59
+ },
48
60
  view_less: 'View less',
49
61
  view_more: 'View more',
50
62
  },
@@ -645,6 +657,7 @@ export default {
645
657
  button_bg_color: 'Background',
646
658
  button_text_color: 'Text',
647
659
  change_logo: 'Change logo',
660
+ colors: 'Brand colors',
648
661
  contact_address: 'Address',
649
662
  contact_address_placeholder: 'E.g. Via Roma 1, 39100 Bolzano',
650
663
  contact_email: 'Email',
@@ -655,7 +668,6 @@ export default {
655
668
  contact_telephone_placeholder: 'E.g. +39 0471 123456',
656
669
  contact_website: 'Website',
657
670
  contact_website_placeholder: 'E.g. https://www.hotel.com',
658
- colors: 'Brand colors',
659
671
  default_button_colors: 'Default button colors',
660
672
  default_email_colors: 'Default email colors',
661
673
  default_font: 'Default font',
@@ -21,6 +21,15 @@ export default {
21
21
  desktop: 'Escritorio',
22
22
  error: 'Error',
23
23
  errore: 'Error',
24
+ errors: {
25
+ forbidden: 'No tienes permiso para realizar esta acción.',
26
+ generic: 'Se ha producido un error inesperado. Inténtalo de nuevo.',
27
+ not_found: 'El recurso solicitado no fue encontrado.',
28
+ server_error: 'Se ha producido un error en el servidor. Inténtalo de nuevo más tarde.',
29
+ service_unavailable:
30
+ 'El servicio no está disponible temporalmente. Inténtalo de nuevo más tarde.',
31
+ session_expired: 'Tu sesión ha expirado. Inicia sesión de nuevo.',
32
+ },
24
33
  imageUpload: {
25
34
  imageJpgPngOnly: 'Solo se admiten archivos de imagen JPG y PNG.',
26
35
  mediaFileTooLarge: 'El archivo es demasiado grande. Tamaño máximo: {maxSize}MB.',
@@ -45,6 +54,10 @@ export default {
45
54
  search: 'Buscar...',
46
55
  success: 'Éxito',
47
56
  translation_failed: 'La traducción ha fallado',
57
+ messageGroupSelect: {
58
+ inactive_tooltip: 'Este grupo de mensajes tiene mensajes no aprobados o faltantes',
59
+ hide_inactive: 'Ocultar inactivos',
60
+ },
48
61
  view_less: 'Ver menos',
49
62
  view_more: 'Ver más',
50
63
  },
@@ -653,6 +666,7 @@ export default {
653
666
  button_bg_color: 'Fondo',
654
667
  button_text_color: 'Texto',
655
668
  change_logo: 'Cambiar logo',
669
+ colors: 'Colores',
656
670
  contact_address: 'Dirección',
657
671
  contact_address_placeholder: 'Ej. Via Roma 1, 39100 Bolzano',
658
672
  contact_email: 'Email',
@@ -663,7 +677,6 @@ export default {
663
677
  contact_telephone_placeholder: 'Ej. +39 0471 123456',
664
678
  contact_website: 'Sitio web',
665
679
  contact_website_placeholder: 'Ej. https://www.hotel.com',
666
- colors: 'Colores',
667
680
  default_button_colors: 'Colores de botón predeterminados',
668
681
  default_email_colors: 'Colores de correo predeterminados',
669
682
  default_font: 'Fuente predeterminada',
@@ -21,6 +21,15 @@ export default {
21
21
  desktop: 'Bureau',
22
22
  error: 'Erreur',
23
23
  errore: 'Erreur',
24
+ errors: {
25
+ forbidden: "Vous n'avez pas la permission d'effectuer cette action.",
26
+ generic: 'Une erreur inattendue est survenue. Veuillez réessayer.',
27
+ not_found: "La ressource demandée n'a pas été trouvée.",
28
+ server_error: 'Une erreur serveur est survenue. Veuillez réessayer plus tard.',
29
+ service_unavailable:
30
+ 'Le service est temporairement indisponible. Veuillez réessayer plus tard.',
31
+ session_expired: 'Votre session a expiré. Veuillez vous reconnecter.',
32
+ },
24
33
  imageUpload: {
25
34
  imageJpgPngOnly: 'Seuls les fichiers image JPG et PNG sont pris en charge.',
26
35
  mediaFileTooLarge: 'Le fichier est trop volumineux. Taille maximale : {maxSize} Mo.',
@@ -45,6 +54,10 @@ export default {
45
54
  search: 'Rechercher...',
46
55
  success: 'Succès',
47
56
  translation_failed: 'Échec de la traduction',
57
+ messageGroupSelect: {
58
+ inactive_tooltip: 'Ce groupe de messages contient des messages non approuvés ou manquants',
59
+ hide_inactive: 'Masquer inactifs',
60
+ },
48
61
  view_less: 'Afficher moins',
49
62
  view_more: 'Afficher plus',
50
63
  },
@@ -657,6 +670,7 @@ export default {
657
670
  button_bg_color: 'Fond',
658
671
  button_text_color: 'Texte',
659
672
  change_logo: 'Changer le logo',
673
+ colors: 'Couleurs',
660
674
  contact_address: 'Adresse',
661
675
  contact_address_placeholder: 'Ex. Via Roma 1, 39100 Bolzano',
662
676
  contact_email: 'Email',
@@ -667,7 +681,6 @@ export default {
667
681
  contact_telephone_placeholder: 'Ex. +39 0471 123456',
668
682
  contact_website: 'Site web',
669
683
  contact_website_placeholder: 'Ex. https://www.hotel.com',
670
- colors: 'Couleurs',
671
684
  default_button_colors: 'Couleurs de bouton par défaut',
672
685
  default_email_colors: "Couleurs d'e-mail par défaut",
673
686
  default_font: 'Police par défaut',
@@ -21,6 +21,14 @@ export default {
21
21
  desktop: 'Desktop',
22
22
  error: 'Errore',
23
23
  errore: 'Errore',
24
+ errors: {
25
+ forbidden: 'Non hai i permessi per eseguire questa azione.',
26
+ generic: 'Si è verificato un errore imprevisto. Riprova.',
27
+ not_found: 'La risorsa richiesta non è stata trovata.',
28
+ server_error: 'Si è verificato un errore del server. Riprova più tardi.',
29
+ service_unavailable: 'Il servizio è temporaneamente non disponibile. Riprova più tardi.',
30
+ session_expired: "La sessione è scaduta. Effettua nuovamente l'accesso.",
31
+ },
24
32
  imageUpload: {
25
33
  imageJpgPngOnly: 'Sono supportati solo file immagine JPG e PNG.',
26
34
  mediaFileTooLarge: 'Il file è troppo grande. Dimensione massima: {maxSize}MB.',
@@ -45,6 +53,10 @@ export default {
45
53
  search: 'Cerca...',
46
54
  success: 'Successo',
47
55
  translation_failed: 'Traduzione non riuscita',
56
+ messageGroupSelect: {
57
+ inactive_tooltip: 'Questo gruppo di messaggi contiene messaggi non approvati o mancanti',
58
+ hide_inactive: 'Nascondi inattivi',
59
+ },
48
60
  view_less: 'Mostra meno',
49
61
  view_more: 'Mostra di più',
50
62
  },
@@ -651,6 +663,7 @@ export default {
651
663
  button_bg_color: 'Sfondo',
652
664
  button_text_color: 'Testo',
653
665
  change_logo: 'Cambia logo',
666
+ colors: 'Colori',
654
667
  contact_address: 'Indirizzo',
655
668
  contact_address_placeholder: 'Es. Via Roma 1, 39100 Bolzano',
656
669
  contact_email: 'Email',
@@ -661,7 +674,6 @@ export default {
661
674
  contact_telephone_placeholder: 'Es. +39 0471 123456',
662
675
  contact_website: 'Sito web',
663
676
  contact_website_placeholder: 'Es. https://www.hotel.com',
664
- colors: 'Colori',
665
677
  default_button_colors: 'Colori pulsante predefiniti',
666
678
  default_email_colors: 'Colori email predefiniti',
667
679
  default_font: 'Font predefinito',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev.smartpricing/message-composer-layer",
3
- "version": "4.2.9",
3
+ "version": "4.2.11-ux.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -36,7 +36,7 @@
36
36
  "vue-router": "^5.0.7",
37
37
  "vue3-emoji-picker": "^1.1.8",
38
38
  "zod": "^4.4.3",
39
- "@dev.smartpricing/message-composer-utils": "4.2.9"
39
+ "@dev.smartpricing/message-composer-utils": "4.2.11-ux.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@nuxt/eslint": "^1.15.2",