From bf5db27cd8f3c3110a6194837e06a420869ac4be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20PAILHAREY?= <rpailharey@grandlyon.com>
Date: Mon, 23 May 2022 14:41:58 +0000
Subject: [PATCH] fix(profile): conditional display of the job and the employer
 in profile

---
 src/app/profile/profile.component.html |  2 +-
 src/app/profile/profile.component.ts   |  4 +++-
 src/app/utils/utils.ts                 | 10 ++++++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/app/profile/profile.component.html b/src/app/profile/profile.component.html
index f374fb6b8..00f5d7373 100644
--- a/src/app/profile/profile.component.html
+++ b/src/app/profile/profile.component.html
@@ -36,7 +36,7 @@
       ></app-svg-icon>
       <div class="information">
         <div class="name">{{ userProfile.name }} {{ userProfile.surname }}</div>
-        <div class="job">{{ userProfile.job.name }}, {{ userProfile.employer.name }}</div>
+        <div *ngIf="utils.getJobEmployer(userProfile)" class="job">{{ utils.getJobEmployer(userProfile) }}</div>
         <div class="phone">{{ userProfile.phone | phone }}</div>
         <a class="email" href="mailto:{{ userProfile.email }}">{{ userProfile.email }}</a>
         <div class="description" *ngIf="userProfile.description">{{ userProfile.description }}</div>
diff --git a/src/app/profile/profile.component.ts b/src/app/profile/profile.component.ts
index 2a2810b38..c92d54a5d 100644
--- a/src/app/profile/profile.component.ts
+++ b/src/app/profile/profile.component.ts
@@ -5,6 +5,7 @@ import { User } from '../models/user.model';
 import { StructureService } from '../services/structure.service';
 import { ButtonType } from '../shared/components/button/buttonType.enum';
 import { ProfileService } from './services/profile.service';
+import { Utils } from '../utils/utils';
 
 @Component({
   selector: 'app-profile',
@@ -19,7 +20,8 @@ export class ProfileComponent implements OnInit {
   constructor(
     private profileService: ProfileService,
     private structureService: StructureService,
-    private router: Router
+    private router: Router,
+    public utils: Utils
   ) {}
 
   ngOnInit(): void {
diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts
index a949f40fd..313183529 100644
--- a/src/app/utils/utils.ts
+++ b/src/app/utils/utils.ts
@@ -1,5 +1,6 @@
 import { Injectable } from '@angular/core';
 import { FormGroup } from '@angular/forms';
+import { User } from '../models/user.model';
 
 @Injectable({
   providedIn: 'root',
@@ -25,4 +26,13 @@ export class Utils {
     }
     return phoneNumber;
   }
+
+  public getJobEmployer(userProfile: User): string {
+    const jobName = userProfile.job?.name;
+    const employerName = userProfile.employer?.name;
+    if (!jobName && !employerName) return '';
+    if (!jobName && employerName) return employerName;
+    if (jobName && !employerName) return jobName;
+    if (jobName && employerName) return `${jobName}, ${employerName}`;
+  }
 }
-- 
GitLab