diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index b7575f9c932c9632ed5e062f972bae3a2b764658..305838f568c23997cc9a6e1d2af23b6baeb79dd1 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -83,7 +83,9 @@ </div> </div> <div fxLayout="row" fxLayoutAlign="center center" class="hide-on-print"> - <a *ngIf="!isClaimed" (click)="toggleClaimModal()" class="primary" tabindex="0">Revendiquer cette structure</a> + <a *ngIf="!isClaimed && userIsLoggedIn()" (click)="toggleClaimModal()" class="primary" tabindex="0" + >Revendiquer cette structure</a + > <a *ngIf="profileService.isLinkedToStructure(structure._id) || profileService.isAdmin()" (click)="editStructure()" diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts index 7baf15f4bb55e55fda563524bf0bd30d78b581e8..dc07c8743cdbe5471f271df6e170008cb664d460 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.ts @@ -63,7 +63,7 @@ export class StructureDetailsComponent implements OnInit { async ngOnInit(): Promise<void> { this.isLoading = true; - if (this.authService.isLoggedIn()) { + if (this.userIsLoggedIn()) { this.currentProfile = await this.profileService.getProfile(); } this.isClaimed = await this.structureService.isClaimed(this.structure._id, this.currentProfile).toPromise(); @@ -90,6 +90,10 @@ export class StructureDetailsComponent implements OnInit { } } + public userIsLoggedIn(): boolean { + return this.authService.isLoggedIn(); + } + public getEquipmentsLabel(equipment: Equipment): string { switch (equipment) { case Equipment.wifi: @@ -148,8 +152,11 @@ export class StructureDetailsComponent implements OnInit { public claimStructure(shouldClaim: boolean): void { this.toggleClaimModal(); if (shouldClaim) { - this.isEditMode = false; - this.displayForm(); + this.profileService.getProfile().then((user: User) => { + this.structureService.claimStructureWithAccount(this.structure._id, user).subscribe(() => { + this.isClaimed = true; + }); + }); } } // Show/hide form structure