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AAA;YAC3D,OAAO,CAAC,GAAG,CAAE,kBAAkB,WAAW,GAAG,WAAW,eAAe,CAAE,CAAA;SAEzE;QAAC,OAAO,CAAC,EAAE;YACX,OAAO,CAAC,GAAG,CAAE,0BAA0B,WAAW,GAAG,WAAW,YAAY,CAAC,CAAC,OAAO,EAAE,CAAE,CAAA;YACzF,SAAS,EAAE,CAAA;SACX;IACF,CAAC,CAAC,CAAA;AACH,CAAC","file":"AppsWidget.min.js","sourcesContent":["// import * as $ from 'jquery/dist/jquery.slim'\r\nimport{ CoreError } from '../Core'\r\nimport { AppType, GLOBAL_AppPlatform, Metrics, Page, Platform, TriggerPoint } from '../Metrics'\r\n\r\n\r\ndeclare var GLOBAL_BaseApiURL_Direct:string\r\n\r\n\r\n// TODO(arch): is there a better/standard way to initialize this? (ie: encapsulate within class)\r\nexport function initAppsWidget( page:Page ){\r\n\t// TODO: handle both platform buttons\r\n\tlet iOSButton:JQuery = $('#__appsWidget > .content > a')\r\n\tiOSButton.on( 'click', async () => {\r\n\t\tif( GLOBAL_AppPlatform == Platform.iOS ) // TEMP: workaround for Amplitude bug where filters are not respected when synching\r\n\t\t\tawait Metrics.logNAV_launchApp( AppType.Permanent, page, TriggerPoint.SecondaryCTA )\r\n\r\n\t\t// navigate\r\n\t\tlet href:string = iOSButton.attr( 'data-href' )\r\n//\t\tconsole.debug( `CTA HREF: ${href}` )\r\n\t\tawait Metrics.flush() // NOTE: ensure metrics are pushed before navigating away\r\n\t\twindow.location.href = href\r\n\t})\r\n\t\r\n\t$('#__appsWidget #androidPreRegisterForm').on( 'submit', async e => {\r\n\t\t// prevent form submission (NOTE: we handle in AJAX instead)\r\n\t\te.preventDefault()\r\n\t\te.stopPropagation()\r\n\t\t\r\n\t\t// validate\r\n\t\tconst countryCodeTextField:JQuery = $('#__appsWidget #countryCodeTextField')\r\n\t\tlet countryCode:string|number|string[]|undefined = countryCodeTextField.val()\r\n\t\tif( !countryCode ){\r\n\t\t\tcountryCode = '+1'\r\n\t\t} else if( countryCode instanceof String ){\r\n\t\t\tcountryCode = countryCode.trim()\r\n\t\t}\r\n\t\tconst phoneNumberTextField:JQuery = $('#__appsWidget #phoneNumberTextField')\r\n\t\tlet phoneNumber:string|number|string[]|undefined = phoneNumberTextField.val()\r\n\t\tif( phoneNumber instanceof String ){\r\n\t\t\tphoneNumber = phoneNumber.trim()\r\n\t\t}\r\n\t\tconst errorLabel:JQuery = $('__appsWidget #errorLabel')\r\n\t\tif( !phoneNumber ){\r\n\t\t\tphoneNumberTextField.addClass( 'is-invalid' )\r\n\t\t\tphoneNumberTextField.addClass( 'was-validated' )\r\n\t\t\terrorLabel.text( \"Please enter your phone number\" )\r\n\t\t\terrorLabel.show() // NOTE: needed because error label is not a sibling of the input control\r\n\t\t\tphoneNumberTextField.trigger( 'focus' )\r\n\t\t\treturn\r\n\t\t// TODO: validate value (can use DOM's 'checkValidity()' method – REF: https://stackoverflow.com/a/39593175/24177)\r\n\t\t// } else if( phoneNumberTextField ){\r\n\t\t//\t\r\n\t\t} else {\r\n\t\t\tphoneNumberTextField.removeClass( 'is-invalid' )\r\n\t\t\tphoneNumberTextField.removeClass( 'was-validated' )\r\n\t\t\terrorLabel.hide()\r\n\t\t}\r\n\t\t\r\n\t\t// submit\r\n\t\tlet preRegisterButton = $('#__appsWidget #registerButton')\r\n\t\tpreRegisterButton.empty()\r\n\t\tpreRegisterButton.append('
' )\r\n\t\terrorLabel.hide()\r\n\t\tfunction showError( message?:string ){\r\n\t\t\tphoneNumberTextField.addClass( 'is-invalid' )\r\n\t\t\tphoneNumberTextField.trigger( 'focus' )\r\n\t\t\terrorLabel.text( message ?? \"Something went wrong. Please try again later.\" )\r\n\t\t\terrorLabel.show() // NOTE: needed because error label is not a sibling of the input control\r\n\t\t\tpreRegisterButton.empty()\r\n\t\t\tpreRegisterButton.text( 'Pre-register' )\r\n\t\t}\r\n\t\ttry {\r\n\t\t\tconst response:Response = await fetch( `${GLOBAL_BaseApiURL_Direct}/account/subscribers`, {\r\n\t\t\t\tmethod: 'POST',\r\n\t\t\t\theaders: {\r\n\t\t\t\t\t'Content-Type': 'application/json',\r\n\t\t\t\t},\r\n\t\t\t\tbody: JSON.stringify({\r\n\t\t\t\t\tPhoneNumber: `${countryCode}${phoneNumber}`,\r\n\t\t\t\t\tPlatform: 'Android',\r\n\t\t\t\t}),\r\n\t\t\t})\r\n\t\t\tif( !response.ok ){\r\n\t\t\t\tconst statusCode:number = response.status\r\n\t\t\t\tif( 400 <= statusCode && statusCode < 500 ){\r\n\t\t\t\t\tconst errorJSON:CoreError = await response.json()\r\n\t\t\t\t\tswitch( errorJSON.ErrorCode ){\r\n\t\t\t\t\tcase \"InvalidPhoneNumber\":\r\n\t\t\t\t\t\tconsole.log( `Could not pre-register ${countryCode}${phoneNumber}. Invalid phone number.` )\r\n\t\t\t\t\t\tshowError( \"Please enter a valid phone number\" )\r\n\t\t\t\t\t\tbreak\r\n\t\t\t\t\t\t\r\n\t\t\t\t\tdefault:\r\n\t\t\t\t\t\tconsole.log( `Could not pre-register ${countryCode}${phoneNumber}. Status code: ${statusCode}` )\r\n\t\t\t\t\t\tshowError()\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\tconsole.log( `Could not pre-register ${countryCode}${phoneNumber}. Status code: ${statusCode}` )\r\n\t\t\t\t\tshowError()\r\n\t\t\t\t}\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\r\n\t\t\tpreRegisterButton.text( 'Registered' )\r\n\t\t\t$('#__appsWidget .register-container > .unregistered').hide()\r\n\t\t\t$('#__appsWidget .register-container > .registered').show()\r\n\t\t\tconsole.log( `Pre-registered ${countryCode}${phoneNumber} successfully` )\r\n\t\t\t\r\n\t\t} catch( x ){\r\n\t\t\tconsole.log( `Could not pre-register ${countryCode}${phoneNumber}. ERROR: ${x.message}` )\r\n\t\t\tshowError()\r\n\t\t}\r\n\t})\r\n}\r\n"]}