Skip to content

Commit

Permalink
Merge pull request #1163 from ORCID/member-info
Browse files Browse the repository at this point in the history
Member info
  • Loading branch information
bobcaprice authored Apr 22, 2024
2 parents ccdc872 + 09d0f76 commit 9f6bfbb
Show file tree
Hide file tree
Showing 15 changed files with 674 additions and 98 deletions.
14 changes: 0 additions & 14 deletions ui/src/app/home/generic-landing.component.html

This file was deleted.

Empty file.
21 changes: 0 additions & 21 deletions ui/src/app/home/generic-landing.component.spec.ts

This file was deleted.

10 changes: 0 additions & 10 deletions ui/src/app/home/generic-landing.component.ts

This file was deleted.

5 changes: 1 addition & 4 deletions ui/src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<div class="h-100">
<div class="d-flex flex-column h-100">
<div class="alert alert-success mt-3">{{ loggedInMessage }}</div>
<div *ngIf="memberData || memberData === null" class="h-100 home-container mb-3">
<router-outlet *ngIf="memberData"></router-outlet>
<app-generic-landing *ngIf="memberData === null" class="p-4 d-flex"></app-generic-landing>
</div>
<router-outlet></router-outlet>
</div>
</div>
</div>
Expand Down
16 changes: 5 additions & 11 deletions ui/src/app/home/home.component.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
:host {
max-width: 1250px;
display: block;
margin: auto;
height: 100%;
}

.home-container {
border: 2px solid #eeeeee;
border-radius: 5px 0px 0px 5px;
}

max-width: 1250px;
display: block;
margin: auto;
height: 100%;
}
14 changes: 3 additions & 11 deletions ui/src/app/home/home.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { HomeComponent } from './home.component'
import { MemberService } from '../member/service/member.service'
import { AccountService } from '../account'
import { of } from 'rxjs'

describe('HomeComponent', () => {
let component: HomeComponent
let fixture: ComponentFixture<HomeComponent>
let memberServiceSpy: jasmine.SpyObj<MemberService>
let accountServiceSpy: jasmine.SpyObj<AccountService>

beforeEach(() => {
accountServiceSpy = jasmine.createSpyObj('AccountService', ['getAccountData'])
memberServiceSpy = jasmine.createSpyObj('MemberService', ['getMemberData'])

TestBed.configureTestingModule({
declarations: [HomeComponent],
providers: [
{ provide: MemberService, useValue: memberServiceSpy },
{ provide: AccountService, useValue: accountServiceSpy },
],
providers: [{ provide: AccountService, useValue: accountServiceSpy }],
})
fixture = TestBed.createComponent(HomeComponent)
component = fixture.componentInstance

accountServiceSpy = TestBed.inject(AccountService) as jasmine.SpyObj<AccountService>
memberServiceSpy = TestBed.inject(MemberService) as jasmine.SpyObj<MemberService>
})

it('should call getAccountData but not getMemberData', () => {
Expand All @@ -37,7 +30,7 @@ describe('HomeComponent', () => {
component.ngOnInit()

expect(accountServiceSpy.getAccountData).toHaveBeenCalled()
expect(memberServiceSpy.getMemberData).toHaveBeenCalledTimes(0)
expect(component.loggedInMessage).toBeUndefined()
})

it('should call getMemberData if account data is not null', () => {
Expand All @@ -57,13 +50,12 @@ describe('HomeComponent', () => {
mfaEnabled: false,
})
)
memberServiceSpy.getMemberData.and.returnValue(of({}))

expect(component).toBeTruthy()

component.ngOnInit()

expect(accountServiceSpy.getAccountData).toHaveBeenCalled()
expect(memberServiceSpy.getMemberData).toHaveBeenCalled()
expect(component.loggedInMessage).toEqual('You are logged in as user email@email.com')
})
})
26 changes: 6 additions & 20 deletions ui/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,24 @@ import { IAccount } from '../account/model/account.model'
export class HomeComponent implements OnInit, OnDestroy {
account: IAccount | undefined | null
memberData: ISFMemberData | undefined | null
authenticationStateSubscription: Subscription | undefined
memberDataSubscription: Subscription | undefined
manageMemberSubscription: Subscription | undefined
salesforceId: string | undefined
loggedInMessage: string | undefined
accountServiceSubscription: Subscription | undefined

constructor(
private accountService: AccountService,
private memberService: MemberService
) {}
constructor(private accountService: AccountService) {}

ngOnInit() {
this.accountService.getAccountData().subscribe((account) => {
this.accountServiceSubscription = this.accountService.getAccountData().subscribe((account) => {
this.account = account
if (account) {
this.memberDataSubscription = this.memberService.getMemberData(account.salesforceId).subscribe((data) => {
this.memberData = data
})
this.loggedInMessage = $localize`:@@home.loggedIn.message.string:You are logged in as user ${account.email}`
}
})
}

ngOnDestroy() {
if (this.authenticationStateSubscription) {
this.authenticationStateSubscription.unsubscribe()
}
if (this.memberDataSubscription) {
this.memberDataSubscription.unsubscribe()
}
if (this.manageMemberSubscription) {
this.manageMemberSubscription.unsubscribe()
ngOnDestroy(): void {
if (this.accountServiceSubscription) {
this.accountServiceSubscription.unsubscribe()
}
}
}
7 changes: 4 additions & 3 deletions ui/src/app/home/home.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { CommonModule } from '@angular/common'
import { RouterModule } from '@angular/router'
import { routes } from './home.route'
import { HomeComponent } from './home.component'
import { GenericLandingComponent } from './generic-landing.component'
import { MemberInfoComponent } from './member-info/member-info.component'
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'

@NgModule({
imports: [CommonModule, RouterModule.forChild(routes)],
declarations: [HomeComponent, GenericLandingComponent],
imports: [CommonModule, RouterModule.forChild(routes), FontAwesomeModule],
declarations: [HomeComponent, MemberInfoComponent],
})
export class HomeModule {}
46 changes: 45 additions & 1 deletion ui/src/app/home/home.route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
import { Routes } from '@angular/router'
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, Routes } from '@angular/router'
import { HomeComponent } from '../home/home.component'
import { AuthGuard } from '../account/auth.guard'
import { MemberInfoComponent } from './member-info/member-info.component'
import { Injectable, inject } from '@angular/core'
import { MemberService } from '../member/service/member.service'
import { Observable, map } from 'rxjs'

export const ManageMemberGuard = (route: ActivatedRouteSnapshot): Observable<boolean> | boolean => {
const router = inject(Router)
const memberService = inject(MemberService)

return memberService.getManagedMember().pipe(
map((salesforceId) => {
if (salesforceId) {
const segments = ['manage', salesforceId]

if (route['routeConfig']?.path === 'edit') {
segments.push('edit')
}

if (route['routeConfig']?.path === 'contact/new') {
segments.push('contact', 'new')
}

if (route['routeConfig']?.path === 'contact/:contactId/edit') {
segments.push('contact', route.params?.['contactId'], 'edit')
}

router.navigate(segments)
return false
}
return true
})
)
}

export const routes: Routes = [
{
Expand All @@ -11,5 +44,16 @@ export const routes: Routes = [
pageTitle: 'home.title.string',
},
canActivate: [AuthGuard],
children: [
{
path: '',
component: MemberInfoComponent,
data: {
authorities: ['ROLE_USER'],
pageTitle: 'home.title.string',
},
canActivate: [ManageMemberGuard],
},
],
},
]
Loading

0 comments on commit 9f6bfbb

Please sign in to comment.