|
@@ -1,6 +1,10 @@
|
|
|
import { Component, Input } from '@angular/core';
|
|
import { Component, Input } from '@angular/core';
|
|
|
import { EventsApiService } from 'src/app/events-api.service';
|
|
import { EventsApiService } from 'src/app/events-api.service';
|
|
|
import { GroupEvent } from '../group-event';
|
|
import { GroupEvent } from '../group-event';
|
|
|
|
|
+import { RegistrationState, RegistrationStateItems } from '../registration-state';
|
|
|
|
|
+import { Registration } from '../registration';
|
|
|
|
|
+import { AuthService } from '@auth0/auth0-angular';
|
|
|
|
|
+import { combineLatest, take } from 'rxjs';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'app-event-view',
|
|
selector: 'app-event-view',
|
|
@@ -12,8 +16,14 @@ export class EventViewComponent {
|
|
|
public eventId: string = '';
|
|
public eventId: string = '';
|
|
|
|
|
|
|
|
public event: GroupEvent | null = null;
|
|
public event: GroupEvent | null = null;
|
|
|
|
|
+ public registrations: Array<Registration> = [];
|
|
|
|
|
+
|
|
|
|
|
+ public registrationStates = RegistrationStateItems;
|
|
|
|
|
+
|
|
|
|
|
+ public currentState = RegistrationState.Unknown;
|
|
|
|
|
|
|
|
public constructor(
|
|
public constructor(
|
|
|
|
|
+ private readonly authService: AuthService,
|
|
|
private readonly eventsApi: EventsApiService
|
|
private readonly eventsApi: EventsApiService
|
|
|
) { }
|
|
) { }
|
|
|
|
|
|
|
@@ -21,5 +31,20 @@ export class EventViewComponent {
|
|
|
this.eventsApi.getEvent(this.eventId).then(event => {
|
|
this.eventsApi.getEvent(this.eventId).then(event => {
|
|
|
this.event = event;
|
|
this.event = event;
|
|
|
});
|
|
});
|
|
|
|
|
+ combineLatest([this.authService.user$, this.eventsApi.getRegistrations(this.eventId)])
|
|
|
|
|
+ .pipe(take(1))
|
|
|
|
|
+ .subscribe(([user, registrations]) => {
|
|
|
|
|
+ const currentRegistrationIndex = registrations.findIndex(r => r.owner?.userId === user?.sub);
|
|
|
|
|
+
|
|
|
|
|
+ this.currentState = (currentRegistrationIndex >= 0 ? registrations.splice(currentRegistrationIndex, 1)[0] : null)?.status ?? RegistrationState.Unknown;
|
|
|
|
|
+ this.registrations = registrations;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public updateRegistration(evt: any): void {
|
|
|
|
|
+ if (this.event) {
|
|
|
|
|
+ console.log(evt, this.currentState);
|
|
|
|
|
+ this.eventsApi.register(this.event, this.currentState);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|