2018-10-19 11:28:08 -04:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
|
import { Logger } from '../core/logger';
|
|
|
|
|
import {
|
|
|
|
|
FormGroup,
|
|
|
|
|
FormControl,
|
|
|
|
|
Validators,
|
|
|
|
|
FormBuilder,
|
|
|
|
|
AbstractControl,
|
|
|
|
|
ValidationErrors
|
|
|
|
|
} from '@angular/forms';
|
|
|
|
|
import { OrgService } from '../core/org.service';
|
|
|
|
|
import { Org } from '../shared/org';
|
|
|
|
|
import { AppError } from '../shared/error';
|
|
|
|
|
import { Util } from '../shared/util';
|
2019-06-28 14:35:46 -04:00
|
|
|
import { DateUtil } from '../shared/dateutil';
|
2018-10-19 11:28:08 -04:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-neworg',
|
|
|
|
|
templateUrl: 'neworg.html'
|
|
|
|
|
})
|
|
|
|
|
export class NewOrgPage {
|
|
|
|
|
public form: FormGroup;
|
|
|
|
|
public error: AppError;
|
|
|
|
|
public joinOrgForm: FormGroup;
|
|
|
|
|
public joinOrgError: AppError;
|
2019-06-28 14:35:46 -04:00
|
|
|
public timezones: string[];
|
|
|
|
|
public defaultTz: string;
|
2018-10-19 11:28:08 -04:00
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private log: Logger,
|
|
|
|
|
private orgService: OrgService,
|
|
|
|
|
private fb: FormBuilder
|
|
|
|
|
) {
|
2019-06-28 14:35:46 -04:00
|
|
|
this.timezones = DateUtil.getTimezones();
|
|
|
|
|
this.defaultTz = DateUtil.getDefaultTimezone();
|
|
|
|
|
|
2018-10-19 11:28:08 -04:00
|
|
|
this.form = fb.group({
|
|
|
|
|
'name': ['', Validators.required],
|
|
|
|
|
'currency': ['USD', Validators.required],
|
|
|
|
|
'precision': [2, Validators.required],
|
2019-06-28 14:35:46 -04:00
|
|
|
'timezone': [this.defaultTz, Validators.required],
|
2020-07-23 11:45:26 -06:00
|
|
|
'createDefaultAccounts': ['business']
|
2018-10-19 11:28:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.joinOrgForm = fb.group({
|
|
|
|
|
'inviteId': [null, Validators.required]
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
|
//this.dataService.setLoading(true);
|
|
|
|
|
let org = new Org(this.form.value);
|
|
|
|
|
org.id = Util.newGuid();
|
|
|
|
|
|
|
|
|
|
this.log.debug(org);
|
|
|
|
|
|
|
|
|
|
this.orgService.newOrg(org, this.form.value['createDefaultAccounts'])
|
|
|
|
|
.subscribe(
|
|
|
|
|
org => {
|
|
|
|
|
this.log.debug(org);
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
//this.dataService.setLoading(false);
|
|
|
|
|
this.log.debug('An error occurred!');
|
|
|
|
|
this.log.debug(error);
|
|
|
|
|
this.error = error;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
joinOrgSubmit() {
|
|
|
|
|
this.log.debug('join org');
|
|
|
|
|
this.log.debug(this.joinOrgForm.value.id);
|
|
|
|
|
this.orgService.acceptInvite(this.joinOrgForm.value.inviteId)
|
|
|
|
|
.switchMap(invite => {
|
|
|
|
|
return this.orgService.selectOrg(invite.orgId)
|
|
|
|
|
})
|
|
|
|
|
.subscribe(org => {
|
|
|
|
|
console.log('joined org ' + org.id);
|
|
|
|
|
}, err => {
|
|
|
|
|
this.joinOrgError = err;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|