File

feature-libs/asm/components/asm-main-ui/asm-main-ui.component.ts

Implements

OnInit

Metadata

selector cx-asm-main-ui
templateUrl ./asm-main-ui.component.html

Index

Properties
Methods
HostBindings

Constructor

constructor(authService: AuthService, csAgentAuthService: CsAgentAuthService, userService: UserService, asmComponentService: AsmComponentService, globalMessageService: GlobalMessageService, routingService: RoutingService, asmService: AsmService)
Parameters :
Name Type Optional
authService AuthService No
csAgentAuthService CsAgentAuthService No
userService UserService No
asmComponentService AsmComponentService No
globalMessageService GlobalMessageService No
routingService RoutingService No
asmService AsmService No

HostBindings

class.hidden
Type : boolean
Default value : false

Methods

Protected handleCustomerSessionStartRedirection
handleCustomerSessionStartRedirection()
Returns : void
hideUi
hideUi()
Returns : void
loginCustomerSupportAgent
loginCustomerSupportAgent(undefined: literal type)
Parameters :
Name Type Optional
literal type No
Returns : void
logout
logout()
Returns : void
ngOnInit
ngOnInit()
Returns : void
startCustomerEmulationSession
startCustomerEmulationSession(undefined: literal type)
Parameters :
Name Type Optional
literal type No
Returns : void

Properties

csAgentTokenLoading$
Type : Observable<boolean>
customer$
Type : Observable<User | undefined>
customerSupportAgentLoggedIn$
Type : Observable<boolean>
disabled
Default value : false
Decorators :
@HostBinding('class.hidden')
isCollapsed$
Type : Observable<boolean>
Protected startingCustomerSession
Default value : false
import { Component, HostBinding, OnInit } from '@angular/core';
import { AsmService, AsmUi } from '@spartacus/asm/core';
import { CsAgentAuthService } from '@spartacus/asm/root';
import {
  AuthService,
  GlobalMessageService,
  GlobalMessageType,
  RoutingService,
  User,
  UserService,
} from '@spartacus/core';
import { Observable, of } from 'rxjs';
import { map, switchMap, take } from 'rxjs/operators';
import { AsmComponentService } from '../services/asm-component.service';

@Component({
  selector: 'cx-asm-main-ui',
  templateUrl: './asm-main-ui.component.html',
})
export class AsmMainUiComponent implements OnInit {
  customerSupportAgentLoggedIn$: Observable<boolean>;
  csAgentTokenLoading$: Observable<boolean>;
  customer$: Observable<User | undefined>;
  isCollapsed$: Observable<boolean>;

  @HostBinding('class.hidden') disabled = false;

  protected startingCustomerSession = false;

  constructor(
    protected authService: AuthService,
    protected csAgentAuthService: CsAgentAuthService,
    protected userService: UserService,
    protected asmComponentService: AsmComponentService,
    protected globalMessageService: GlobalMessageService,
    protected routingService: RoutingService,
    protected asmService: AsmService
  ) {}

  ngOnInit(): void {
    this.customerSupportAgentLoggedIn$ =
      this.csAgentAuthService.isCustomerSupportAgentLoggedIn();
    this.csAgentTokenLoading$ =
      this.csAgentAuthService.getCustomerSupportAgentTokenLoading();
    this.customer$ = this.authService.isUserLoggedIn().pipe(
      switchMap((isLoggedIn) => {
        if (isLoggedIn) {
          this.handleCustomerSessionStartRedirection();
          return this.userService.get();
        } else {
          return of(undefined);
        }
      })
    );
    this.isCollapsed$ = this.asmService
      .getAsmUiState()
      .pipe(
        map((uiState: AsmUi) =>
          uiState.collapsed === undefined ? false : uiState.collapsed
        )
      );
  }

  protected handleCustomerSessionStartRedirection(): void {
    this.asmComponentService
      .isCustomerEmulationSessionInProgress()
      .pipe(take(1))
      .subscribe((isCustomerEmulated) => {
        if (this.startingCustomerSession && isCustomerEmulated) {
          this.startingCustomerSession = false;
          this.globalMessageService.remove(GlobalMessageType.MSG_TYPE_ERROR);
          this.routingService.go('/');
        }
      });
  }

  loginCustomerSupportAgent({
    userId,
    password,
  }: {
    userId: string;
    password: string;
  }): void {
    this.csAgentAuthService.authorizeCustomerSupportAgent(userId, password);
  }

  logout(): void {
    this.asmComponentService.logoutCustomerSupportAgentAndCustomer();
  }

  startCustomerEmulationSession({ customerId }: { customerId?: string }): void {
    if (customerId) {
      this.csAgentAuthService.startCustomerEmulationSession(customerId);
      this.startingCustomerSession = true;
    } else {
      this.globalMessageService.add(
        { key: 'asm.error.noCustomerId' },
        GlobalMessageType.MSG_TYPE_ERROR
      );
    }
  }

  hideUi(): void {
    this.disabled = true;
    this.asmComponentService.unload();
  }
}
<div class="asm-bar">
  <div class="asm-bar-branding">
    <img
      class="logo"
      src="data:image/png;base64,i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ut3eK8Lnp254pAOTevnK+G0yI4RFQvtzQ9r6vc0NEyvfL5Mt/g8XIbTVhsig+gAAAABJRU5ErkJggg=="
      width="48"
      height="24"
      alt="{{ 'asm.mainLogoLabel' | cxTranslate }}"
    />

    <div class="asm-title">
      {{ 'asm.mainTitle' | cxTranslate }}
    </div>
  </div>
  <div class="asm-bar-actions">
    <cx-asm-toggle-ui></cx-asm-toggle-ui>

    <cx-asm-session-timer
      *ngIf="customerSupportAgentLoggedIn$ | async"
    ></cx-asm-session-timer>

    <button
      class="close"
      title="{{ 'asm.hideUi' | cxTranslate }}"
      *ngIf="
        !(customerSupportAgentLoggedIn$ | async) &&
        !(csAgentTokenLoading$ | async)
      "
      (click)="hideUi()"
    ></button>

    <button
      class="logout"
      title="{{ 'asm.logout' | cxTranslate }}"
      *ngIf="customerSupportAgentLoggedIn$ | async"
      (click)="logout()"
    ></button>
  </div>
</div>

<ng-container *ngIf="!(isCollapsed$ | async) as notCollapsed">
  <ng-container
    *ngIf="customerSupportAgentLoggedIn$ | async; else showLoginForm"
  >
    <ng-container *ngIf="customer$ | async; else showCustomerSelection">
      <cx-customer-emulation *ngIf="notCollapsed"></cx-customer-emulation>
    </ng-container>
    <ng-template #showCustomerSelection>
      <cx-customer-selection
        *ngIf="notCollapsed"
        (submitEvent)="startCustomerEmulationSession($event)"
      ></cx-customer-selection>
    </ng-template>
  </ng-container>

  <ng-template #showLoginForm>
    <cx-csagent-login-form
      *ngIf="notCollapsed"
      (submitEvent)="loginCustomerSupportAgent($event)"
      [csAgentTokenLoading]="csAgentTokenLoading$ | async"
    ></cx-csagent-login-form>
  </ng-template>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""