Просмотр исходного кода

fix(admin-ui): Fix display of Address custom fields in customer detail view

Fixes #2272
Michael Bromley 2 лет назад
Родитель
Сommit
189e714a8b

+ 7 - 19
packages/admin-ui/src/lib/customer/src/components/customer-detail/customer-detail.component.ts

@@ -189,13 +189,6 @@ export class CustomerDetailComponent
                 this.addressCustomFields.reduce((hash, field) => ({ ...hash, [field.name]: '' }), {}),
             ),
         });
-        // if (this.addressCustomFields.length) {
-        //     const customFieldsGroup = this.formBuilder.group({});
-        //     for (const fieldDef of this.addressCustomFields) {
-        //         customFieldsGroup.addControl(fieldDef.name, new UntypedFormControl(''));
-        //     }
-        //     newAddress.addControl('customFields', customFieldsGroup);
-        // }
         addressFormArray.push(newAddress);
     }
 
@@ -495,7 +488,13 @@ export class CustomerDetailComponent
                     ...rest,
                     countryCode: address.country.code,
                     customFields: this.formBuilder.group(
-                        this.addressCustomFields.reduce((hash, field) => ({ ...hash, [field.name]: '' }), {}),
+                        this.addressCustomFields.reduce(
+                            (hash, field) => ({
+                                ...hash,
+                                [field.name]: address['customFields'][field.name],
+                            }),
+                            {},
+                        ),
                     ),
                 });
                 addressesArray.push(addressGroup);
@@ -505,17 +504,6 @@ export class CustomerDetailComponent
                 if (address.defaultBillingAddress) {
                     this.defaultBillingAddressId = address.id;
                 }
-
-                if (this.addressCustomFields.length) {
-                    const customFieldsGroup = this.formBuilder.group({});
-                    for (const fieldDef of this.addressCustomFields) {
-                        const key = fieldDef.name;
-                        const value = (address as any).customFields?.[key];
-                        const control = new UntypedFormControl(value);
-                        customFieldsGroup.addControl(key, control);
-                    }
-                    addressGroup.addControl('customFields', customFieldsGroup);
-                }
             }
             this.detailForm.setControl('addresses', addressesArray);
         }