Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Observable } from 'rxjs';
import { v4 as uuid } from 'uuid';
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { B2bUser } from '../../models/b2b-user/b2b-user.model';
@Component({
selector: 'ish-user-create-page',
templateUrl: './user-create-page.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UserCreatePageComponent implements OnInit {
loading$: Observable<boolean>;
userError$: Observable<HttpError>;
form: FormGroup = this.fb.group({
profile: this.fb.group({}),
roleIDs: this.fb.control([]),
userBudget: this.fb.group({}),
});
constructor(private fb: FormBuilder, private organizationManagementFacade: OrganizationManagementFacade) {}
ngOnInit() {
this.loading$ = this.organizationManagementFacade.usersLoading$;
this.userError$ = this.organizationManagementFacade.usersError$;
}
get profile(): FormGroup {
return this.form.get('profile') as FormGroup;
}
get budgetForm() {
return this.form.get('userBudget') as FormGroup;
}
submitForm() {
Iif (this.form.valid) {
const formValue = this.form.value;
const user: B2bUser = {
title: formValue.profile.title,
firstName: formValue.profile.firstName,
lastName: formValue.profile.lastName,
email: formValue.profile.email,
active: formValue.profile.active,
phoneHome: formValue.profile.phoneHome,
birthday: formValue.profile.birthday === '' ? undefined : formValue.birthday,
businessPartnerNo: `U${uuid()}`,
roleIDs: formValue.roleIDs,
userBudget: formValue.userBudget.currency
? {
budget: formValue.userBudget.budgetValue
? { value: formValue.userBudget.budgetValue, currency: formValue.userBudget.currency, type: 'Money' }
: undefined,
budgetPeriod: formValue.userBudget.budgetPeriod,
orderSpentLimit: formValue.userBudget.orderSpentLimitValue
? {
value: formValue.userBudget.orderSpentLimitValue,
currency: formValue.userBudget.currency,
type: 'Money',
}
: undefined,
}
: undefined,
};
this.organizationManagementFacade.addUser(user);
}
}
}
|