Settings component Save_Account button updated - testing version

This commit is contained in:
Rene V. Vergara A. 2022-09-06 21:44:36 -05:00
parent 87ef9ea10a
commit 12dbdd999d
4 changed files with 51 additions and 23 deletions

View file

@ -21,7 +21,7 @@
} }
::ng-deep .mat-snack-bar-container.error { ::ng-deep .mat-snack-bar-container.error {
background: antiquewhite; background: navajowhite;
color: red; color: red;
} }
@ -32,6 +32,6 @@
::ng-deep .mat-snack-bar-container.warning { ::ng-deep .mat-snack-bar-container.warning {
background: antiquewhite; background: antiquewhite;
color: #fdebd0; color: black;
} }

View file

@ -78,7 +78,7 @@
label="Integrations" label="Integrations"
style="align-items: center;"> style="align-items: center;">
<div class="container" style="margin-bottom: 20px;"> <div class="container" style="margin-bottom: 20px;">
<mat-dialog-content [formGroup]="settingsForm"> <mat-dialog-content [formGroup]="accCodForm">
<div style="height: 10px; <div style="height: 10px;
margin-top: 10px;"> margin-top: 10px;">
</div> </div>
@ -139,7 +139,7 @@
<input matInput <input matInput
width="100%" width="100%"
placeholder="9999999999" placeholder="9999999999"
formControlName="xeroAccCod" formControlName="xAcc"
(change)="xeroAccCodChanged($event)"> (change)="xeroAccCodChanged($event)">
</mat-form-field> </mat-form-field>

View file

@ -23,6 +23,7 @@ export class SettingsComponent implements OnInit {
faCopy = faCopy; faCopy = faCopy;
// ------------------------------------ // ------------------------------------
settingsForm: UntypedFormGroup; settingsForm: UntypedFormGroup;
accCodForm: UntypedFormGroup;
owner: Owner; owner: Owner;
useZats: boolean; useZats: boolean;
proVersion: boolean = false; proVersion: boolean = false;
@ -76,6 +77,10 @@ export class SettingsComponent implements OnInit {
// proVersion: [data.invoices, Validators.required], // proVersion: [data.invoices, Validators.required],
vKey: [data.viewkey] vKey: [data.viewkey]
}); });
this.accCodForm = fb.group ({
xAcc: [this.xeroAccCod]
});
if (data.payconf) { if (data.payconf) {
this.settingsForm.get('vKey')!.enable(); this.settingsForm.get('vKey')!.enable();
} }
@ -94,6 +99,8 @@ export class SettingsComponent implements OnInit {
xeroService.getXeroAccountCode(this.owner.address); xeroService.getXeroAccountCode(this.owner.address);
this.accCodeUpdate.subscribe(accData => { this.accCodeUpdate.subscribe(accData => {
this.xeroAccCod = accData; this.xeroAccCod = accData;
console.log("xeroAccCod -> [" + this.xeroAccCod + "]");
this.accCodForm.get('xAcc')!.setValue(this.xeroAccCod);
}); });
} }
@ -156,10 +163,6 @@ export class SettingsComponent implements OnInit {
} }
saveAccCod() {
}
copyUrl() { copyUrl() {
// console.log("Inside copyUrl()"); // console.log("Inside copyUrl()");
if (navigator.clipboard) { if (navigator.clipboard) {
@ -176,11 +179,31 @@ export class SettingsComponent implements OnInit {
} }
} }
saveAccCod() {
this.xeroAccCod = this.accCodForm.value.xAcc;
console.log(">>> " + this.xeroAccCod);
if ( this.xeroAccCod.length <= 10 ) {
const savedAcc = this.xeroService
.setXeroAccountCode(this.owner.address,
this.xeroAccCod );
console.log("savedAcc: " + JSON.stringify(savedAcc));
if ( savedAcc ) {
this.notifierService
.showNotification("Account saved correctly!!","Close",'success');
} else {
this.notifierService
.showNotification("Error while saving account code!!","Close",'error');
}
} else {
this.notifierService
.showNotification("Invalid Account code (10 chars max.)","Close",'error');
}
}
xeroAccCodChanged( arg: any ) { xeroAccCodChanged( arg: any ) {
// console.log("Account Code changed: " + arg.target.value); // console.log("Account Code changed: " + arg.target.value);
// console.log(arg); // console.log(arg);
this.saveAccOk = (arg.target.value !== ''); this.saveAccOk = (arg.target.value != this.xeroAccCod );
} }
} }

View file

@ -77,14 +77,19 @@ export class XeroService {
} }
setXeroAccountCode(address: string, code: string){ setXeroAccountCode(address: string, code: string) : boolean {
let res : boolean = false;
const params = new HttpParams().append('address', address).append('code', code); const params = new HttpParams().append('address', address).append('code', code);
let obs = this.http.post(this.beUrl + 'api/xerotoken', {}, {headers: this.reqHeaders, params: params, observe: 'response'}); let obs = this.http.post(this.beUrl + 'api/xerotoken', {}, {headers: this.reqHeaders, params: params, observe: 'response'});
obs.subscribe(responseData => { obs.subscribe(responseData => {
if (responseData.status == 202) { if (responseData.status == 202) {
console.log('Account saved'); console.log('Account saved');
res = true;
} }
}, error => {
console.log('Oops!! ',error.message);
res = false;
}); });
return obs; return res;
} }
} }