Skip to content

Commit

Permalink
Merge pull request #809 from OneSignal/fix/sms_web_prompt_capture_as_…
Browse files Browse the repository at this point in the history
…e164

Fix SMS web prompt to format as e164
  • Loading branch information
jkasten2 authored Apr 28, 2021
2 parents 227f27b + cfa3ae2 commit 1ccaf59
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/managers/slidedownManager/SlidedownManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,25 @@ export class SlidedownManager {

private async handleAllowForEmailType(): Promise<void> {
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<void> {
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);
}

Expand All @@ -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;
Expand All @@ -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
Expand Down
29 changes: 14 additions & 15 deletions src/slidedown/ChannelCaptureContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,24 @@ export default class ChannelCaptureContainer {
}
}

/* S T A T I C */
static isEmailInputFieldEmpty(): boolean {
return ChannelCaptureContainer.getValueFromEmailInput() === "";
isEmailInputFieldEmpty(): boolean {
return this.getValueFromEmailInput() === "";
}

isSmsInputFieldEmpty(): boolean {
return this.getValueFromSmsInput() === "";
}

getValueFromEmailInput(): string {
const inputNode = getDomElementOrStub(`#${CHANNEL_CAPTURE_CONTAINER_CSS_IDS.onesignalEmailInput}`);
return (<HTMLInputElement>inputNode)?.value || "";
}

static isSmsInputFieldEmpty(): boolean {
return ChannelCaptureContainer.getValueFromSmsInput() === "";
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}`
Expand Down Expand Up @@ -329,16 +338,6 @@ export default class ChannelCaptureContainer {
}
}

static getValueFromEmailInput(): string {
const inputNode = getDomElementOrStub(`#${CHANNEL_CAPTURE_CONTAINER_CSS_IDS.onesignalEmailInput}`);
return (<HTMLInputElement>inputNode)?.value || "";
}

static getValueFromSmsInput(): string {
const inputNode = getDomElementOrStub(`#${CHANNEL_CAPTURE_CONTAINER_CSS_IDS.onesignalSmsInput}`);
return (<HTMLInputElement>inputNode)?.value || "";
}

static validateEmailInputWithReturnVal(emailString?: string): boolean {
const re = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
return re.test(emailString || '') || emailString === "";
Expand Down

0 comments on commit 1ccaf59

Please sign in to comment.