@dev.smartpricing/message-composer-layer 5.0.11 → 5.0.12

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.
@@ -29,6 +29,8 @@ import PhoneInput from '@/components/Common/PhoneInput.vue'
29
29
  import { z } from 'zod'
30
30
  import {
31
31
  VALID_PHONE_NUMBER_REGEX,
32
+ areWhatsappButtonsGrouped,
33
+ groupWhatsappButtons,
32
34
  isValidUrl,
33
35
  } from '@dev.smartpricing/message-composer-utils/utils'
34
36
 
@@ -44,6 +46,7 @@ const emit = defineEmits<{
44
46
  buttonAdded: [button: WaButtonV1]
45
47
  buttonRemoved: [buttonId: string]
46
48
  buttonTypeChanged: [button: WaButtonV1]
49
+ buttonsReordered: [buttonIds: string[]]
47
50
  }>()
48
51
 
49
52
  const { t } = useI18n()
@@ -154,6 +157,16 @@ function updateButtonType(button: WaButtonV1, index: number, type: WaButtonTypeV
154
157
  emit('buttonTypeChanged', button)
155
158
  }
156
159
 
160
+ const buttonsGrouped = computed(() => areWhatsappButtonsGrouped(model.value.buttons))
161
+
162
+ function reorderButtons() {
163
+ model.value.buttons = groupWhatsappButtons(model.value.buttons)
164
+ emit(
165
+ 'buttonsReordered',
166
+ model.value.buttons.map((button) => button.id),
167
+ )
168
+ }
169
+
157
170
  const phoneButtonCount = computed(
158
171
  () => model.value.buttons.filter((btn) => btn.type === 'phone').length,
159
172
  )
@@ -241,7 +254,26 @@ watch(
241
254
  </div>
242
255
  </section>
243
256
 
244
- <!-- Add Button Dropdown -->
257
+ <UAlert
258
+ v-if="!buttonsGrouped"
259
+ class="mb-4"
260
+ color="error"
261
+ variant="soft"
262
+ icon="ph:warning-circle-bold"
263
+ :title="t('editor.whatsapp.buttons.groups_mixed.title')"
264
+ :description="t('editor.whatsapp.buttons.groups_mixed.description')"
265
+ :data-testid="whatsappEditorButtonsTestIds.groupsMixedAlert"
266
+ :actions="[
267
+ {
268
+ label: t('editor.whatsapp.buttons.groups_mixed.reorder'),
269
+ color: 'error',
270
+ variant: 'outline',
271
+ size: 'sm',
272
+ 'data-testid': whatsappEditorButtonsTestIds.reorderButton,
273
+ onClick: reorderButtons,
274
+ },
275
+ ]"
276
+ />
245
277
 
246
278
  <!-- Button Configuration Grid -->
247
279
  <div class="space-y-4">
@@ -18,6 +18,7 @@ const emit = defineEmits<{
18
18
  buttonAdded: [button: WaButtonV1]
19
19
  buttonRemoved: [buttonId: string]
20
20
  buttonTypeChanged: [button: WaButtonV1]
21
+ buttonsReordered: [buttonIds: string[]]
21
22
  headerTypeChanged: [header: HeaderBlockV1]
22
23
  headerMediaChanged: [payload: { header: HeaderBlockV1; previousUrl: string }]
23
24
  footerEnabledChanged: [enabled: boolean]
@@ -85,6 +86,7 @@ const bodyGenerateContext = computed(() => {
85
86
  @button-added="emit('buttonAdded', $event)"
86
87
  @button-removed="emit('buttonRemoved', $event)"
87
88
  @button-type-changed="emit('buttonTypeChanged', $event)"
89
+ @buttons-reordered="emit('buttonsReordered', $event)"
88
90
  />
89
91
  </div>
90
92
  </template>
@@ -22,6 +22,33 @@ const props = defineProps<Props>()
22
22
 
23
23
  const model = defineModel<WhatsappMessage>({ required: true })
24
24
 
25
+ /**
26
+ * Gives every other language the main language's button order
27
+ */
28
+ function handleButtonsReordered(buttonIds: string[]) {
29
+ // A message has at most one unsubscribe button: match it by type when older
30
+ // data gave it a different ID in a translation
31
+ const unsubscribeIndex = model.value.body.buttons.buttons.findIndex(
32
+ (btn) => btn.type === 'unsubscribe',
33
+ )
34
+ const position = (button: WaButtonV1) => {
35
+ const index = buttonIds.indexOf(button.id)
36
+ if (index !== -1) return index
37
+ if (button.type === 'unsubscribe' && unsubscribeIndex !== -1) return unsubscribeIndex
38
+ return buttonIds.length
39
+ }
40
+ for (const langId in props.messages) {
41
+ if (langId === props.mainLanguageId) continue
42
+
43
+ const targetMsg = props.messages[langId]
44
+ if (!targetMsg?.body?.buttons) continue
45
+
46
+ targetMsg.body.buttons.buttons = [...targetMsg.body.buttons.buttons].sort(
47
+ (a, b) => position(a) - position(b),
48
+ )
49
+ }
50
+ }
51
+
25
52
  /**
26
53
  * Syncs button addition to all other languages
27
54
  */
@@ -164,6 +191,7 @@ function handleFooterEnabledChanged(enabled: boolean) {
164
191
  @button-added="handleButtonAdded"
165
192
  @button-removed="handleButtonRemoved"
166
193
  @button-type-changed="handleButtonTypeChanged"
194
+ @buttons-reordered="handleButtonsReordered"
167
195
  @header-type-changed="handleHeaderTypeChanged"
168
196
  @header-media-changed="handleHeaderMediaChanged"
169
197
  @footer-enabled-changed="handleFooterEnabledChanged"
@@ -372,6 +372,8 @@ export const whatsappEditorButtonsTestIds = {
372
372
  buttonUrlField: 'whatsapp-editor-buttons-url-field',
373
373
  buttonUrlInput: 'whatsapp-editor-buttons-url-input',
374
374
  buttonRemoveButton: 'whatsapp-editor-buttons-remove-button',
375
+ groupsMixedAlert: 'whatsapp-editor-buttons-groups-mixed-alert',
376
+ reorderButton: 'whatsapp-editor-buttons-reorder-button',
375
377
  } as const
376
378
 
377
379
  export const whatsappEditorFooterTestIds = {
@@ -805,8 +805,10 @@ export default {
805
805
  bodyRequired: 'Nachrichtentext ist erforderlich',
806
806
  bodyTooLong: 'Text überschreitet 1024 Zeichen',
807
807
  buttonFontSizeInvalid: 'Schaltflächen-Schriftgröße muss zwischen 12 und 32 Pixeln liegen',
808
+ buttonGroupsMixed:
809
+ 'Schnellantwort-Schaltflächen müssen zusammen vor oder nach den anderen Schaltflächen stehen',
808
810
  buttonTextRequired: 'Button-Text ist erforderlich',
809
- buttonTextTooLong: 'Schaltflächentext überschreitet 20 Zeichen',
811
+ buttonTextTooLong: 'Schaltflächentext überschreitet 25 Zeichen',
810
812
  discountFontSizeInvalid: 'Rabatt-Schriftgröße muss zwischen 12 und 48 Pixeln liegen',
811
813
  dividerThicknessInvalid: 'Linienstärke muss zwischen 1 und 20 Pixeln liegen',
812
814
  dividerWidthInvalid: 'Linienbreite muss zwischen 10% und 100% liegen',
@@ -824,9 +826,9 @@ export default {
824
826
  imageWidthInvalid: 'Bildbreite muss zwischen 50 und 600 Pixeln liegen',
825
827
  invalidRenderType: 'Ungültiger Nachrichtentyp',
826
828
  maxButtons: 'Maximal 10 Schaltflächen erlaubt',
827
- maxLinkButtons: 'Maximal 1 Link-Schaltfläche erlaubt',
829
+ maxLinkButtons: 'Maximal 2 Link-Schaltflächen erlaubt',
828
830
  maxPhoneButtons: 'Maximal 1 Telefon-Schaltfläche erlaubt',
829
- maxQuickReplyButtons: 'Maximal 3 Schnellantwort-Schaltflächen erlaubt',
831
+ maxQuickReplyButtons: 'Maximal 10 Schnellantwort-Schaltflächen erlaubt',
830
832
  maxUnsubscribeButtons: 'Maximal 1 Abmelden-Schaltfläche erlaubt',
831
833
  messageRequired: 'Mindestens eine Sprache ist erforderlich',
832
834
  nameRequired: 'Name ist erforderlich',
@@ -883,6 +885,12 @@ export default {
883
885
  'Die Schaltfläche <b>Schnellantwort</b> ermöglicht es Nutzerinnen und Nutzern, zwischen einer oder mehreren vordefinierten Optionen zu wählen, ohne Text eingeben zu müssen. Das macht das Gespräch flüssiger und geführter.',
884
886
  description_unsubscribe:
885
887
  'Die Schaltfläche <b>Abmelden</b> ermöglicht es Nutzerinnen und Nutzern, den Erhalt zukünftiger Nachrichten Ihres Unternehmens abzubestellen. Für Marketingnachrichten wird sie dringend empfohlen.',
888
+ groups_mixed: {
889
+ title: 'Schnellantwort-Schaltflächen sind getrennt',
890
+ description:
891
+ 'WhatsApp akzeptiert Schnellantwort- und Abmelden-Schaltflächen nur, wenn sie zusammen vor oder nach den anderen Schaltflächen stehen.',
892
+ reorder: 'Neu anordnen',
893
+ },
886
894
  placeholders: {
887
895
  phone: 'Telefonnummer',
888
896
  text: 'Schaltflächentext',
@@ -783,8 +783,10 @@ export default {
783
783
  bodyRequired: 'Message body is required',
784
784
  bodyTooLong: 'Body text exceeds 1024 characters',
785
785
  buttonFontSizeInvalid: 'Button font size must be between 12 and 32 pixels',
786
+ buttonGroupsMixed:
787
+ 'Quick reply buttons must be placed together, before or after the other buttons',
786
788
  buttonTextRequired: 'Button text is required',
787
- buttonTextTooLong: 'Button text exceeds 20 characters',
789
+ buttonTextTooLong: 'Button text exceeds 25 characters',
788
790
  discountFontSizeInvalid: 'Discount font size must be between 12 and 48 pixels',
789
791
  dividerThicknessInvalid: 'Divider thickness must be between 1 and 20 pixels',
790
792
  dividerWidthInvalid: 'Divider width must be between 10% and 100%',
@@ -801,9 +803,9 @@ export default {
801
803
  imageWidthInvalid: 'Image width must be between 50 and 600 pixels',
802
804
  invalidRenderType: 'Invalid message type',
803
805
  maxButtons: 'Maximum 10 buttons allowed',
804
- maxLinkButtons: 'Maximum 1 link button allowed',
806
+ maxLinkButtons: 'Maximum 2 link buttons allowed',
805
807
  maxPhoneButtons: 'Maximum 1 phone button allowed',
806
- maxQuickReplyButtons: 'Maximum 3 quick reply buttons allowed',
808
+ maxQuickReplyButtons: 'Maximum 10 quick reply buttons allowed',
807
809
  maxUnsubscribeButtons: 'Maximum 1 unsubscribe button allowed',
808
810
  messageRequired: 'At least one language is required',
809
811
  nameRequired: 'Name is required',
@@ -857,6 +859,12 @@ export default {
857
859
  '<b>Quick reply</b> button lets users choose between one or more predefined options without having to type text, making the conversation more fluid and guided.',
858
860
  description_unsubscribe:
859
861
  "<b>Unsubscribe</b> button lets users opt out of receiving future messages from your business. It's strongly recommended for marketing messages.",
862
+ groups_mixed: {
863
+ title: 'Quick reply buttons are split up',
864
+ description:
865
+ 'WhatsApp only accepts quick reply and unsubscribe buttons placed together, before or after the other buttons.',
866
+ reorder: 'Reorder',
867
+ },
860
868
  placeholders: {
861
869
  phone: 'Phone number',
862
870
  text: 'Button text',
@@ -789,8 +789,10 @@ export default {
789
789
  bodyRequired: 'Se requiere el cuerpo del mensaje',
790
790
  bodyTooLong: 'El texto supera los 1024 caracteres',
791
791
  buttonFontSizeInvalid: 'El tamaño de fuente del botón debe estar entre 12 y 32 píxeles',
792
+ buttonGroupsMixed:
793
+ 'Los botones de respuesta rápida deben ir juntos, antes o después de los demás botones',
792
794
  buttonTextRequired: 'El texto del botón es obligatorio',
793
- buttonTextTooLong: 'El texto del botón supera los 20 caracteres',
795
+ buttonTextTooLong: 'El texto del botón supera los 25 caracteres',
794
796
  discountFontSizeInvalid:
795
797
  'El tamaño de fuente del descuento debe estar entre 12 y 48 píxeles',
796
798
  dividerThicknessInvalid: 'El grosor del separador debe estar entre 1 y 20 píxeles',
@@ -809,9 +811,9 @@ export default {
809
811
  imageWidthInvalid: 'El ancho de la imagen debe estar entre 50 y 600 píxeles',
810
812
  invalidRenderType: 'Tipo de mensaje inválido',
811
813
  maxButtons: 'Máximo 10 botones permitidos',
812
- maxLinkButtons: 'Máximo 1 botón de enlace permitido',
814
+ maxLinkButtons: 'Máximo 2 botones de enlace permitidos',
813
815
  maxPhoneButtons: 'Máximo 1 botón de teléfono permitido',
814
- maxQuickReplyButtons: 'Máximo 3 botones de respuesta rápida permitidos',
816
+ maxQuickReplyButtons: 'Máximo 10 botones de respuesta rápida permitidos',
815
817
  maxUnsubscribeButtons: 'Máximo 1 botón de cancelación de suscripción permitido',
816
818
  messageRequired: 'Se requiere al menos un idioma',
817
819
  nameRequired: 'Se requiere el nombre',
@@ -869,6 +871,12 @@ export default {
869
871
  'El botón <b>Respuesta rápida</b> permite a los usuarios elegir entre una o más opciones predefinidas sin tener que escribir texto, haciendo la conversación más fluida y guiada.',
870
872
  description_unsubscribe:
871
873
  'El botón <b>Cancelar suscripción</b> permite a los usuarios darse de baja de futuros mensajes de tu empresa. Se recomienda encarecidamente para mensajes de marketing.',
874
+ groups_mixed: {
875
+ title: 'Los botones de respuesta rápida están separados',
876
+ description:
877
+ 'WhatsApp solo acepta los botones de respuesta rápida y de cancelación de suscripción si van juntos, antes o después de los demás botones.',
878
+ reorder: 'Reordenar',
879
+ },
872
880
  placeholders: {
873
881
  phone: 'Número de teléfono',
874
882
  text: 'Texto del botón',
@@ -797,8 +797,10 @@ export default {
797
797
  bodyTooLong: 'Le texte dépasse 1024 caractères',
798
798
  buttonFontSizeInvalid:
799
799
  'La taille de police du bouton doit être comprise entre 12 et 32 pixels',
800
+ buttonGroupsMixed:
801
+ 'Les boutons de réponse rapide doivent être regroupés, avant ou après les autres boutons',
800
802
  buttonTextRequired: 'Le texte du bouton est requis',
801
- buttonTextTooLong: 'Le texte du bouton dépasse 20 caractères',
803
+ buttonTextTooLong: 'Le texte du bouton dépasse 25 caractères',
802
804
  discountFontSizeInvalid:
803
805
  'La taille de police de la remise doit être comprise entre 12 et 48 pixels',
804
806
  dividerThicknessInvalid:
@@ -819,9 +821,9 @@ export default {
819
821
  imageWidthInvalid: 'La largeur de l’image doit être comprise entre 50 et 600 pixels',
820
822
  invalidRenderType: 'Type de message invalide',
821
823
  maxButtons: 'Maximum de 10 boutons autorisés',
822
- maxLinkButtons: 'Maximum de 1 bouton lien autorisé',
824
+ maxLinkButtons: 'Maximum de 2 boutons lien autorisés',
823
825
  maxPhoneButtons: 'Maximum de 1 bouton téléphone autorisé',
824
- maxQuickReplyButtons: 'Maximum de 3 boutons de réponse rapide autorisés',
826
+ maxQuickReplyButtons: 'Maximum de 10 boutons de réponse rapide autorisés',
825
827
  maxUnsubscribeButtons: 'Maximum de 1 bouton de désinscription autorisé',
826
828
  messageRequired: 'Au moins une langue est requise',
827
829
  nameRequired: 'Le nom est requis',
@@ -879,6 +881,12 @@ export default {
879
881
  'Le bouton <b>Réponse rapide</b> permet aux utilisateurs de choisir parmi une ou plusieurs options prédéfinies sans avoir à saisir de texte, rendant la conversation plus fluide et guidée.',
880
882
  description_unsubscribe:
881
883
  'Le bouton <b>Désinscription</b> permet aux utilisateurs de se désinscrire de la réception de futurs messages de votre entreprise. Il est fortement recommandé pour les messages marketing.',
884
+ groups_mixed: {
885
+ title: 'Les boutons de réponse rapide sont séparés',
886
+ description:
887
+ 'WhatsApp n’accepte les boutons de réponse rapide et de désabonnement que s’ils sont regroupés, avant ou après les autres boutons.',
888
+ reorder: 'Réorganiser',
889
+ },
882
890
  placeholders: {
883
891
  phone: 'Numéro de téléphone',
884
892
  text: 'Texte du bouton',
@@ -792,8 +792,10 @@ export default {
792
792
  bodyRequired: 'Il corpo del messaggio è obbligatorio',
793
793
  bodyTooLong: 'Il testo supera i 1024 caratteri',
794
794
  buttonFontSizeInvalid: 'La dimensione del pulsante deve essere tra 12 e 32 pixel',
795
+ buttonGroupsMixed:
796
+ 'I pulsanti di risposta rapida devono stare insieme, prima o dopo gli altri pulsanti',
795
797
  buttonTextRequired: 'Il testo del pulsante è obbligatorio',
796
- buttonTextTooLong: 'Il testo del pulsante supera i 20 caratteri',
798
+ buttonTextTooLong: 'Il testo del pulsante supera i 25 caratteri',
797
799
  discountFontSizeInvalid: 'La dimensione dello sconto deve essere tra 12 e 48 pixel',
798
800
  dividerThicknessInvalid: 'Lo spessore del divider deve essere tra 1 e 20 pixel',
799
801
  dividerWidthInvalid: 'La larghezza del divider deve essere tra 10% e 100%',
@@ -811,9 +813,9 @@ export default {
811
813
  imageWidthInvalid: 'La larghezza dell’immagine deve essere tra 50 e 600 pixel',
812
814
  invalidRenderType: 'Tipo di messaggio non valido',
813
815
  maxButtons: 'Massimo 10 pulsanti consentiti',
814
- maxLinkButtons: 'Massimo 1 pulsante link consentito',
816
+ maxLinkButtons: 'Massimo 2 pulsanti link consentiti',
815
817
  maxPhoneButtons: 'Massimo 1 pulsante telefono consentito',
816
- maxQuickReplyButtons: 'Massimo 3 pulsanti di risposta rapida consentiti',
818
+ maxQuickReplyButtons: 'Massimo 10 pulsanti di risposta rapida consentiti',
817
819
  maxUnsubscribeButtons: 'Massimo 1 pulsante di disiscrizione consentito',
818
820
  messageRequired: 'È richiesta almeno una lingua',
819
821
  nameRequired: 'Il nome è obbligatorio',
@@ -870,6 +872,12 @@ export default {
870
872
  'Il pulsante <b>Risposta rapida</b> consente agli utenti di scegliere tra una o più opzioni predefinite senza dover digitare testo, rendendo la conversazione più fluida e guidata.',
871
873
  description_unsubscribe:
872
874
  'Il pulsante <b>Disiscriviti</b> consente agli utenti di rinunciare a ricevere futuri messaggi dalla tua azienda. È fortemente consigliato per i messaggi marketing.',
875
+ groups_mixed: {
876
+ title: 'I pulsanti di risposta rapida sono separati',
877
+ description:
878
+ 'WhatsApp accetta i pulsanti di risposta rapida e di disiscrizione solo se stanno insieme, prima o dopo gli altri pulsanti.',
879
+ reorder: 'Riordina',
880
+ },
873
881
  placeholders: {
874
882
  phone: 'Numero di telefono',
875
883
  text: 'Testo pulsante',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev.smartpricing/message-composer-layer",
3
- "version": "5.0.11",
3
+ "version": "5.0.12",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -35,7 +35,7 @@
35
35
  "vue-router": "^5.0.7",
36
36
  "vue3-emoji-picker": "^1.1.8",
37
37
  "zod": "^4.4.3",
38
- "@dev.smartpricing/message-composer-utils": "5.0.11"
38
+ "@dev.smartpricing/message-composer-utils": "5.0.12"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@dev.smartpricing/platform-layer": "^0.0.23",