From e9304c950ad18e9364b955978f0107fa87179c7e Mon Sep 17 00:00:00 2001 From: Le Deng Date: Wed, 8 Mar 2017 15:51:13 -0500 Subject: [PATCH] latest --- .../my-profile/my-profile.component.html | 1 + .../my-profile/my-profile.component.ts | 53 +++++++++++-------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/store-front/src/app/components/my-profile/my-profile.component.html b/store-front/src/app/components/my-profile/my-profile.component.html index 2ec0c1a..c612ad0 100644 --- a/store-front/src/app/components/my-profile/my-profile.component.html +++ b/store-front/src/app/components/my-profile/my-profile.component.html @@ -73,6 +73,7 @@

+

Default payment set successfully!

diff --git a/store-front/src/app/components/my-profile/my-profile.component.ts b/store-front/src/app/components/my-profile/my-profile.component.ts index a2a100c..a284a14 100644 --- a/store-front/src/app/components/my-profile/my-profile.component.ts +++ b/store-front/src/app/components/my-profile/my-profile.component.ts @@ -40,6 +40,7 @@ export class MyProfileComponent implements OnInit { private selectedBillingTab:number = 0; private defaultUserPaymentId:number; + private defaultPaymentSet:boolean; constructor (private paymentService:PaymentService, private loginService: LoginService, private userService: UserService, private router: Router){ } @@ -103,7 +104,8 @@ export class MyProfileComponent implements OnInit { onNewPayment () { this.paymentService.newPayment(this.userPayment).subscribe( res => { - location.reload(); + this.getCurrentUser(); + this.selectedBillingTab = 0; }, error => { console.log(error.text()); @@ -120,7 +122,8 @@ export class MyProfileComponent implements OnInit { onRemovePayment(id:number) { this.paymentService.removePayment(id).subscribe( res => { - location.reload(); + this.getCurrentUser(); + }, error => { console.log(error.text()); @@ -129,10 +132,13 @@ export class MyProfileComponent implements OnInit { } setDefaultPayment() { + this.defaultPaymentSet=false; this.paymentService.setDefaultPayment(this.defaultUserPaymentId).subscribe( res => { - console.log(res.text()); - location.reload(); + this.getCurrentUser(); + this.defaultPaymentSet=true; + // this.selectedProfileTab = 2; + // this.selectedBillingTab = 0; }, error => { console.log(error.text()); @@ -140,6 +146,25 @@ export class MyProfileComponent implements OnInit { ); } + getCurrentUser() { + this.userService.getCurrentUser().subscribe( + res => { + this.user=res.json(); + this.userPaymentList = this.user.userPaymentList; + + for (let index in this.userPaymentList) { + if (this.userPaymentList[index].defaultPayment) { + this.defaultUserPaymentId=this.userPaymentList[index].id; + return; + } + } + }, + error => { + console.log(error); + } + ); + } + ngOnInit() { this.loginService.checkSession().subscribe( res => { @@ -150,22 +175,7 @@ export class MyProfileComponent implements OnInit { } ); - this.userService.getCurrentUser().subscribe( - res => { - this.user=res.json(); - this.userPaymentList = this.user.userPaymentList; - - for (let index in this.userPaymentList) { - if (this.userPaymentList[index].defaultPayment) { - this.defaultUserPaymentId=this.userPaymentList[index].id; - return; - } - } - }, - error => { - console.log(error); - } - ); + this.getCurrentUser(); for (let s in AppConst.usStates) { this.stateList.push(s); @@ -176,6 +186,7 @@ export class MyProfileComponent implements OnInit { this.userPayment.expiryMonth=""; this.userPayment.expiryYear=""; this.userPayment.userBilling = this.userBilling; - + this.defaultPaymentSet=false; + } }