This commit is contained in:
Le Deng
2017-03-08 15:51:13 -05:00
parent c6504d3616
commit e9304c950a
2 changed files with 33 additions and 21 deletions

View File

@@ -73,6 +73,7 @@
<br> <br>
<br> <br>
<div> <div>
<p *ngIf="defaultPaymentSet">Default payment set successfully!</p>
<md-tab-group (selectedIndexChange)="selectedIndexChange($event)" [selectedIndex]="selectedBillingTab"> <md-tab-group (selectedIndexChange)="selectedIndexChange($event)" [selectedIndex]="selectedBillingTab">
<md-tab label="List of Credit Cards"> <md-tab label="List of Credit Cards">
<form (ngSubmit)="setDefaultPayment()" method="post"> <form (ngSubmit)="setDefaultPayment()" method="post">

View File

@@ -40,6 +40,7 @@ export class MyProfileComponent implements OnInit {
private selectedBillingTab:number = 0; private selectedBillingTab:number = 0;
private defaultUserPaymentId:number; private defaultUserPaymentId:number;
private defaultPaymentSet:boolean;
constructor (private paymentService:PaymentService, private loginService: LoginService, private userService: UserService, private router: Router){ constructor (private paymentService:PaymentService, private loginService: LoginService, private userService: UserService, private router: Router){
} }
@@ -103,7 +104,8 @@ export class MyProfileComponent implements OnInit {
onNewPayment () { onNewPayment () {
this.paymentService.newPayment(this.userPayment).subscribe( this.paymentService.newPayment(this.userPayment).subscribe(
res => { res => {
location.reload(); this.getCurrentUser();
this.selectedBillingTab = 0;
}, },
error => { error => {
console.log(error.text()); console.log(error.text());
@@ -120,7 +122,8 @@ export class MyProfileComponent implements OnInit {
onRemovePayment(id:number) { onRemovePayment(id:number) {
this.paymentService.removePayment(id).subscribe( this.paymentService.removePayment(id).subscribe(
res => { res => {
location.reload(); this.getCurrentUser();
}, },
error => { error => {
console.log(error.text()); console.log(error.text());
@@ -129,10 +132,13 @@ export class MyProfileComponent implements OnInit {
} }
setDefaultPayment() { setDefaultPayment() {
this.defaultPaymentSet=false;
this.paymentService.setDefaultPayment(this.defaultUserPaymentId).subscribe( this.paymentService.setDefaultPayment(this.defaultUserPaymentId).subscribe(
res => { res => {
console.log(res.text()); this.getCurrentUser();
location.reload(); this.defaultPaymentSet=true;
// this.selectedProfileTab = 2;
// this.selectedBillingTab = 0;
}, },
error => { error => {
console.log(error.text()); 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() { ngOnInit() {
this.loginService.checkSession().subscribe( this.loginService.checkSession().subscribe(
res => { res => {
@@ -150,22 +175,7 @@ export class MyProfileComponent implements OnInit {
} }
); );
this.userService.getCurrentUser().subscribe( this.getCurrentUser();
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);
}
);
for (let s in AppConst.usStates) { for (let s in AppConst.usStates) {
this.stateList.push(s); this.stateList.push(s);
@@ -176,6 +186,7 @@ export class MyProfileComponent implements OnInit {
this.userPayment.expiryMonth=""; this.userPayment.expiryMonth="";
this.userPayment.expiryYear=""; this.userPayment.expiryYear="";
this.userPayment.userBilling = this.userBilling; this.userPayment.userBilling = this.userBilling;
this.defaultPaymentSet=false;
} }
} }