Skip to content

Commit

Permalink
feat: display error when button has variables
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobernardoaf committed Nov 6, 2023
1 parent 47a1d61 commit b1dca46
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/components/BaseInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
:label="label"
:placeholder="placeholder"
:maxlength="maxlength"
:message="message"
:type="type"
/>
</template>

Expand Down Expand Up @@ -33,6 +35,17 @@
type: Number,
default: 25,
},
message: {
type: String,
default: null,
},
type: {
type: String,
default: 'normal',
validator(value) {
return ['normal', 'error'].indexOf(value) !== -1;
},
},
replaceRegex: {
type: RegExp,
default: null,
Expand Down
10 changes: 9 additions & 1 deletion src/components/whatsAppTemplates/FormTabContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@
value: false,
message: '',
},
buttons: {
value: false,
message: '',
},
},
};
},
Expand Down Expand Up @@ -242,7 +246,11 @@
}
this.updateTemplateForm({ fieldName, fieldValue });
},
handleGenericInput({ fieldName, fieldValue }) {
handleGenericInput({ fieldName, fieldValue, hasIssue = false }) {
if (hasIssue) {
this.errorStates[fieldName].value = true;
}
this.updateTemplateTranslationForm({
formName: this.selectedForm,
fieldName,
Expand Down
28 changes: 28 additions & 0 deletions src/components/whatsAppTemplates/FormTabContentButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
:placeholder="$t('WhatsApp.templates.form_field.button_text_placeholder')"
:maxlength="25"
:replaceRegex="EMOJI_REGEX"
:message="errors[index] || null"
:type="errors[index] ? 'error' : 'normal'"
@input="handleRepliesInput($event, index)"
/>
</div>
Expand Down Expand Up @@ -201,6 +203,7 @@
<script>
import { mapGetters } from 'vuex';
import { getCountries, getCountryCallingCode } from 'libphonenumber-js';
import { countVariables } from '@/utils/countTemplateVariables.js';
import BaseInput from '../BaseInput.vue';
export default {
Expand Down Expand Up @@ -247,6 +250,7 @@
}),
buttons: [],
errors: {},
maxRepliesButtons: 3,
maxActionButtons: 2,
focusedUrlInput: false,
Expand Down Expand Up @@ -286,6 +290,16 @@
},
methods: {
getCountryCallingCode,
checkIssues() {
let hasIssues = false;
for (const key in this.errors) {
if (this.errors[key]) {
hasIssues = true;
}
}
return hasIssues;
},
handleButtonTypeChange(event) {
if (event === this.buttonsType) {
return;
Expand All @@ -309,10 +323,17 @@
this.$emit('input-change', { fieldName: 'buttonsType', fieldValue: event });
},
handleRepliesInput(event, index) {
if (countVariables(event) > 0) {
this.errors[index] = this.$t('WhatsApp.templates.form_field.error_has_variable');
} else {
this.errors[index] = null;
}
this.buttons[index].text = event;
this.$emit('input-change', {
fieldName: 'buttons',
fieldValue: [...this.buttons],
hasIssue: this.checkIssues(),
});
},
handleCallToActionTypeChange(event, index) {
Expand All @@ -337,10 +358,17 @@
});
},
handleActionInput(event, inputName, index) {
if (countVariables(event) > 0) {
this.errors[index] = this.$t('WhatsApp.templates.form_field.error_has_variable');
} else {
this.errors[index] = null;
}
this.buttons[index][inputName] = event;
this.$emit('input-change', {
fieldName: 'buttons',
fieldValue: [...this.buttons],
hasIssue: this.checkIssues(),
});
},
handleCountryCodeSelection(event, index) {
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@
"button_text": "Button text",
"phone_number_placeholder": "Enter the phone number",
"url_placeholder": "Enter the Website URL",
"footer_text_placeholder": "Enter the footer text"
"footer_text_placeholder": "Enter the footer text",
"error_has_variable": "Template buttons cannot contain variables"
},
"category_options": {
"marketing": "Marketing",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/es_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@
"button_text": "Texto del botón",
"phone_number_placeholder": "Ingrese el número de teléfono",
"url_placeholder": "Ingrese la URL del sitio web",
"footer_text_placeholder": "Escribe el texto de pie de página"
"footer_text_placeholder": "Escribe el texto de pie de página",
"error_has_variable": "Los botones de plantilla no pueden contener variables"
},
"category_options": {
"marketing": "Marketing",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@
"button_text": "Texto do botão",
"phone_number_placeholder": "Escreva o número de telefone",
"url_placeholder": "Escreva a URL do website",
"footer_text_placeholder": "Escreva o texto do rodapé"
"footer_text_placeholder": "Escreva o texto do rodapé",
"error_has_variable": "Os botões de modelo não podem conter variáveis"
},
"category_options": {
"marketing": "Marketing",
Expand Down

0 comments on commit b1dca46

Please sign in to comment.