forked from alfio-event/alf.io-public-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement "my profile" (alfio-event#78)
* initial work for displaying user profile * update profile * add guard for preventing users to access my-profile
- Loading branch information
Showing
15 changed files
with
234 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<div class="container mt-2" *ngIf="userForm"> | ||
<form [formGroup]="userForm" (submit)="save()"> | ||
<div class="application-container p-md-4"> | ||
<app-topbar [contentLanguages]="languages"></app-topbar> | ||
<div class="page-header"> | ||
<h1>{{ 'user.menu.my-profile' | translate }}</h1> | ||
<small>{{ 'my-profile.description' | translate }}</small> | ||
</div> | ||
|
||
<div class="row mt-3" [formGroup]="userForm"> | ||
<div class="col-12 col-sm-6"> | ||
<div class="form-group"> | ||
<label for="first-name">{{'common.first-name'|translate}}{{' '}}*</label> | ||
<input id="first-name" class="form-control" formControlName="firstName" aria-required="true" type="text" autocomplete="fname" [attr.maxlength]="255" appInvalidFeedback> | ||
</div> | ||
</div> | ||
<div class="col-12 col-sm-6"> | ||
<div class="form-group"> | ||
<label for="last-name">{{'common.last-name'|translate}}{{' '}}*</label> | ||
<input id="last-name" class="form-control" formControlName="lastName" aria-required="true" type="text" autocomplete="lname" [attr.maxlength]="255" appInvalidFeedback> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div *ngIf="invoicingConfiguration.invoiceAllowed"> | ||
<app-invoice-form [form]="userForm" [invoicingConfiguration]="invoicingConfiguration"></app-invoice-form> | ||
</div> | ||
|
||
<hr> | ||
<div class="mt-5"> | ||
<div class="row d-flex justify-content-md-between"> | ||
<div class="col-md-5 order-md-1 col-12 mb-2"> | ||
<button class="block-button btn btn-success">{{ 'common.confirm' | translate }}</button> | ||
</div> | ||
<div class="col-md-5 order-md-0 col-12 mt-2 mt-md-0 mb-2"> | ||
<a class="block-button btn btn-light" [routerLink]="['/']" translate="to-home"></a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import {Component, OnInit} from '@angular/core'; | ||
import {UserService} from '../shared/user.service'; | ||
import {User} from '../model/user'; | ||
import {TranslateService} from '@ngx-translate/core'; | ||
import {I18nService} from '../shared/i18n.service'; | ||
import {InvoicingConfiguration, Language} from '../model/event'; | ||
import {zip} from 'rxjs'; | ||
import {FormBuilder, FormGroup, Validators} from '@angular/forms'; | ||
import {BookingComponent} from '../reservation/booking/booking.component'; | ||
import {handleServerSideValidationError} from '../shared/validation-helper'; | ||
import {ErrorDescriptor} from '../model/validated-response'; | ||
import {InfoService} from '../shared/info.service'; | ||
|
||
@Component({ | ||
selector: 'app-my-profile', | ||
templateUrl: './my-profile.component.html' | ||
}) | ||
export class MyProfileComponent implements OnInit { | ||
|
||
user?: User; | ||
languages: Language[]; | ||
userForm?: FormGroup; | ||
invoicingConfiguration?: InvoicingConfiguration; | ||
globalErrors: ErrorDescriptor[]; | ||
|
||
constructor(private userService: UserService, | ||
private translateService: TranslateService, | ||
private i18nService: I18nService, | ||
private formBuilder: FormBuilder, | ||
private infoService: InfoService) { | ||
this.userForm = this.formBuilder.group({ | ||
firstName: this.formBuilder.control(null, Validators.required), | ||
lastName: this.formBuilder.control(null, Validators.required), | ||
addCompanyBillingDetails: this.formBuilder.control(false), | ||
billingAddressCompany: this.formBuilder.control(null), | ||
billingAddressLine1: this.formBuilder.control(null), | ||
billingAddressLine2: this.formBuilder.control(null), | ||
billingAddressZip: this.formBuilder.control(null), | ||
billingAddressCity: this.formBuilder.control(null), | ||
billingAddressState: this.formBuilder.control(null), | ||
vatCountryCode: this.formBuilder.control(null), | ||
skipVatNr: this.formBuilder.control(false), | ||
vatNr: this.formBuilder.control(null), | ||
italyEInvoicingFiscalCode: this.formBuilder.control(null), | ||
italyEInvoicingReferenceType: this.formBuilder.control(null), | ||
italyEInvoicingReferenceAddresseeCode: this.formBuilder.control(null), | ||
italyEInvoicingReferencePEC: this.formBuilder.control(null), | ||
italyEInvoicingSplitPayment: this.formBuilder.control(null), | ||
}); | ||
} | ||
|
||
ngOnInit(): void { | ||
zip(this.userService.getUserIdentity(), this.i18nService.getAvailableLanguages(), this.infoService.getInfo()) | ||
.subscribe(([user, languages, info]) => { | ||
this.languages = languages; | ||
this.i18nService.setPageTitle('user.menu.my-profile', null); | ||
this.invoicingConfiguration = info.invoicingConfiguration; | ||
let values: {[p: string]: any} = { | ||
firstName: user.firstName, | ||
lastName: user.lastName | ||
}; | ||
const userBillingDetails = user.profile?.billingDetails; | ||
if (userBillingDetails != null) { | ||
values = { | ||
...values, | ||
billingAddressCompany: userBillingDetails.companyName, | ||
billingAddressLine1: userBillingDetails.addressLine1, | ||
billingAddressLine2: userBillingDetails.addressLine2, | ||
billingAddressZip: userBillingDetails.zip, | ||
billingAddressCity: userBillingDetails.city, | ||
billingAddressState: userBillingDetails.state, | ||
vatCountryCode: userBillingDetails.country, | ||
vatNr: userBillingDetails.taxId, | ||
italyEInvoicingFiscalCode: BookingComponent.optionalGet(userBillingDetails, (i) => i.fiscalCode), | ||
italyEInvoicingReferenceType: BookingComponent.optionalGet(userBillingDetails, (i) => i.referenceType), | ||
italyEInvoicingReferenceAddresseeCode: BookingComponent.optionalGet(userBillingDetails, (i) => i.addresseeCode), | ||
italyEInvoicingReferencePEC: BookingComponent.optionalGet(userBillingDetails, (i) => i.pec), | ||
italyEInvoicingSplitPayment: BookingComponent.optionalGet(userBillingDetails, (i) => i.splitPayment) | ||
}; | ||
} | ||
this.userForm.patchValue(values); | ||
}); | ||
} | ||
|
||
|
||
save(): void { | ||
if (this.userForm.valid) { | ||
this.userService.updateUser(this.userForm.value) | ||
.subscribe(res => { | ||
if (res.success) { | ||
this.user = res.value; | ||
} else { | ||
handleServerSideValidationError(res.validationErrors, this.userForm); | ||
} | ||
}, err => this.globalErrors = handleServerSideValidationError(err, this.userForm)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.