Merge pull request #4 from Pear-Trading/finn/AccountFix

Fixed account editing
This commit is contained in:
Finn 2017-09-04 16:31:19 +01:00 committed by GitHub
commit 7bdcc5fb7e

View file

@ -13,7 +13,7 @@ export class AccountEditComponent implements OnInit {
settingOrganisationForm: FormGroup; settingOrganisationForm: FormGroup;
settingCustomerForm: FormGroup; settingCustomerForm: FormGroup;
accountType: any; accountType: any;
@ViewChild('fileInput') fileInput; // @ViewChild('fileInput') fileInput;
submitStatus: any; submitStatus: any;
constructor( constructor(
@ -26,7 +26,6 @@ export class AccountEditComponent implements OnInit {
postcode : ['', [Validators.required]], postcode : ['', [Validators.required]],
password : ['', [Validators.required]], password : ['', [Validators.required]],
new_password : [''], new_password : [''],
// profile_picture : [''],
}); });
this.settingOrganisationForm = this.formBuilder.group({ this.settingOrganisationForm = this.formBuilder.group({
name : ['', [Validators.required]], name : ['', [Validators.required]],
@ -80,13 +79,13 @@ export class AccountEditComponent implements OnInit {
const settingOrganisationForm = this.settingOrganisationForm.value; const settingOrganisationForm = this.settingOrganisationForm.value;
// image upload code // image upload code
const fi = this.fileInput.nativeElement; // const fi = this.fileInput.nativeElement;
const data = new FormData(); // const data = new FormData();
if (fi.files && fi.files[0]) { // if (fi.files && fi.files[0]) {
const fileToUpload = fi.files[0]; // const fileToUpload = fi.files[0];
data.append('file', fileToUpload); // data.append('file', fileToUpload);
} // }
const submitData = { const submitData = {
email: settingForm.email, email: settingForm.email,
@ -98,11 +97,11 @@ export class AccountEditComponent implements OnInit {
town: settingOrganisationForm.town, town: settingOrganisationForm.town,
}; };
data.append('form', JSON.stringify(submitData)); // data.append('form', JSON.stringify(submitData));
console.log(data); console.log(submitData);
this.api this.api
.accountEditUpdate(data) .accountEditUpdate(submitData)
.subscribe( .subscribe(
result => { result => {
console.log('data submitted!'); console.log('data submitted!');
@ -130,13 +129,13 @@ export class AccountEditComponent implements OnInit {
const settingCustomerForm = this.settingCustomerForm.value; const settingCustomerForm = this.settingCustomerForm.value;
// image upload code // image upload code
const fi = this.fileInput.nativeElement; // const fi = this.fileInput.nativeElement;
const data = new FormData(); const data = new FormData();
if (fi.files && fi.files[0]) { // if (fi.files && fi.files[0]) {
const fileToUpload = fi.files[0]; // const fileToUpload = fi.files[0];
data.append('file', fileToUpload); // data.append('file', fileToUpload);
} // }
const submitData = { const submitData = {
email: settingForm.email, email: settingForm.email,
@ -147,10 +146,10 @@ export class AccountEditComponent implements OnInit {
display_name: settingCustomerForm.display_name, display_name: settingCustomerForm.display_name,
}; };
data.append('form', JSON.stringify(submitData)); // data.append('form', JSON.stringify(submitData));
this.api this.api
.accountEditUpdate(data) .accountEditUpdate(submitData)
.subscribe( .subscribe(
result => { result => {
console.log('data submitted!'); console.log('data submitted!');