File

feature-libs/organization/administration/components/user/change-password-form/user-change-password-form.component.ts

Metadata

changeDetection ChangeDetectionStrategy.OnPush
host {
}
selector cx-org-user-change-password-form
templateUrl ./user-change-password-form.component.html

Index

Properties
Methods

Constructor

constructor(itemService: UserItemService, formService: UserChangePasswordFormService, messageService: MessageService)
Parameters :
Name Type Optional
itemService UserItemService No
formService UserChangePasswordFormService No
messageService MessageService No

Methods

Protected notify
notify(item: User)
Parameters :
Name Type Optional
item User No
Returns : void
save
save(form: FormGroup)
Parameters :
Name Type Optional
form FormGroup No
Returns : void

Properties

form$
Type : Observable<FormGroup>
Default value : this.itemService.current$.pipe( map((item) => this.formService.getForm(item)) )
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { User } from '@spartacus/core';
import { LoadStatus } from '@spartacus/organization/administration/core';
import { Observable } from 'rxjs';
import { filter, first, map, switchMap, take } from 'rxjs/operators';
import { MessageService } from '../../shared/message/services/message.service';
import { UserItemService } from '../services/user-item.service';
import { UserChangePasswordFormService } from './user-change-password-form.service';

@Component({
  selector: 'cx-org-user-change-password-form',
  templateUrl: './user-change-password-form.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'content-wrapper' },
})
export class UserChangePasswordFormComponent {
  form$: Observable<FormGroup> = this.itemService.current$.pipe(
    map((item) => this.formService.getForm(item))
  );

  constructor(
    protected itemService: UserItemService,
    protected formService: UserChangePasswordFormService,
    protected messageService: MessageService
  ) {}

  save(form: FormGroup): void {
    this.itemService.current$
      .pipe(
        first(),
        switchMap((item) =>
          this.itemService.save(form, (form.value as User).customerId).pipe(
            take(1),
            filter((data) => data.status === LoadStatus.SUCCESS),
            map((data) => ({
              ...item,
              ...data.item,
            }))
          )
        )
      )
      .subscribe((data) => {
        this.notify(data);
        this.itemService.launchDetails(data);
      });
  }

  protected notify(item: User) {
    this.messageService.add({
      message: {
        key: `orgUser.messages.updatePassword`,
        params: {
          item,
        },
      },
    });
  }
}
<form *ngIf="form$ | async as form" [formGroup]="form" (submit)="save(form)">
  <cx-org-card
    [previous]="false"
    i18nRoot="orgUser.password"
    [cxFocus]="{ autofocus: 'input', refreshFocus: form }"
  >
    <button actions class="button primary">
      {{ 'organization.save' | cxTranslate }}
    </button>
    <button actions class="link" routerLink="../" type="button">
      {{ 'organization.cancel' | cxTranslate }}
    </button>

    <section main class="details">
      <label class="full-width">
        <span class="label-content">{{
          'orgUser.password.newPassword' | cxTranslate
        }}</span>
        <input
          aria-required="true"
          class="form-control"
          type="password"
          name="password"
          placeholder="{{ 'orgUser.password.newPassword' | cxTranslate }}"
          formControlName="password"
        />
        <cx-form-errors [control]="form.get('password')"></cx-form-errors>
      </label>
      <label>
        <span class="label-content">{{
          'orgUser.password.confirmPassword' | cxTranslate
        }}</span>
        <input
          aria-required="true"
          class="form-control"
          type="password"
          name="confirmPassword"
          placeholder="{{ 'orgUser.password.confirmPassword' | cxTranslate }}"
          formControlName="confirmPassword"
        />
        <cx-form-errors
          [control]="form.get('confirmPassword')"
        ></cx-form-errors>
      </label>
    </section>
  </cx-org-card>
</form>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""