Browse Source

fix(admin-ui): Fix saving countries in other languages

Closes #528
Michael Bromley 5 years ago
parent
commit
11a1004057

+ 1 - 1
packages/admin-ui/src/lib/core/src/public_api.ts

@@ -174,9 +174,9 @@ export * from './shared/pipes/custom-field-label.pipe';
 export * from './shared/pipes/duration.pipe';
 export * from './shared/pipes/duration.pipe';
 export * from './shared/pipes/file-size.pipe';
 export * from './shared/pipes/file-size.pipe';
 export * from './shared/pipes/has-permission.pipe';
 export * from './shared/pipes/has-permission.pipe';
-export * from './shared/pipes/state-i18n-token.pipe';
 export * from './shared/pipes/sentence-case.pipe';
 export * from './shared/pipes/sentence-case.pipe';
 export * from './shared/pipes/sort.pipe';
 export * from './shared/pipes/sort.pipe';
+export * from './shared/pipes/state-i18n-token.pipe';
 export * from './shared/pipes/string-to-color.pipe';
 export * from './shared/pipes/string-to-color.pipe';
 export * from './shared/pipes/time-ago.pipe';
 export * from './shared/pipes/time-ago.pipe';
 export * from './shared/providers/routing/can-deactivate-detail-guard';
 export * from './shared/providers/routing/can-deactivate-detail-guard';

+ 22 - 12
packages/admin-ui/src/lib/settings/src/components/country-detail/country-detail.component.ts

@@ -2,12 +2,17 @@ import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
 import { FormBuilder, FormGroup, Validators } from '@angular/forms';
 import { ActivatedRoute, Router } from '@angular/router';
 import { ActivatedRoute, Router } from '@angular/router';
 import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
 import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
-import { BaseDetailComponent } from '@vendure/admin-ui/core';
-import { Country, CreateCountryInput, LanguageCode, UpdateCountryInput } from '@vendure/admin-ui/core';
-import { createUpdatedTranslatable } from '@vendure/admin-ui/core';
-import { NotificationService } from '@vendure/admin-ui/core';
-import { DataService } from '@vendure/admin-ui/core';
-import { ServerConfigService } from '@vendure/admin-ui/core';
+import {
+    BaseDetailComponent,
+    Country,
+    CreateCountryInput,
+    createUpdatedTranslatable,
+    DataService,
+    LanguageCode,
+    NotificationService,
+    ServerConfigService,
+    UpdateCountryInput,
+} from '@vendure/admin-ui/core';
 import { combineLatest, Observable } from 'rxjs';
 import { combineLatest, Observable } from 'rxjs';
 import { mergeMap, take } from 'rxjs/operators';
 import { mergeMap, take } from 'rxjs/operators';
 
 
@@ -16,7 +21,8 @@ import { mergeMap, take } from 'rxjs/operators';
     templateUrl: './country-detail.component.html',
     templateUrl: './country-detail.component.html',
     styleUrls: ['./country-detail.component.scss'],
     styleUrls: ['./country-detail.component.scss'],
 })
 })
-export class CountryDetailComponent extends BaseDetailComponent<Country.Fragment>
+export class CountryDetailComponent
+    extends BaseDetailComponent<Country.Fragment>
     implements OnInit, OnDestroy {
     implements OnInit, OnDestroy {
     country$: Observable<Country.Fragment>;
     country$: Observable<Country.Fragment>;
     detailForm: FormGroup;
     detailForm: FormGroup;
@@ -69,7 +75,7 @@ export class CountryDetailComponent extends BaseDetailComponent<Country.Fragment
                 }),
                 }),
             )
             )
             .subscribe(
             .subscribe(
-                (data) => {
+                data => {
                     this.notificationService.success(_('common.notify-create-success'), {
                     this.notificationService.success(_('common.notify-create-success'), {
                         entity: 'Country',
                         entity: 'Country',
                     });
                     });
@@ -77,7 +83,7 @@ export class CountryDetailComponent extends BaseDetailComponent<Country.Fragment
                     this.changeDetector.markForCheck();
                     this.changeDetector.markForCheck();
                     this.router.navigate(['../', data.createCountry.id], { relativeTo: this.route });
                     this.router.navigate(['../', data.createCountry.id], { relativeTo: this.route });
                 },
                 },
-                (err) => {
+                err => {
                     this.notificationService.error(_('common.notify-create-error'), {
                     this.notificationService.error(_('common.notify-create-error'), {
                         entity: 'Country',
                         entity: 'Country',
                     });
                     });
@@ -95,19 +101,23 @@ export class CountryDetailComponent extends BaseDetailComponent<Country.Fragment
                         translatable: country,
                         translatable: country,
                         updatedFields: formValue,
                         updatedFields: formValue,
                         languageCode,
                         languageCode,
+                        defaultTranslation: {
+                            name: formValue.name,
+                            languageCode,
+                        },
                     });
                     });
                     return this.dataService.settings.updateCountry(input);
                     return this.dataService.settings.updateCountry(input);
                 }),
                 }),
             )
             )
             .subscribe(
             .subscribe(
-                (data) => {
+                data => {
                     this.notificationService.success(_('common.notify-update-success'), {
                     this.notificationService.success(_('common.notify-update-success'), {
                         entity: 'Country',
                         entity: 'Country',
                     });
                     });
                     this.detailForm.markAsPristine();
                     this.detailForm.markAsPristine();
                     this.changeDetector.markForCheck();
                     this.changeDetector.markForCheck();
                 },
                 },
-                (err) => {
+                err => {
                     this.notificationService.error(_('common.notify-update-error'), {
                     this.notificationService.error(_('common.notify-update-error'), {
                         entity: 'Country',
                         entity: 'Country',
                     });
                     });
@@ -116,7 +126,7 @@ export class CountryDetailComponent extends BaseDetailComponent<Country.Fragment
     }
     }
 
 
     protected setFormValues(country: Country, languageCode: LanguageCode): void {
     protected setFormValues(country: Country, languageCode: LanguageCode): void {
-        const currentTranslation = country.translations.find((t) => t.languageCode === languageCode);
+        const currentTranslation = country.translations.find(t => t.languageCode === languageCode);
 
 
         this.detailForm.patchValue({
         this.detailForm.patchValue({
             code: country.code,
             code: country.code,