-
Notifications
You must be signed in to change notification settings - Fork 395
/
Copy pathpunchout-close-session.component.ts
39 lines (35 loc) · 1.23 KB
/
punchout-close-session.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { AuthService } from '@spartacus/core';
import { PunchoutFacade, PunchoutStoreService } from '@spartacus/punchout/root';
import { map, Observable, of, switchMap } from 'rxjs';
@Component({
selector: 'cx-punchout-close-session',
templateUrl: './punchout-close-session.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class PunchoutCloseSessionComponent {
protected punchoutStoreService = inject(PunchoutStoreService);
protected authService = inject(AuthService);
protected punchoutFacade = inject(PunchoutFacade);
isPunchoutSessionactive$: Observable<boolean> = this.authService
.isUserLoggedIn()
.pipe(
switchMap((isLoggedIn) => {
return isLoggedIn
? this.punchoutStoreService.getPunchoutState()
: of({ punchoutSessionId: undefined });
}),
map((punchoutState) => {
return !!punchoutState.punchoutSessionId;
})
);
clickCloseSessionButton(): void {
this.punchoutFacade.closePunchoutSession().subscribe();
}
}