diff --git a/src/app/profile/edit/edit.component.ts b/src/app/profile/edit/edit.component.ts index fc39fd0880bd6119d105e5fe4978a2577c7bae95..8e272bcc28d8b65df4a7193787c27a9acd113af4 100644 --- a/src/app/profile/edit/edit.component.ts +++ b/src/app/profile/edit/edit.component.ts @@ -56,6 +56,7 @@ export class EditComponent implements OnInit { public employers: Employer[]; private selectedEmployer: Employer; private isAlreadySearching = false; + public isNewUser = false; @ViewChild('searchEmployer') searchEmployer: ElementRef; @ViewChild('newJobInput') newJobInput: ElementRef; @@ -76,7 +77,9 @@ export class EditComponent implements OnInit { this.userProfile = new User(profile); this.initialUserProfile = { ...profile }; this.selectedEmployer = { ...profile.employer }; - + if (!profile.employer || !profile.job) { + this.isNewUser = true; + } const otherJob = new Job({ name: 'Autre' }); this.profileService.getJobs().subscribe((jobs) => { this.jobs = [...jobs, otherJob]; @@ -165,10 +168,18 @@ export class EditComponent implements OnInit { return this.passwordValid(this.newPassword) && this.newPassword == this.newPasswordConfirm; } } else if (this.currentTab === tabsEnum.employer) { - return !!( + if (this.isNewUser) { + if (!this.selectedEmployer || !this.selectedJob) { + return false; + } + return true; + } else if ( this.selectedEmployer?.name !== this.userProfile.employer?.name || this.selectedJob?.name !== this.userProfile.job?.name - ); + ) { + return true; + } + return false; } else if (this.currentTab === tabsEnum.description) { return this.descriptionValid() && this.initialUserProfile.description !== this.userProfile.description; } diff --git a/src/app/profile/profile-structure/profile-structure.component.html b/src/app/profile/profile-structure/profile-structure.component.html index d151d648c0806493ac7e48bfbfe05ab24f876931..428635d98e976297178344cef978eddfed1b0dd6 100644 --- a/src/app/profile/profile-structure/profile-structure.component.html +++ b/src/app/profile/profile-structure/profile-structure.component.html @@ -130,7 +130,7 @@ (click)="addMemberModalOpenned = true" ></app-button> </div> - <div class="call-to-action" *ngIf="!isPublic && !this.personalOffer && userProfile.job.hasPersonalOffer"> + <div class="call-to-action" *ngIf="!isPublic && !this.personalOffer && userProfile.job?.hasPersonalOffer"> <app-button [type]="'button'" [iconBtn]="'add'" diff --git a/src/app/profile/profile-structure/profile-structure.component.ts b/src/app/profile/profile-structure/profile-structure.component.ts index 3299f2af81430a229b9da4e9cff187025b31fd4f..700c8fc3044991062cef08db0e5adb4e07c04ebb 100644 --- a/src/app/profile/profile-structure/profile-structure.component.ts +++ b/src/app/profile/profile-structure/profile-structure.component.ts @@ -68,11 +68,9 @@ export class ProfileStructureComponent implements OnInit { // Check if user has personal offers if ( - !this.userProfile || - !this.userProfile.job || - !this.userProfile.personalOffers || - !this.userProfile.job.hasPersonalOffer || - this.userProfile.personalOffers.length === 0 + !this.userProfile?.personalOffers || + !this.userProfile?.job?.hasPersonalOffer || + this.userProfile?.personalOffers?.length === 0 ) return null;