Unverified Commit ee738762 authored by Ruslan Konviser's avatar Ruslan Konviser Committed by GitHub
Browse files

Merge pull request #1146 from ever-co/fix/#1134-Admin-edit-customers

fix:#1134 connect the selected customer to the edit page
parents 534fdb5d 567d2135
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
<toaster-container></toaster-container>

<div>
	<nb-card *ngIf="customer$ | async as customer">
	<nb-card *ngIf="_currentCustomer">
		<nb-card-header>
			<div class="d-inline-flex">
				<svg
					viewBox="0 0 24 24"
					class="control-icon control-icon-left"
					[routerLink]="['/customers/list/' + customer.id]"
					[routerLink]="['/customers/list/' + _currentCustomer.id]"
				>
					<path
						d="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"
+7 −24
Original line number Diff line number Diff line
import { Component, ViewChild, EventEmitter, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import {
	first,
	map,
	switchMap,
	withLatestFrom,
	catchError,
} from 'rxjs/operators';
import { first } from 'rxjs/operators';
import { ToasterService } from 'angular2-toaster';
import { BasicInfoFormComponent } from '../../../../@shared/user/forms';
import { LocationFormComponent } from '../../../../@shared/forms/location';
import { UserRouter } from '@modules/client.common.angular2/routers/user-router.service';
import IGeoLocation from '@modules/server.common/interfaces/IGeoLocation';
import User from '@modules/server.common/entities/User';
import { empty } from 'rxjs';

@Component({
	templateUrl: './customer-edit.component.html',
@@ -41,19 +34,6 @@ export class CustomerEditComponent implements OnInit {
	readonly basicInfo = this.form.get('basicInfo') as FormControl;
	readonly location = this.form.get('location') as FormControl;

	readonly customerId$ = this._activatedRoute.params.pipe(
		map((p) => p['id'])
	);

	readonly customer$ = this.customerId$.pipe(
		catchError((err) => {
			return empty();
		}),
		switchMap((id) => {
			return this._customerRouter.get(id).pipe(first());
		})
	);

	private _currentCustomer: User;

	constructor(
@@ -65,9 +45,12 @@ export class CustomerEditComponent implements OnInit {
	) {}

	ngOnInit() {
		this.customer$
			.pipe(withLatestFrom(this.customerId$))
			.subscribe(([customer, id]) => {
		const id = this._activatedRoute.snapshot.params.id;

		this._customerRouter
			.get(id)
			.pipe(first())
			.subscribe((customer) => {
				if (!customer) {
					this._toasterService.pop(
						'error',