Skip to content
Snippets Groups Projects
Commit df71bf7c authored by Etienne LOUPIAS's avatar Etienne LOUPIAS
Browse files

add empty offer if needed for connected user

parent 494acadb
No related branches found
No related tags found
1 merge request!936Resolve "[modification fiche structure] - Offre structure vs. Offre accompagnant numérique + ordre des blocs"
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment