From b37dbd6189d88c15f0e693599ad2422aceb9824c Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Wed, 28 Apr 2021 10:40:31 +0000 Subject: [PATCH 1/2] Return SMS phone number from WebPrompt as E164 * OneSignal's API expects the SMS phone number to be in E164 format * Use the intl-tel-input.getNumber(intlTelInputUtils.numberFormat.E164) to get the number in this format * Converted static methods to non-static we need to get an instance to itiOneSignal --- .../slidedownManager/SlidedownManager.ts | 16 ++++++++-------- src/slidedown/ChannelCaptureContainer.ts | 15 +++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/managers/slidedownManager/SlidedownManager.ts b/src/managers/slidedownManager/SlidedownManager.ts index 4b86a3b11..423e1018e 100644 --- a/src/managers/slidedownManager/SlidedownManager.ts +++ b/src/managers/slidedownManager/SlidedownManager.ts @@ -116,25 +116,25 @@ export class SlidedownManager { private async handleAllowForEmailType(): Promise { const emailInputFieldIsValid = OneSignal.slidedown.channelCaptureContainer.emailInputFieldIsValid; - const isEmailEmpty = ChannelCaptureContainer.isEmailInputFieldEmpty(); + const isEmailEmpty = OneSignal.slidedown.channelCaptureContainer.isEmailInputFieldEmpty(); if (!emailInputFieldIsValid || isEmailEmpty) { throw new ChannelCaptureError(InvalidChannelInputField.InvalidEmail); } - const email = ChannelCaptureContainer.getValueFromEmailInput(); + const email = OneSignal.slidedown.channelCaptureContainer.getValueFromEmailInput(); this.updateEmail(email); } private async handleAllowForSmsType(): Promise { const smsInputFieldIsValid = OneSignal.slidedown.channelCaptureContainer.smsInputFieldIsValid; - const isSmsEmpty = ChannelCaptureContainer.isSmsInputFieldEmpty(); + const isSmsEmpty = OneSignal.slidedown.channelCaptureContainer.isSmsInputFieldEmpty(); if (!smsInputFieldIsValid || isSmsEmpty) { throw new ChannelCaptureError(InvalidChannelInputField.InvalidSms); } - const sms = ChannelCaptureContainer.getValueFromSmsInput(); + const sms = OneSignal.slidedown.channelCaptureContainer.getValueFromSmsInput(); this.updateSMS(sms); } @@ -147,8 +147,8 @@ export class SlidedownManager { * * thus, we need separate checks for the emptiness properties */ - const isEmailEmpty = ChannelCaptureContainer.isEmailInputFieldEmpty(); - const isSmsEmpty = ChannelCaptureContainer.isSmsInputFieldEmpty(); + const isEmailEmpty = OneSignal.slidedown.channelCaptureContainer.isEmailInputFieldEmpty(); + const isSmsEmpty = OneSignal.slidedown.channelCaptureContainer.isSmsInputFieldEmpty(); const bothFieldsEmpty = isEmailEmpty && isSmsEmpty; const bothFieldsInvalid = !smsInputFieldIsValid && !emailInputFieldIsValid; @@ -157,8 +157,8 @@ export class SlidedownManager { throw new ChannelCaptureError(InvalidChannelInputField.InvalidEmailAndSms); } - const email = ChannelCaptureContainer.getValueFromEmailInput(); - const sms = ChannelCaptureContainer.getValueFromSmsInput(); + const email = OneSignal.slidedown.channelCaptureContainer.getValueFromEmailInput(); + const sms = OneSignal.slidedown.channelCaptureContainer.getValueFromSmsInput(); /** * empty is ok (we can accept only one of two input fields), but invalid is not diff --git a/src/slidedown/ChannelCaptureContainer.ts b/src/slidedown/ChannelCaptureContainer.ts index d69370ac0..c184ee736 100644 --- a/src/slidedown/ChannelCaptureContainer.ts +++ b/src/slidedown/ChannelCaptureContainer.ts @@ -259,12 +259,12 @@ export default class ChannelCaptureContainer { } /* S T A T I C */ - static isEmailInputFieldEmpty(): boolean { - return ChannelCaptureContainer.getValueFromEmailInput() === ""; + isEmailInputFieldEmpty(): boolean { + return this.getValueFromEmailInput() === ""; } - static isSmsInputFieldEmpty(): boolean { - return ChannelCaptureContainer.getValueFromSmsInput() === ""; + isSmsInputFieldEmpty(): boolean { + return this.getValueFromSmsInput() === ""; } static showSmsInputError(state: boolean): void { @@ -329,14 +329,13 @@ export default class ChannelCaptureContainer { } } - static getValueFromEmailInput(): string { + getValueFromEmailInput(): string { const inputNode = getDomElementOrStub(`#${CHANNEL_CAPTURE_CONTAINER_CSS_IDS.onesignalEmailInput}`); return (inputNode)?.value || ""; } - static getValueFromSmsInput(): string { - const inputNode = getDomElementOrStub(`#${CHANNEL_CAPTURE_CONTAINER_CSS_IDS.onesignalSmsInput}`); - return (inputNode)?.value || ""; + getValueFromSmsInput(): string { + return this.itiOneSignal.getNumber(intlTelInputUtils.numberFormat.E164) || ""; } static validateEmailInputWithReturnVal(emailString?: string): boolean { From cfa3ae22d90f70d787172ee9c8e10393119b724e Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Wed, 28 Apr 2021 10:46:40 +0000 Subject: [PATCH 2/2] Static region code clean up * These methods were under a STATIC comment so moved them above to maintain the "region" pattern - The commit was Intentionally split from the last to separate a logic change from a code move / formatting change. --- src/slidedown/ChannelCaptureContainer.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/slidedown/ChannelCaptureContainer.ts b/src/slidedown/ChannelCaptureContainer.ts index c184ee736..a9c5ca5c9 100644 --- a/src/slidedown/ChannelCaptureContainer.ts +++ b/src/slidedown/ChannelCaptureContainer.ts @@ -258,7 +258,6 @@ export default class ChannelCaptureContainer { } } - /* S T A T I C */ isEmailInputFieldEmpty(): boolean { return this.getValueFromEmailInput() === ""; } @@ -267,6 +266,16 @@ export default class ChannelCaptureContainer { return this.getValueFromSmsInput() === ""; } + getValueFromEmailInput(): string { + const inputNode = getDomElementOrStub(`#${CHANNEL_CAPTURE_CONTAINER_CSS_IDS.onesignalEmailInput}`); + return (inputNode)?.value || ""; + } + + getValueFromSmsInput(): string { + return this.itiOneSignal.getNumber(intlTelInputUtils.numberFormat.E164) || ""; + } + + /* S T A T I C */ static showSmsInputError(state: boolean): void { const validationElement = document.querySelector( `#${CHANNEL_CAPTURE_CONTAINER_CSS_IDS.onesignalSmsValidationElement}` @@ -329,15 +338,6 @@ export default class ChannelCaptureContainer { } } - getValueFromEmailInput(): string { - const inputNode = getDomElementOrStub(`#${CHANNEL_CAPTURE_CONTAINER_CSS_IDS.onesignalEmailInput}`); - return (inputNode)?.value || ""; - } - - getValueFromSmsInput(): string { - return this.itiOneSignal.getNumber(intlTelInputUtils.numberFormat.E164) || ""; - } - static validateEmailInputWithReturnVal(emailString?: string): boolean { const re = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; return re.test(emailString || '') || emailString === "";