Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/v3/src/app/pages/home/home.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="exp-header">
<h2 class="headline-2"
[innerHTML]="experience.name"></h2>
<div class="button-group-no-gap" *ngIf="projectBrief || showProjectHub">
<div class="button-group-no-gap" *ngIf="!isExpert && (projectBrief || showProjectHub)">
<ion-button fill="clear"
size="small"
class="project-brief-btn"
Expand Down
14 changes: 14 additions & 0 deletions projects/v3/src/app/pages/home/home.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ describe('HomePage', () => {
expect(component.showProjectHub).toBe(false);
});

it('should treat mentor users as expert users', async () => {
storageService.getUser.and.returnValue({
role: 'mentor',
apikey: 'test-key',
projectId: 1,
teamId: 1,
});

await component.updateDashboard();

expect(component.isExpert).toBe(true);
expect(component.isParticipant).toBe(false);
});

it('should call service methods to fetch data', async () => {
await component.updateDashboard();
expect(homeService.getMilestones).toHaveBeenCalled();
Expand Down
27 changes: 15 additions & 12 deletions projects/v3/src/app/pages/home/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {

isMobile: boolean;
isParticipant: boolean;
isExpert: boolean;
isExpertWithoutTeam: boolean;
pulseCheckIndicatorEnabled: boolean;
activityProgresses = {};
Expand Down Expand Up @@ -96,10 +97,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
}

ngOnInit() {
const role = this.storageService.getUser().role;
const teamId = this.storageService.getUser().teamId;
this.isParticipant = role === 'participant';
this.isExpertWithoutTeam = role === 'mentor' && !teamId;
this.updateUserRoleState();
this.pulseCheckIndicatorEnabled = this.storageService.getFeature('pulseCheckIndicator');
this.isMobile = this.utils.isMobile();

Expand All @@ -110,10 +108,8 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
takeUntil(this.unsubscribe$)
)
.subscribe(() => {
// re-evaluate expert without team status when team changes
const currentRole = this.storageService.getUser().role;
const currentTeamId = this.storageService.getUser().teamId;
this.isExpertWithoutTeam = currentRole === 'mentor' && !currentTeamId;
// re-evaluate role state when team changes
this.updateUserRoleState();
});

this.homeService.milestones$
Expand Down Expand Up @@ -219,10 +215,7 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
await this.sharedService.refreshJWT(); // refresh JWT token [CORE-6083]

// re-evaluate user role and team status after JWT refresh updates teamId
const role = this.storageService.getUser().role;
const teamId = this.storageService.getUser().teamId;
this.isParticipant = role === 'participant';
this.isExpertWithoutTeam = role === 'mentor' && !teamId;
this.updateUserRoleState();

this.experience = this.storageService.get("experience");
this.showProjectHub = this.storageService.getFeature('showProjectHub');
Expand Down Expand Up @@ -283,6 +276,16 @@ export class HomePage implements OnInit, OnDestroy, AfterViewChecked {
this.router.navigate(["experiences"]);
}

private updateUserRoleState(): void {
const user = this.storageService.getUser() || {};
const role = user.role;
const teamId = user.teamId;

this.isParticipant = role === 'participant';
this.isExpert = role === 'mentor';
this.isExpertWithoutTeam = this.isExpert && !teamId;
}

switchContent(event) {
// update points upon switching to badges tab
if (event.detail.value === "badges") {
Expand Down