diff --git a/src/app/profile/structure-edition-summary/structure-edition-summary.component.ts b/src/app/profile/structure-edition-summary/structure-edition-summary.component.ts index 6430bef42a3fd6e5d8e6c18579840408b727d2fd..569b61ab4f29bf96945016a976bf87aca12a73fe 100644 --- a/src/app/profile/structure-edition-summary/structure-edition-summary.component.ts +++ b/src/app/profile/structure-edition-summary/structure-edition-summary.component.ts @@ -93,6 +93,7 @@ export class StructureEditionSummaryComponent implements OnInit { this.members = structureWithOwners.owners; // Get personal offers for each member of the structure + const userId = this.profileService.getId(); this.members.forEach((member) => { // Return personal offer if the user has one in this structure const personalOffer = this.structure.personalOffers.find((structureOffer) => @@ -102,7 +103,7 @@ export class StructureEditionSummaryComponent implements OnInit { // Get categories labels if (personalOffer) { // Check if it is the user's own offer - const isMyself = this.profileService.getId() === member._id; + const isMyself = userId === member._id; const offerHolder = { user: member, @@ -120,7 +121,23 @@ export class StructureEditionSummaryComponent implements OnInit { } }); - // Add the structure offer to the beginning of the array + // If the connected user has no offer for this structure, add empty offer to the beginning of the array so they can edit it + if (!this.offerHolders.some((offerHolder) => offerHolder.user._id === userId)) { + // Check if the connected user is member of the structure (admin can edit the structure but is not member of the structure) + const member = this.members.find((member) => member._id === userId); + if (member) { + this.offerHolders.unshift({ + user: member, + isMyself: true, + offers: { + categories: { advancedSkills: [], baseSkills: [], onlineProcedures: [] }, + categoriesDisplay: { advancedSkills: [], baseSkills: [], onlineProcedures: [] }, + }, + }); + } + } + + // Add the structure offer to the beginning of the array (in first position, before the connected user) this.offerHolders.unshift({ structure: this.structure, offers: this.structure,