{"version":3,"sources":["webpack:///src/app/admin/users/user/user.component.ts","webpack:///src/app/admin/users/user/user.component.html"],"names":["UserFormMode","VIEW","EDIT","ADD","EDIT_SELF","UserComponent","usersService","options","route","authService","settingService","tokenService","countriesService","userStore","toasterService","subscriptionService","cd","fb","appSettingService","roleProvider","ConversionFactorsPreference","SearchCountryField","CountryISO","PhoneNumberFormat","preferredCountries","UnitedStates","Canada","ContactAndBillingInfoLabel","ContactInfoLabel","BillingInfoLabel","PhoneInfoLabel","SubscriptionPlanLabel","deviceToken","ChangePasswordLabel","CurrentPasswordLabel","NewPasswordLabel","ConfirmPasswordLabel","PasswordsValidationMessage","strategy","this","getConfigValue","minLength","maxLength","isAdmin","configurations","appStorePassword","keyId","issuerId","username","teamId","teamName","bundleId","branchName","token","unsubscribe$","selectedPlanCode","isLoading","resetPasswordForm","get","userForm","viewMode","mode","getRole","subscribe","role","Array","some","x","toLowerCase","ADMIN","id","snapshot","paramMap","getUserSettings","Number","parseInt","res","userSettings","appLogo","logo","color","appColor","themeName","appStoreUrl","playStoreUrl","initUserForm","loadUserData","initChangePasswordForm","observablePlans","getAvailableList","Countries","list","passwordValidators","required","group","currentPassword","control","Password","confirmPassword","email","firstName","lastName","conversionFactorsPreference","phoneNumber","businessName","isCustomAppInProduction","customAppEnabled","address","street","secondAddress","city","country","zipCode","queryParamMap","setViewMode","loadUser","currentUserId","getUser","toString","event","file","target","files","reader","FileReader","onload","fileLoadEvent","result","readAsText","getCurrentUser","pipe","user","currentUser","planCode","getByCode","plan","selectedPlan","setValue","value","internationalNumber","patchValue","convertToUser","observable","updateCurrent","set","Date","handleSuccessResponse","setUser","handleWrongResponse","update","create","userData","console","log","resetPassword","isSuccess","handleResetPasswordSuccessResponse","handleResetPasswordWrongResponse","reset","confirm","updateCurrentUserPlan","handlePlanSuccessResponse","handlePlanWrongResponse","runBuild","success","back","danger","subscription","fragment","setTimeout","scrollToAnchor","e","document","querySelector","scrollIntoView","unsubscribe","next","complete","key","sendNotifications","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EV,0CACE,uFAeE,oD,kCAKF,8BACA,oGAUA,8BACF,8BACF,8BAEA,2CACE,yEAIW,8BAEX,0CACE,iHAQF,8BACF,8BACF,8BACF,8BACF,8BACF,8BACA,8CAqGF,8BACF,8BACA,oDACE,+CAKE,qDAAS,EAAA+K,UALX,6BAQA,8BACF,8BACF,8BAEA,sD,MAjfgB,+EACP,8EAuBW,+LAYA,gIAAkD,0EAsBlD,0LAaA,8HAAiD,wEAuDjD,kGAAyC,6BAAzC,CAAyC,uBAAzC,CAAyC,uBAAzC,CAAyC,+GAAzC,CAAyC,wBAAzC,CAAyC,+CAAzC,CAAyC,eAAzC,CAAyC,iDAAzC,CAAyC,sBAoBzC,kLAEC,0KA2BC,+FA+BF,8RAcA,sLAEC,+EAFD,CAEC,gFAsBD,mPAcA,8JAA2D,mEAA3D,CAA2D,oEAmC3D,sOAcA,sJAAuD,+DAAvD,CAAuD,gEAuBvD,0PAUE,+GAQF,kKAEC,sEA+BE,wEA4GjB,iGAQG,kG,myFD1bF","file":"x","sourcesContent":["import {\r\n Component,\r\n OnDestroy,\r\n OnInit,\r\n ChangeDetectorRef,\r\n Inject,\r\n AfterViewInit,\r\n} from '@angular/core';\r\nimport { Location } from '@angular/common';\r\nimport { FormBuilder, FormGroup, Validators } from '@angular/forms';\r\nimport { Router, ActivatedRoute } from '@angular/router';\r\nimport { Observable, Subscription } from 'rxjs';\r\nimport { Subject } from 'rxjs/Subject';\r\nimport { finalize, takeUntil } from 'rxjs/operators';\r\nimport { NbToastrService } from '@nebular/theme';\r\nimport {\r\n SearchCountryField,\r\n CountryISO,\r\n PhoneNumberFormat,\r\n} from 'ngx-intl-tel-input';\r\nimport {\r\n getDeepFromObject,\r\n NbAuthOAuth2JWTToken,\r\n NbAuthResult,\r\n NbAuthService,\r\n NbTokenService,\r\n NB_AUTH_OPTIONS,\r\n} from '@nebular/auth';\r\n\r\nimport { User, UserData } from '../../../@core/interfaces/common/users';\r\nimport { UserStore } from '../../../@core/stores/user.store';\r\nimport {\r\n SubscriptionPlanData,\r\n SubscriptionPlan,\r\n} from '../../../@core/interfaces/common/CalorieFriend/subscriptionPlan';\r\nimport {\r\n Country,\r\n CountryData,\r\n} from '../../../@core/interfaces/common/countries';\r\nimport { ConversionFactorsData } from 'app/@core/utils/conversionFactors.data';\r\nimport { AppSettingsService } from 'app/@core/backend/common/services/appSettings.service';\r\nimport { NbRoleProvider } from '@nebular/security';\r\nimport { ROLES } from 'app/@auth/roles';\r\nimport { AppSettings } from 'app/@core/interfaces/common/appSettings';\r\nimport { SettingsService } from 'app/@core/backend/common/services/settings.service';\r\nimport { Settings } from 'app/@core/interfaces/common/settings';\r\nimport { JSONStringify } from './../../../SupportOps';\r\nimport { AppSettingsConfigurations } from 'app/@components/app-settings/app-settings.component';\r\nimport { is } from 'date-fns/locale';\r\n\r\nexport enum UserFormMode {\r\n VIEW = 'View',\r\n EDIT = 'Edit',\r\n ADD = 'Add',\r\n EDIT_SELF = 'EditSelf',\r\n}\r\n\r\n@Component({\r\n selector: 'ngx-user',\r\n templateUrl: './user.component.html',\r\n styleUrls: ['./user.component.scss'],\r\n})\r\nexport class UserComponent implements OnInit, AfterViewInit, OnDestroy {\r\n UserFormMode = UserFormMode;\r\n userForm: FormGroup;\r\n ConversionFactorsPreference = ConversionFactorsData;\r\n\r\n SearchCountryField = SearchCountryField;\r\n CountryISO = CountryISO;\r\n PhoneNumberFormat = PhoneNumberFormat;\r\n preferredCountries: CountryISO[] = [\r\n CountryISO.UnitedStates,\r\n CountryISO.Canada,\r\n ];\r\n\r\n ContactAndBillingInfoLabel = 'Contact and Billing Info';\r\n ContactInfoLabel = 'Contact Info';\r\n BillingInfoLabel = 'Billing Info';\r\n PhoneInfoLabel = 'Phone Number';\r\n SubscriptionPlanLabel = 'Subscription Plan';\r\n appSettings: AppSettings;\r\n deviceToken=\"cHT0GeujRhy-q5Bs7SVL-3:APA91bFTYMLwYfWSiZwMCbG4dfTn6uTikcvIaJqtEv_YUSKfP2P3Dfg0SpwEKBfEYDxTWEDvMnxHemkLaQcrNEcfJENXugNx_ACtqzUmfGVx3kRLt82AJiDzyDoNZeUM82o36G8uV6Si\";\r\n\r\n ChangePasswordLabel: string = 'Change Password';\r\n CurrentPasswordLabel: string = 'Current Password';\r\n NewPasswordLabel: string = 'New Password';\r\n ConfirmPasswordLabel: string = 'Confirm Password';\r\n PasswordsValidationMessage: string =\r\n 'New password and confirm password does not match!';\r\n\r\n strategy: string = this.getConfigValue('forms.resetPassword.strategy');\r\n minLength: number = this.getConfigValue(\r\n 'forms.validation.password.minLength'\r\n );\r\n maxLength: number = this.getConfigValue(\r\n 'forms.validation.password.maxLength'\r\n );\r\n isAdmin: boolean = false;\r\n resetPasswordForm: FormGroup;\r\n configurations: AppSettingsConfigurations = {\r\n appStorePassword: null,\r\n keyId: null,\r\n issuerId: null,\r\n username: null,\r\n teamId: null,\r\n teamName: null,\r\n bundleId: null,\r\n branchName: null,\r\n token: null,\r\n };\r\n get currentPassword() {\r\n return this.resetPasswordForm.get('currentPassword');\r\n }\r\n get Password() {\r\n return this.resetPasswordForm.get('Password');\r\n }\r\n get confirmPassword() {\r\n return this.resetPasswordForm.get('confirmPassword');\r\n }\r\n\r\n protected readonly unsubscribe$ = new Subject();\r\n\r\n get firstName() {\r\n return this.userForm.get('firstName');\r\n }\r\n get lastName() {\r\n return this.userForm.get('lastName');\r\n }\r\n // get login() { return this.userForm.get('login'); }\r\n // get email() { return this.userForm.get('email'); }\r\n get phoneNumber() {\r\n return this.userForm.get('phoneNumber');\r\n }\r\n get businessName() {\r\n return this.userForm.get('businessName');\r\n }\r\n get secondAddress() {\r\n return this.userForm.get('secondAddress');\r\n }\r\n get street() {\r\n return this.userForm.get('address').get('street');\r\n }\r\n get city() {\r\n return this.userForm.get('address').get('city');\r\n }\r\n get country() {\r\n return this.userForm.get('address').get('country');\r\n }\r\n get zipCode() {\r\n return this.userForm.get('address').get('zipCode');\r\n }\r\n\r\n get conversionFactorsValue() {\r\n return this.userForm.get('conversionFactorsPreference');\r\n }\r\n\r\n mode: UserFormMode;\r\n setViewMode(viewMode: UserFormMode) {\r\n this.mode = viewMode;\r\n }\r\n\r\n currentUser: User;\r\n userSettings: Settings;\r\n selectedPlanCode: string = '';\r\n selectedPlan: SubscriptionPlan;\r\n appStoreUrl: string;\r\n playStoreUrl: string;\r\n public isLoading: boolean = false;\r\n\r\n observablePlans: Observable;\r\n\r\n Countries: Observable;\r\n\r\n constructor(\r\n private usersService: UserData,\r\n @Inject(NB_AUTH_OPTIONS) protected options = {},\r\n private route: ActivatedRoute,\r\n private authService: NbAuthService,\r\n private settingService: SettingsService,\r\n private tokenService: NbTokenService,\r\n private countriesService: CountryData,\r\n private userStore: UserStore,\r\n private toasterService: NbToastrService,\r\n protected subscriptionService: SubscriptionPlanData,\r\n protected cd: ChangeDetectorRef,\r\n private fb: FormBuilder,\r\n private appSettingService: AppSettingsService,\r\n private roleProvider: NbRoleProvider,\r\n ) {}\r\n\r\n ngOnInit(): void {\r\n this.roleProvider.getRole().subscribe(role => {\r\n const roles = role instanceof Array ? role : [role];\r\n this.isAdmin = roles.some((x) => x && x.toLowerCase() === ROLES.ADMIN);\r\n if(this.isAdmin) {\r\n const id = this.route.snapshot.paramMap.get('id');\r\n this.settingService.getUserSettings(Number.parseInt(id)).subscribe(res => {\r\n if(res)\r\n this.userSettings = res;\r\n else {\r\n this.userSettings = {\r\n id: Number.parseInt(id),\r\n appLogo: null,\r\n logo: null,\r\n color: null,\r\n appColor: null,\r\n themeName: null,\r\n appStoreUrl: null,\r\n playStoreUrl: null,\r\n }\r\n }\r\n });\r\n }\r\n });\r\n this.initUserForm();\r\n this.loadUserData();\r\n this.initChangePasswordForm();\r\n this.observablePlans = this.subscriptionService.getAvailableList();\r\n\r\n // load countries\r\n this.Countries = this.countriesService.list();\r\n }\r\n\r\n initChangePasswordForm() {\r\n const passwordValidators = [\r\n Validators.required,\r\n Validators.minLength(this.minLength),\r\n Validators.maxLength(this.maxLength),\r\n ];\r\n\r\n this.resetPasswordForm = this.fb.group({\r\n currentPassword: this.fb.control('', [...passwordValidators]),\r\n Password: this.fb.control('', [...passwordValidators]),\r\n confirmPassword: this.fb.control('', [...passwordValidators]),\r\n });\r\n }\r\n\r\n initUserForm() {\r\n this.userForm = this.fb.group({\r\n id: this.fb.control(''),\r\n role: this.fb.control(''),\r\n email: this.fb.control('', [\r\n Validators.required,\r\n Validators.email\r\n ]),\r\n firstName: this.fb.control('', [\r\n Validators.minLength(3),\r\n Validators.maxLength(40),\r\n ]),\r\n lastName: this.fb.control('', [\r\n Validators.minLength(3),\r\n Validators.maxLength(40),\r\n ]),\r\n conversionFactorsPreference: this.fb.control('g'),\r\n // login: this.fb.control('', [Validators.required, Validators.minLength(6), Validators.maxLength(20)]),\r\n // email: this.fb.control('', [\r\n // Validators.required,\r\n // Validators.pattern(EMAIL_PATTERN),\r\n // ]),\r\n phoneNumber: this.fb.control('', [Validators.required]),\r\n businessName: this.fb.control('', [\r\n Validators.required,\r\n Validators.minLength(3),\r\n Validators.maxLength(100),\r\n ]),\r\n isCustomAppInProduction: this.fb.control(null),\r\n customAppEnabled: this.fb.control(null),\r\n address: this.fb.group({\r\n street: this.fb.control('', [\r\n Validators.required,\r\n Validators.minLength(3),\r\n Validators.maxLength(1024),\r\n ]),\r\n secondAddress: this.fb.control(''),\r\n city: this.fb.control('', [\r\n Validators.required,\r\n Validators.minLength(3),\r\n Validators.maxLength(1024),\r\n ]),\r\n country: this.fb.control('', [\r\n Validators.required,\r\n Validators.minLength(3),\r\n Validators.maxLength(1024),\r\n ]),\r\n zipCode: this.fb.control(''),\r\n }),\r\n });\r\n }\r\n\r\n get canEdit(): boolean {\r\n return this.mode !== UserFormMode.VIEW;\r\n }\r\n\r\n loadUserData() {\r\n const id = this.route.snapshot.paramMap.get('id');\r\n const isProfile = this.route.snapshot.queryParamMap.get('profile');\r\n if (isProfile) {\r\n this.setViewMode(UserFormMode.EDIT_SELF);\r\n this.loadUser();\r\n } else {\r\n if (id) {\r\n const currentUserId = this.userStore.getUser()?.id;\r\n this.setViewMode(\r\n currentUserId?.toString() === id\r\n ? UserFormMode.EDIT_SELF\r\n : UserFormMode.EDIT\r\n );\r\n this.loadUser(id);\r\n } else {\r\n this.setViewMode(UserFormMode.ADD);\r\n }\r\n }\r\n }\r\n\r\n tokenFileUpload(event: any): void{\r\n const file = event.target.files[0];\r\n if (!file) {\r\n return;\r\n }\r\n\r\n const reader = new FileReader();\r\n reader.onload = (fileLoadEvent) => {\r\n const text = fileLoadEvent.target.result;\r\n this.configurations.token = text as string;\r\n }\r\n reader.readAsText(file);\r\n }\r\n\r\n loadUser(id?) {\r\n this.isLoading = true;\r\n const loadUser =\r\n this.mode === UserFormMode.EDIT_SELF\r\n ? this.usersService.getCurrentUser()\r\n : this.usersService.get(id);\r\n\r\n loadUser.pipe(takeUntil(this.unsubscribe$),\r\n finalize(() => this.isLoading = false)).subscribe((user: User) => {\r\n this.currentUser = user;\r\n this.selectedPlanCode = user.planCode;\r\n\r\n this.subscriptionService.getByCode(user.planCode).subscribe((plan) => {\r\n this.selectedPlan = plan;\r\n });\r\n this.userForm.setValue({\r\n id: user.id ? user.id : '',\r\n role: user.role ? user.role : '',\r\n firstName: user.firstName ? user.firstName : '',\r\n lastName: user.lastName ? user.lastName : '',\r\n phoneNumber: user.phoneNumber ? user.phoneNumber : '',\r\n businessName: user.businessName ? user.businessName : '',\r\n email: user.email ? user.email : '',\r\n conversionFactorsPreference: user.conversionFactorsPreference? user.conversionFactorsPreference: 'g',\r\n address: {\r\n street:\r\n user.address && user.address.street ? user.address.street : '',\r\n secondAddress:\r\n user.address && user.address.secondAddress\r\n ? user.address.secondAddress\r\n : '',\r\n city: user.address && user.address.city ? user.address.city : '',\r\n country:\r\n user.address && user.address.country ? user.address.country : '',\r\n zipCode:\r\n user.address && user.address.zipCode ? user.address.zipCode : '',\r\n },\r\n isCustomAppInProduction: user.isCustomAppInProduction,\r\n customAppEnabled: user.customAppEnabled,\r\n });\r\n\r\n // this is a place for value changes handling\r\n // this.userForm.valueChanges.pipe(takeUntil(this.unsubscribe$)).subscribe((value) => { });\r\n });\r\n }\r\n\r\n convertToUser(value: any): User {\r\n const user: User = {\r\n ...value,\r\n phoneNumber: value.phoneNumber.internationalNumber,\r\n };\r\n return user;\r\n }\r\n\r\n changeIsCustomAppInProduction(event) {\r\n this.userForm.patchValue({\r\n isCustomAppInProduction: event,\r\n });\r\n }\r\n\r\n changeCustomAppEnabled(event) {\r\n this.userForm.patchValue({\r\n customAppEnabled: event,\r\n });\r\n }\r\n\r\n get isCustomAppEnabled(): boolean {\r\n return this.userForm.get('customAppEnabled').value;\r\n }\r\n\r\n get isCustomAppInProduction(): boolean {\r\n return this.userForm.get('isCustomAppInProduction').value;\r\n }\r\n\r\n save() {\r\n const user: User = this.convertToUser(this.userForm.value);\r\n // user.email = this.currentUser.email;\r\n // user.login = this.currentUser.login;\r\n\r\n let observable = new Observable();\r\n if (this.mode === UserFormMode.EDIT_SELF) {\r\n this.usersService.updateCurrent(user).subscribe(\r\n (result: any) => {\r\n this.tokenService.set(\r\n new NbAuthOAuth2JWTToken(result, 'email', new Date())\r\n );\r\n this.handleSuccessResponse();\r\n this.userStore.setUser(user);\r\n },\r\n () => {\r\n this.handleWrongResponse();\r\n }\r\n );\r\n } else {\r\n observable = user.id\r\n ? this.usersService.update(user)\r\n : this.usersService.create(user);\r\n // this.userSettings.color = JSON.stringify(this.userSettings.color);\r\n // this.settingService.updateUserSettings({...this.userSettings, appLogo: null, logo: null, color: JSON.stringify(this.userSettings.color), appColor: JSON.stringify(this.userSettings.appColor)}).subscribe(res => {\r\n // console.log(res);\r\n // });\r\n // this.appSettingService.update({...this.appSettings, configuration: JSONStringify(this.configurations)}).subscribe(res => {\r\n // console.log(res);\r\n // });\r\n }\r\n this.isLoading = true;\r\n\r\n observable.pipe(takeUntil(this.unsubscribe$),\r\n finalize(() => this.isLoading = false)).subscribe(\r\n () => {\r\n this.handleSuccessResponse();\r\n },\r\n () => {\r\n this.handleWrongResponse();\r\n }\r\n );\r\n // if(this.isAdmin) {\r\n // this.appSettingService.update(this.appSettings).subscribe(res => {\r\n // console.log(res);\r\n // })\r\n // }\r\n }\r\n\r\n saveAppSettings({user, settings}): void {\r\n const userData: User = this.convertToUser({...this.userForm.value,\r\n isCustomAppInProduction: user.isCustomAppInProduction,\r\n customAppEnabled: user.customAppEnabled});\r\n console.log(userData);\r\n this.usersService.update(\r\n userData\r\n ).subscribe(\r\n (result: User) => {\r\n this.handleSuccessResponse();\r\n this.currentUser = user;\r\n this.userStore.setUser(user);\r\n },\r\n () => {\r\n this.handleWrongResponse();\r\n }\r\n );\r\n }\r\n\r\n changePassword() {\r\n const passwordData: any = this.resetPasswordForm.value;\r\n\r\n this.authService\r\n .resetPassword(this.strategy, passwordData)\r\n .subscribe((result: NbAuthResult) => {\r\n if (result.isSuccess()) {\r\n this.handleResetPasswordSuccessResponse();\r\n // this.messages = result.getMessages();\r\n } else {\r\n this.handleResetPasswordWrongResponse();\r\n // this.errors = result.getErrors();\r\n }\r\n this.resetPasswordForm.reset();\r\n });\r\n }\r\n\r\n savePlan() {\r\n if (this.mode === UserFormMode.EDIT_SELF) {\r\n if (this.selectedPlanCode !== this.currentUser.planCode) {\r\n if (\r\n !confirm('Are you sure you want to change the subscription plan?')\r\n ) {\r\n this.selectedPlanCode = this.currentUser.planCode;\r\n return;\r\n }\r\n\r\n this.usersService\r\n .updateCurrentUserPlan(this.currentUser, this.selectedPlanCode)\r\n .subscribe(\r\n () => {\r\n this.currentUser.planCode = this.selectedPlanCode;\r\n this.handlePlanSuccessResponse();\r\n this.loadUser();\r\n },\r\n () => {\r\n this.handlePlanWrongResponse();\r\n }\r\n );\r\n }\r\n }\r\n }\r\n\r\n runBuild() {\r\n const id = this.route.snapshot.paramMap.get('id');\r\n this.appSettingService.runBuild(parseInt(id)).subscribe(res => {\r\n console.log(res);\r\n });\r\n }\r\n\r\n handleSuccessResponse() {\r\n this.toasterService.success(\r\n '',\r\n `Item ${this.mode === UserFormMode.ADD ? 'created' : 'updated'}!`\r\n );\r\n this.back();\r\n }\r\n\r\n handleWrongResponse() {\r\n this.toasterService.danger('', `This email has already taken!`);\r\n }\r\n\r\n handleResetPasswordSuccessResponse() {\r\n this.toasterService.success('', `The password has been changed!`);\r\n }\r\n\r\n handleResetPasswordWrongResponse() {\r\n this.toasterService.danger('', `Changing password failed!`);\r\n }\r\n\r\n handlePlanSuccessResponse() {\r\n this.toasterService.success('', `The subscription plan has been changed!`);\r\n this.back();\r\n }\r\n\r\n handlePlanWrongResponse() {\r\n this.toasterService.danger('', `The subscription plan cannot be changed!`);\r\n }\r\n\r\n back() {\r\n // this.location.back();\r\n // this.router.navigate(['/admin/users/list']);\r\n }\r\n\r\n subscription: Subscription;\r\n\r\n fragment: string;\r\n\r\n public ngAfterViewInit(): void {\r\n this.subscription = this.route.fragment.subscribe((fragment) => {\r\n try {\r\n this.fragment = fragment;\r\n setTimeout(() => this.scrollToAnchor(), 10);\r\n } catch (e) {}\r\n });\r\n }\r\n\r\n scrollToAnchor(): void {\r\n try {\r\n if (this.fragment) {\r\n document.querySelector('#' + this.fragment).scrollIntoView();\r\n }\r\n } catch (e) {}\r\n }\r\n\r\n ngOnDestroy(): void {\r\n this.subscription.unsubscribe();\r\n\r\n this.unsubscribe$.next();\r\n this.unsubscribe$.complete();\r\n }\r\n\r\n getConfigValue(key: string): any {\r\n return getDeepFromObject(this.options, key, null);\r\n }\r\n\r\n sendNotifications(){\r\n this.appSettingService.sendNotifications(this.deviceToken).subscribe(() => {\r\n console.log(\"Sended....\");\r\n })\r\n }\r\n}\r\n","\r\n \r\n
\r\n Contact and Billing Info\r\n
\r\n
\r\n\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n Contact Info\r\n \r\n\r\n \r\n
\r\n First Name\r\n
\r\n \r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n Last Name\r\n
\r\n \r\n \r\n
\r\n
\r\n\r\n \r\n\r\n
\r\n Email\r\n
\r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n Phone Number\r\n
\r\n \r\n \r\n
\r\n
\r\n
\r\n Conversion factor preference\r\n
\r\n \r\n {{ item.text }}\r\n \r\n
\r\n
\r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n \r\n Billing Info\r\n \r\n\r\n \r\n
\r\n Business Name\r\n
\r\n \r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n Address\r\n
\r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n
\r\n
\r\n \r\n
\r\n
\r\n\r\n
\r\n City\r\n
\r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n Country\r\n
\r\n \r\n {{ item.name }}\r\n \r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n Zip Code\r\n
\r\n \r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n
\r\n \r\n \r\n
\r\n
\r\n
\r\n
\r\n \r\n \r\n Submit\r\n \r\n \r\n
\r\n\r\n\r\n \r\n
Change Password
\r\n
\r\n\r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n \r\n \r\n \r\n
\r\n\r\n
\r\n
\r\n \r\n
\r\n\r\n \r\n \r\n Change Password\r\n \r\n \r\n
\r\n"]}