|
@@ -1,6 +1,16 @@
|
|
|
-import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ ChangeDetectionStrategy,
|
|
|
|
|
+ ChangeDetectorRef,
|
|
|
|
|
+ Component,
|
|
|
|
|
+ EventEmitter,
|
|
|
|
|
+ Input,
|
|
|
|
|
+ OnInit,
|
|
|
|
|
+ Output,
|
|
|
|
|
+} from '@angular/core';
|
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
|
-import { CustomFieldConfig, GetAvailableCountries } from '@vendure/admin-ui/core';
|
|
|
|
|
|
|
+import { CustomFieldConfig, GetAvailableCountries, ModalService } from '@vendure/admin-ui/core';
|
|
|
|
|
+
|
|
|
|
|
+import { AddressDetailDialogComponent } from '../address-detail-dialog/address-detail-dialog.component';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'vdr-address-card',
|
|
selector: 'vdr-address-card',
|
|
@@ -9,7 +19,6 @@ import { CustomFieldConfig, GetAvailableCountries } from '@vendure/admin-ui/core
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
})
|
|
})
|
|
|
export class AddressCardComponent implements OnInit {
|
|
export class AddressCardComponent implements OnInit {
|
|
|
- editing = false;
|
|
|
|
|
@Input() addressForm: FormGroup;
|
|
@Input() addressForm: FormGroup;
|
|
|
@Input() customFields: CustomFieldConfig;
|
|
@Input() customFields: CustomFieldConfig;
|
|
|
@Input() availableCountries: GetAvailableCountries.Items[] = [];
|
|
@Input() availableCountries: GetAvailableCountries.Items[] = [];
|
|
@@ -18,10 +27,12 @@ export class AddressCardComponent implements OnInit {
|
|
|
@Output() setAsDefaultShipping = new EventEmitter<string>();
|
|
@Output() setAsDefaultShipping = new EventEmitter<string>();
|
|
|
@Output() setAsDefaultBilling = new EventEmitter<string>();
|
|
@Output() setAsDefaultBilling = new EventEmitter<string>();
|
|
|
|
|
|
|
|
|
|
+ constructor(private modalService: ModalService, private changeDetector: ChangeDetectorRef) {}
|
|
|
|
|
+
|
|
|
ngOnInit(): void {
|
|
ngOnInit(): void {
|
|
|
const streetLine1 = this.addressForm.get('streetLine1') as FormControl;
|
|
const streetLine1 = this.addressForm.get('streetLine1') as FormControl;
|
|
|
if (!streetLine1.value) {
|
|
if (!streetLine1.value) {
|
|
|
- this.editing = true;
|
|
|
|
|
|
|
+ this.editAddress();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -42,4 +53,20 @@ export class AddressCardComponent implements OnInit {
|
|
|
this.setAsDefaultShipping.emit(this.addressForm.value.id);
|
|
this.setAsDefaultShipping.emit(this.addressForm.value.id);
|
|
|
this.addressForm.markAsDirty();
|
|
this.addressForm.markAsDirty();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ editAddress() {
|
|
|
|
|
+ this.modalService
|
|
|
|
|
+ .fromComponent(AddressDetailDialogComponent, {
|
|
|
|
|
+ locals: {
|
|
|
|
|
+ addressForm: this.addressForm,
|
|
|
|
|
+ customFields: this.customFields,
|
|
|
|
|
+ availableCountries: this.availableCountries,
|
|
|
|
|
+ },
|
|
|
|
|
+ size: 'md',
|
|
|
|
|
+ closable: true,
|
|
|
|
|
+ })
|
|
|
|
|
+ .subscribe(() => {
|
|
|
|
|
+ this.changeDetector.markForCheck();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|