feat: Adds number validation for WhatsApp inbox at the creation step (#6043)

Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
This commit is contained in:
Sivin Varghese 2022-12-13 09:22:37 +05:30 committed by GitHub
parent 86958278cd
commit 9d78f0d6c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 13 deletions

View file

@ -134,7 +134,7 @@
"PHONE_NUMBER": { "PHONE_NUMBER": {
"LABEL": "Phone number", "LABEL": "Phone number",
"PLACEHOLDER": "Please enter the phone number from which message will be sent.", "PLACEHOLDER": "Please enter the phone number from which message will be sent.",
"ERROR": "Please enter a valid value. Phone number should start with `+` sign." "ERROR": "Please provide a valid phone number that starts with a `+` sign and does not contain any spaces."
}, },
"API_CALLBACK": { "API_CALLBACK": {
"TITLE": "Callback URL", "TITLE": "Callback URL",
@ -185,7 +185,7 @@
"PHONE_NUMBER": { "PHONE_NUMBER": {
"LABEL": "Phone number", "LABEL": "Phone number",
"PLACEHOLDER": "Please enter the phone number from which message will be sent.", "PLACEHOLDER": "Please enter the phone number from which message will be sent.",
"ERROR": "Please enter a valid value. Phone number should start with `+` sign." "ERROR": "Please provide a valid phone number that starts with a `+` sign and does not contain any spaces."
}, },
"SUBMIT_BUTTON": "Create Bandwidth Channel", "SUBMIT_BUTTON": "Create Bandwidth Channel",
"API": { "API": {
@ -214,7 +214,7 @@
"PHONE_NUMBER": { "PHONE_NUMBER": {
"LABEL": "Phone number", "LABEL": "Phone number",
"PLACEHOLDER": "Please enter the phone number from which message will be sent.", "PLACEHOLDER": "Please enter the phone number from which message will be sent.",
"ERROR": "Please enter a valid value. Phone number should start with `+` sign." "ERROR": "Please provide a valid phone number that starts with a `+` sign and does not contain any spaces."
}, },
"PHONE_NUMBER_ID": { "PHONE_NUMBER_ID": {
"LABEL": "Phone number ID", "LABEL": "Phone number ID",

View file

@ -62,7 +62,7 @@ import alertMixin from 'shared/mixins/alertMixin';
import { required } from 'vuelidate/lib/validators'; import { required } from 'vuelidate/lib/validators';
import router from '../../../../index'; import router from '../../../../index';
const shouldStartWithPlusSign = (value = '') => value.startsWith('+'); import { isPhoneE164OrEmpty } from 'shared/helpers/Validators';
export default { export default {
mixins: [alertMixin], mixins: [alertMixin],
@ -78,7 +78,7 @@ export default {
}, },
validations: { validations: {
inboxName: { required }, inboxName: { required },
phoneNumber: { required, shouldStartWithPlusSign }, phoneNumber: { required, isPhoneE164OrEmpty },
apiKey: { required }, apiKey: { required },
}, },
methods: { methods: {

View file

@ -99,8 +99,7 @@ import { mapGetters } from 'vuex';
import alertMixin from 'shared/mixins/alertMixin'; import alertMixin from 'shared/mixins/alertMixin';
import { required } from 'vuelidate/lib/validators'; import { required } from 'vuelidate/lib/validators';
import router from '../../../../index'; import router from '../../../../index';
import { isPhoneE164OrEmpty, isNumber } from 'shared/helpers/Validators';
const shouldStartWithPlusSign = (value = '') => value.startsWith('+');
export default { export default {
mixins: [alertMixin], mixins: [alertMixin],
@ -118,10 +117,10 @@ export default {
}, },
validations: { validations: {
inboxName: { required }, inboxName: { required },
phoneNumber: { required, shouldStartWithPlusSign }, phoneNumber: { required, isPhoneE164OrEmpty },
apiKey: { required }, apiKey: { required },
phoneNumberId: { required }, phoneNumberId: { required, isNumber },
businessAccountId: { required }, businessAccountId: { required, isNumber },
}, },
methods: { methods: {
async createChannel() { async createChannel() {

View file

@ -110,8 +110,7 @@ import { mapGetters } from 'vuex';
import alertMixin from 'shared/mixins/alertMixin'; import alertMixin from 'shared/mixins/alertMixin';
import { required } from 'vuelidate/lib/validators'; import { required } from 'vuelidate/lib/validators';
import router from '../../../../index'; import router from '../../../../index';
import { isPhoneE164OrEmpty } from 'shared/helpers/Validators';
const shouldStartWithPlusSign = (value = '') => value.startsWith('+');
export default { export default {
mixins: [alertMixin], mixins: [alertMixin],
@ -142,7 +141,7 @@ export default {
return { return {
channelName: { required }, channelName: { required },
messagingServiceSID: {}, messagingServiceSID: {},
phoneNumber: { shouldStartWithPlusSign }, phoneNumber: { required, isPhoneE164OrEmpty },
authToken: { required }, authToken: { required },
accountSID: { required }, accountSID: { required },
medium: { required }, medium: { required },

View file

@ -16,3 +16,4 @@ export const isValidPassword = value => {
containsSpecialCharacter containsSpecialCharacter
); );
}; };
export const isNumber = value => /^\d+$/.test(value);

View file

@ -1,5 +1,6 @@
import { shouldBeUrl } from '../Validators'; import { shouldBeUrl } from '../Validators';
import { isValidPassword } from '../Validators'; import { isValidPassword } from '../Validators';
import { isNumber } from '../Validators';
describe('#shouldBeUrl', () => { describe('#shouldBeUrl', () => {
it('should return correct url', () => { it('should return correct url', () => {
@ -22,3 +23,15 @@ describe('#isValidPassword', () => {
expect(isValidPassword('testPass!')).toEqual(false); expect(isValidPassword('testPass!')).toEqual(false);
}); });
}); });
describe('#isNumber', () => {
it('should return correct number', () => {
expect(isNumber('123')).toEqual(true);
});
it('should return wrong number', () => {
expect(isNumber('123-')).toEqual(false);
expect(isNumber('123./')).toEqual(false);
expect(isNumber('string')).toEqual(false);
});
});