diff --git a/packages/admin-ui/src/lib/core/src/common/generated-types.ts b/packages/admin-ui/src/lib/core/src/common/generated-types.ts index 1d950d4304..24656e7bb9 100644 --- a/packages/admin-ui/src/lib/core/src/common/generated-types.ts +++ b/packages/admin-ui/src/lib/core/src/common/generated-types.ts @@ -5687,6 +5687,11 @@ export type CustomerFragment = ( )>> } ); +export type CustomerGroupFragment = ( + { __typename?: 'CustomerGroup' } + & Pick +); + export type GetCustomerListQueryVariables = Exact<{ options?: Maybe; }>; @@ -5792,7 +5797,7 @@ export type CreateCustomerGroupMutationVariables = Exact<{ export type CreateCustomerGroupMutation = { createCustomerGroup: ( { __typename?: 'CustomerGroup' } - & Pick + & CustomerGroupFragment ) }; export type UpdateCustomerGroupMutationVariables = Exact<{ @@ -5802,7 +5807,7 @@ export type UpdateCustomerGroupMutationVariables = Exact<{ export type UpdateCustomerGroupMutation = { updateCustomerGroup: ( { __typename?: 'CustomerGroup' } - & Pick + & CustomerGroupFragment ) }; export type DeleteCustomerGroupMutationVariables = Exact<{ @@ -5825,7 +5830,7 @@ export type GetCustomerGroupsQuery = { customerGroups: ( & Pick & { items: Array<( { __typename?: 'CustomerGroup' } - & Pick + & CustomerGroupFragment )> } ) }; @@ -5837,7 +5842,6 @@ export type GetCustomerGroupWithCustomersQueryVariables = Exact<{ export type GetCustomerGroupWithCustomersQuery = { customerGroup?: Maybe<( { __typename?: 'CustomerGroup' } - & Pick & { customers: ( { __typename?: 'CustomerList' } & Pick @@ -5846,6 +5850,7 @@ export type GetCustomerGroupWithCustomersQuery = { customerGroup?: Maybe<( & Pick )> } ) } + & CustomerGroupFragment )> }; export type AddCustomersToGroupMutationVariables = Exact<{ @@ -5856,7 +5861,7 @@ export type AddCustomersToGroupMutationVariables = Exact<{ export type AddCustomersToGroupMutation = { addCustomersToGroup: ( { __typename?: 'CustomerGroup' } - & Pick + & CustomerGroupFragment ) }; export type RemoveCustomersFromGroupMutationVariables = Exact<{ @@ -5867,7 +5872,7 @@ export type RemoveCustomersFromGroupMutationVariables = Exact<{ export type RemoveCustomersFromGroupMutation = { removeCustomersFromGroup: ( { __typename?: 'CustomerGroup' } - & Pick + & CustomerGroupFragment ) }; export type GetCustomerHistoryQueryVariables = Exact<{ @@ -7329,7 +7334,7 @@ export type DeleteCountryMutation = { deleteCountry: ( export type ZoneFragment = ( { __typename?: 'Zone' } - & Pick + & Pick & { members: Array<( { __typename?: 'Country' } & CountryFragment @@ -7341,11 +7346,11 @@ export type GetZonesQueryVariables = Exact<{ [key: string]: never; }>; export type GetZonesQuery = { zones: Array<( { __typename?: 'Zone' } - & Pick & { members: Array<( { __typename?: 'Country' } & Pick )> } + & ZoneFragment )> }; export type GetZoneQueryVariables = Exact<{ @@ -8051,6 +8056,30 @@ export type GetServerConfigQuery = { globalSettings: ( ) | ( { __typename?: 'TextCustomFieldConfig' } & CustomFields_TextCustomFieldConfig_Fragment + )>, Country: Array<( + { __typename?: 'StringCustomFieldConfig' } + & CustomFields_StringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'LocaleStringCustomFieldConfig' } + & CustomFields_LocaleStringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'IntCustomFieldConfig' } + & CustomFields_IntCustomFieldConfig_Fragment + ) | ( + { __typename?: 'FloatCustomFieldConfig' } + & CustomFields_FloatCustomFieldConfig_Fragment + ) | ( + { __typename?: 'BooleanCustomFieldConfig' } + & CustomFields_BooleanCustomFieldConfig_Fragment + ) | ( + { __typename?: 'DateTimeCustomFieldConfig' } + & CustomFields_DateTimeCustomFieldConfig_Fragment + ) | ( + { __typename?: 'RelationCustomFieldConfig' } + & CustomFields_RelationCustomFieldConfig_Fragment + ) | ( + { __typename?: 'TextCustomFieldConfig' } + & CustomFields_TextCustomFieldConfig_Fragment )>, Customer: Array<( { __typename?: 'StringCustomFieldConfig' } & CustomFields_StringCustomFieldConfig_Fragment @@ -8075,6 +8104,30 @@ export type GetServerConfigQuery = { globalSettings: ( ) | ( { __typename?: 'TextCustomFieldConfig' } & CustomFields_TextCustomFieldConfig_Fragment + )>, CustomerGroup: Array<( + { __typename?: 'StringCustomFieldConfig' } + & CustomFields_StringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'LocaleStringCustomFieldConfig' } + & CustomFields_LocaleStringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'IntCustomFieldConfig' } + & CustomFields_IntCustomFieldConfig_Fragment + ) | ( + { __typename?: 'FloatCustomFieldConfig' } + & CustomFields_FloatCustomFieldConfig_Fragment + ) | ( + { __typename?: 'BooleanCustomFieldConfig' } + & CustomFields_BooleanCustomFieldConfig_Fragment + ) | ( + { __typename?: 'DateTimeCustomFieldConfig' } + & CustomFields_DateTimeCustomFieldConfig_Fragment + ) | ( + { __typename?: 'RelationCustomFieldConfig' } + & CustomFields_RelationCustomFieldConfig_Fragment + ) | ( + { __typename?: 'TextCustomFieldConfig' } + & CustomFields_TextCustomFieldConfig_Fragment )>, Facet: Array<( { __typename?: 'StringCustomFieldConfig' } & CustomFields_StringCustomFieldConfig_Fragment @@ -8219,6 +8272,30 @@ export type GetServerConfigQuery = { globalSettings: ( ) | ( { __typename?: 'TextCustomFieldConfig' } & CustomFields_TextCustomFieldConfig_Fragment + )>, PaymentMethod: Array<( + { __typename?: 'StringCustomFieldConfig' } + & CustomFields_StringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'LocaleStringCustomFieldConfig' } + & CustomFields_LocaleStringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'IntCustomFieldConfig' } + & CustomFields_IntCustomFieldConfig_Fragment + ) | ( + { __typename?: 'FloatCustomFieldConfig' } + & CustomFields_FloatCustomFieldConfig_Fragment + ) | ( + { __typename?: 'BooleanCustomFieldConfig' } + & CustomFields_BooleanCustomFieldConfig_Fragment + ) | ( + { __typename?: 'DateTimeCustomFieldConfig' } + & CustomFields_DateTimeCustomFieldConfig_Fragment + ) | ( + { __typename?: 'RelationCustomFieldConfig' } + & CustomFields_RelationCustomFieldConfig_Fragment + ) | ( + { __typename?: 'TextCustomFieldConfig' } + & CustomFields_TextCustomFieldConfig_Fragment )>, Product: Array<( { __typename?: 'StringCustomFieldConfig' } & CustomFields_StringCustomFieldConfig_Fragment @@ -8315,6 +8392,30 @@ export type GetServerConfigQuery = { globalSettings: ( ) | ( { __typename?: 'TextCustomFieldConfig' } & CustomFields_TextCustomFieldConfig_Fragment + )>, Promotion: Array<( + { __typename?: 'StringCustomFieldConfig' } + & CustomFields_StringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'LocaleStringCustomFieldConfig' } + & CustomFields_LocaleStringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'IntCustomFieldConfig' } + & CustomFields_IntCustomFieldConfig_Fragment + ) | ( + { __typename?: 'FloatCustomFieldConfig' } + & CustomFields_FloatCustomFieldConfig_Fragment + ) | ( + { __typename?: 'BooleanCustomFieldConfig' } + & CustomFields_BooleanCustomFieldConfig_Fragment + ) | ( + { __typename?: 'DateTimeCustomFieldConfig' } + & CustomFields_DateTimeCustomFieldConfig_Fragment + ) | ( + { __typename?: 'RelationCustomFieldConfig' } + & CustomFields_RelationCustomFieldConfig_Fragment + ) | ( + { __typename?: 'TextCustomFieldConfig' } + & CustomFields_TextCustomFieldConfig_Fragment )>, ShippingMethod: Array<( { __typename?: 'StringCustomFieldConfig' } & CustomFields_StringCustomFieldConfig_Fragment @@ -8339,6 +8440,54 @@ export type GetServerConfigQuery = { globalSettings: ( ) | ( { __typename?: 'TextCustomFieldConfig' } & CustomFields_TextCustomFieldConfig_Fragment + )>, TaxCategory: Array<( + { __typename?: 'StringCustomFieldConfig' } + & CustomFields_StringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'LocaleStringCustomFieldConfig' } + & CustomFields_LocaleStringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'IntCustomFieldConfig' } + & CustomFields_IntCustomFieldConfig_Fragment + ) | ( + { __typename?: 'FloatCustomFieldConfig' } + & CustomFields_FloatCustomFieldConfig_Fragment + ) | ( + { __typename?: 'BooleanCustomFieldConfig' } + & CustomFields_BooleanCustomFieldConfig_Fragment + ) | ( + { __typename?: 'DateTimeCustomFieldConfig' } + & CustomFields_DateTimeCustomFieldConfig_Fragment + ) | ( + { __typename?: 'RelationCustomFieldConfig' } + & CustomFields_RelationCustomFieldConfig_Fragment + ) | ( + { __typename?: 'TextCustomFieldConfig' } + & CustomFields_TextCustomFieldConfig_Fragment + )>, TaxRate: Array<( + { __typename?: 'StringCustomFieldConfig' } + & CustomFields_StringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'LocaleStringCustomFieldConfig' } + & CustomFields_LocaleStringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'IntCustomFieldConfig' } + & CustomFields_IntCustomFieldConfig_Fragment + ) | ( + { __typename?: 'FloatCustomFieldConfig' } + & CustomFields_FloatCustomFieldConfig_Fragment + ) | ( + { __typename?: 'BooleanCustomFieldConfig' } + & CustomFields_BooleanCustomFieldConfig_Fragment + ) | ( + { __typename?: 'DateTimeCustomFieldConfig' } + & CustomFields_DateTimeCustomFieldConfig_Fragment + ) | ( + { __typename?: 'RelationCustomFieldConfig' } + & CustomFields_RelationCustomFieldConfig_Fragment + ) | ( + { __typename?: 'TextCustomFieldConfig' } + & CustomFields_TextCustomFieldConfig_Fragment )>, User: Array<( { __typename?: 'StringCustomFieldConfig' } & CustomFields_StringCustomFieldConfig_Fragment @@ -8363,6 +8512,30 @@ export type GetServerConfigQuery = { globalSettings: ( ) | ( { __typename?: 'TextCustomFieldConfig' } & CustomFields_TextCustomFieldConfig_Fragment + )>, Zone: Array<( + { __typename?: 'StringCustomFieldConfig' } + & CustomFields_StringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'LocaleStringCustomFieldConfig' } + & CustomFields_LocaleStringCustomFieldConfig_Fragment + ) | ( + { __typename?: 'IntCustomFieldConfig' } + & CustomFields_IntCustomFieldConfig_Fragment + ) | ( + { __typename?: 'FloatCustomFieldConfig' } + & CustomFields_FloatCustomFieldConfig_Fragment + ) | ( + { __typename?: 'BooleanCustomFieldConfig' } + & CustomFields_BooleanCustomFieldConfig_Fragment + ) | ( + { __typename?: 'DateTimeCustomFieldConfig' } + & CustomFields_DateTimeCustomFieldConfig_Fragment + ) | ( + { __typename?: 'RelationCustomFieldConfig' } + & CustomFields_RelationCustomFieldConfig_Fragment + ) | ( + { __typename?: 'TextCustomFieldConfig' } + & CustomFields_TextCustomFieldConfig_Fragment )> } ) } ) } @@ -9008,6 +9181,10 @@ export namespace Customer { export type Addresses = NonNullable<(NonNullable)[number]>; } +export namespace CustomerGroup { + export type Fragment = CustomerGroupFragment; +} + export namespace GetCustomerList { export type Variables = GetCustomerListQueryVariables; export type Query = GetCustomerListQuery; @@ -10074,19 +10251,26 @@ export namespace GetServerConfig { export type Asset = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Asset']>)[number]>; export type Channel = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Channel']>)[number]>; export type Collection = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Collection']>)[number]>; + export type Country = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Country']>)[number]>; export type Customer = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Customer']>)[number]>; + export type CustomerGroup = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['CustomerGroup']>)[number]>; export type Facet = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Facet']>)[number]>; export type FacetValue = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['FacetValue']>)[number]>; export type Fulfillment = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Fulfillment']>)[number]>; export type _GlobalSettings = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['GlobalSettings']>)[number]>; export type Order = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Order']>)[number]>; export type OrderLine = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['OrderLine']>)[number]>; + export type PaymentMethod = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['PaymentMethod']>)[number]>; export type Product = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Product']>)[number]>; export type ProductOption = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['ProductOption']>)[number]>; export type ProductOptionGroup = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['ProductOptionGroup']>)[number]>; export type ProductVariant = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['ProductVariant']>)[number]>; + export type Promotion = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Promotion']>)[number]>; export type ShippingMethod = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['ShippingMethod']>)[number]>; + export type TaxCategory = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['TaxCategory']>)[number]>; + export type TaxRate = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['TaxRate']>)[number]>; export type User = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['User']>)[number]>; + export type Zone = NonNullable<(NonNullable<(NonNullable<(NonNullable<(NonNullable)['serverConfig']>)['customFieldConfig']>)['Zone']>)[number]>; } export namespace JobInfo { diff --git a/packages/admin-ui/src/lib/core/src/data/definitions/customer-definitions.ts b/packages/admin-ui/src/lib/core/src/data/definitions/customer-definitions.ts index 07bb3d9597..973169a649 100644 --- a/packages/admin-ui/src/lib/core/src/data/definitions/customer-definitions.ts +++ b/packages/admin-ui/src/lib/core/src/data/definitions/customer-definitions.ts @@ -48,6 +48,15 @@ export const CUSTOMER_FRAGMENT = gql` ${ADDRESS_FRAGMENT} `; +export const CUSTOMER_GROUP_FRAGMENT = gql` + fragment CustomerGroup on CustomerGroup { + id + createdAt + updatedAt + name + } +`; + export const GET_CUSTOMER_LIST = gql` query GetCustomerList($options: CustomerListOptions) { customers(options: $options) { @@ -145,23 +154,19 @@ export const UPDATE_CUSTOMER_ADDRESS = gql` export const CREATE_CUSTOMER_GROUP = gql` mutation CreateCustomerGroup($input: CreateCustomerGroupInput!) { createCustomerGroup(input: $input) { - id - createdAt - updatedAt - name + ...CustomerGroup } } + ${CUSTOMER_GROUP_FRAGMENT} `; export const UPDATE_CUSTOMER_GROUP = gql` mutation UpdateCustomerGroup($input: UpdateCustomerGroupInput!) { updateCustomerGroup(input: $input) { - id - createdAt - updatedAt - name + ...CustomerGroup } } + ${CUSTOMER_GROUP_FRAGMENT} `; export const DELETE_CUSTOMER_GROUP = gql` @@ -177,23 +182,18 @@ export const GET_CUSTOMER_GROUPS = gql` query GetCustomerGroups($options: CustomerGroupListOptions) { customerGroups(options: $options) { items { - id - createdAt - updatedAt - name + ...CustomerGroup } totalItems } } + ${CUSTOMER_GROUP_FRAGMENT} `; export const GET_CUSTOMER_GROUP_WITH_CUSTOMERS = gql` query GetCustomerGroupWithCustomers($id: ID!, $options: CustomerListOptions) { customerGroup(id: $id) { - id - createdAt - updatedAt - name + ...CustomerGroup customers(options: $options) { items { id @@ -207,28 +207,25 @@ export const GET_CUSTOMER_GROUP_WITH_CUSTOMERS = gql` } } } + ${CUSTOMER_GROUP_FRAGMENT} `; export const ADD_CUSTOMERS_TO_GROUP = gql` mutation AddCustomersToGroup($groupId: ID!, $customerIds: [ID!]!) { addCustomersToGroup(customerGroupId: $groupId, customerIds: $customerIds) { - id - createdAt - updatedAt - name + ...CustomerGroup } } + ${CUSTOMER_GROUP_FRAGMENT} `; export const REMOVE_CUSTOMERS_FROM_GROUP = gql` mutation RemoveCustomersFromGroup($groupId: ID!, $customerIds: [ID!]!) { removeCustomersFromGroup(customerGroupId: $groupId, customerIds: $customerIds) { - id - createdAt - updatedAt - name + ...CustomerGroup } } + ${CUSTOMER_GROUP_FRAGMENT} `; export const GET_CUSTOMER_HISTORY = gql` diff --git a/packages/admin-ui/src/lib/core/src/data/definitions/settings-definitions.ts b/packages/admin-ui/src/lib/core/src/data/definitions/settings-definitions.ts index a2abfdf8e8..8aed43627a 100644 --- a/packages/admin-ui/src/lib/core/src/data/definitions/settings-definitions.ts +++ b/packages/admin-ui/src/lib/core/src/data/definitions/settings-definitions.ts @@ -88,6 +88,8 @@ export const DELETE_COUNTRY = gql` export const ZONE_FRAGMENT = gql` fragment Zone on Zone { id + createdAt + updatedAt name members { ...Country @@ -99,10 +101,7 @@ export const ZONE_FRAGMENT = gql` export const GET_ZONES = gql` query GetZones { zones { - id - createdAt - updatedAt - name + ...Zone members { createdAt updatedAt @@ -113,6 +112,7 @@ export const GET_ZONES = gql` } } } + ${ZONE_FRAGMENT} `; export const GET_ZONE = gql` @@ -647,9 +647,15 @@ export const GET_SERVER_CONFIG = gql` Collection { ...CustomFields } + Country { + ...CustomFields + } Customer { ...CustomFields } + CustomerGroup { + ...CustomFields + } Facet { ...CustomFields } @@ -668,6 +674,9 @@ export const GET_SERVER_CONFIG = gql` OrderLine { ...CustomFields } + PaymentMethod { + ...CustomFields + } Product { ...CustomFields } @@ -680,12 +689,24 @@ export const GET_SERVER_CONFIG = gql` ProductVariant { ...CustomFields } + Promotion { + ...CustomFields + } ShippingMethod { ...CustomFields } + TaxCategory { + ...CustomFields + } + TaxRate { + ...CustomFields + } User { ...CustomFields } + Zone { + ...CustomFields + } } } } diff --git a/packages/admin-ui/src/lib/core/src/data/providers/settings-data.service.ts b/packages/admin-ui/src/lib/core/src/data/providers/settings-data.service.ts index 8f386a6bca..7313a6a9cb 100644 --- a/packages/admin-ui/src/lib/core/src/data/providers/settings-data.service.ts +++ b/packages/admin-ui/src/lib/core/src/data/providers/settings-data.service.ts @@ -131,13 +131,13 @@ export class SettingsDataService { createCountry(input: CreateCountryInput) { return this.baseDataService.mutate(CREATE_COUNTRY, { - input: pick(input, ['code', 'enabled', 'translations']), + input: pick(input, ['code', 'enabled', 'translations', 'customFields']), }); } updateCountry(input: UpdateCountryInput) { return this.baseDataService.mutate(UPDATE_COUNTRY, { - input: pick(input, ['id', 'code', 'enabled', 'translations']), + input: pick(input, ['id', 'code', 'enabled', 'translations', 'customFields']), }); } diff --git a/packages/admin-ui/src/lib/customer/src/components/customer-group-detail-dialog/customer-group-detail-dialog.component.html b/packages/admin-ui/src/lib/customer/src/components/customer-group-detail-dialog/customer-group-detail-dialog.component.html index 1d95492325..87c26b5d7a 100644 --- a/packages/admin-ui/src/lib/customer/src/components/customer-group-detail-dialog/customer-group-detail-dialog.component.html +++ b/packages/admin-ui/src/lib/customer/src/components/customer-group-detail-dialog/customer-group-detail-dialog.component.html @@ -2,11 +2,27 @@ {{ 'customer.update-customer-group' | translate }} {{ 'customer.create-customer-group' | translate }} - - - - - +
+ + + +
+ + + + +
+
diff --git a/packages/admin-ui/src/lib/settings/src/components/zone-detail-dialog/zone-detail-dialog.component.ts b/packages/admin-ui/src/lib/settings/src/components/zone-detail-dialog/zone-detail-dialog.component.ts index 6f3ae6ba36..82e4249c99 100644 --- a/packages/admin-ui/src/lib/settings/src/components/zone-detail-dialog/zone-detail-dialog.component.ts +++ b/packages/admin-ui/src/lib/settings/src/components/zone-detail-dialog/zone-detail-dialog.component.ts @@ -1,5 +1,6 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { Dialog } from '@vendure/admin-ui/core'; +import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { CreateZoneInput, CustomFieldConfig, Dialog, ServerConfigService } from '@vendure/admin-ui/core'; @Component({ selector: 'vdr-zone-detail-dialog', @@ -7,15 +8,43 @@ import { Dialog } from '@vendure/admin-ui/core'; styleUrls: ['./zone-detail-dialog.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class ZoneDetailDialogComponent implements Dialog { - zone: { id?: string; name: string }; - resolveWith: (result?: string) => void; +export class ZoneDetailDialogComponent implements Dialog, OnInit { + zone: { id?: string; name: string; customFields?: { [name: string]: any } }; + resolveWith: (result?: CreateZoneInput) => void; + + customFields: CustomFieldConfig[]; + form: FormGroup; + + constructor(private serverConfigService: ServerConfigService, private formBuilder: FormBuilder) { + this.customFields = this.serverConfigService.getCustomFieldsFor('CustomerGroup'); + } + + ngOnInit() { + this.form = this.formBuilder.group({ + name: [this.zone.name, Validators.required], + customFields: this.formBuilder.group( + this.customFields.reduce((hash, field) => ({ ...hash, [field.name]: '' }), {}), + ), + }); + if (this.customFields.length) { + const customFieldsGroup = this.form.get('customFields') as FormGroup; + + for (const fieldDef of this.customFields) { + const key = fieldDef.name; + const value = this.zone.customFields?.[key]; + const control = customFieldsGroup.get(key); + if (control) { + control.patchValue(value); + } + } + } + } cancel() { this.resolveWith(); } save() { - this.resolveWith(this.zone.name); + this.resolveWith(this.form.value); } } diff --git a/packages/admin-ui/src/lib/settings/src/components/zone-list/zone-list.component.ts b/packages/admin-ui/src/lib/settings/src/components/zone-list/zone-list.component.ts index d80d99051b..86c04260fc 100644 --- a/packages/admin-ui/src/lib/settings/src/components/zone-list/zone-list.component.ts +++ b/packages/admin-ui/src/lib/settings/src/components/zone-list/zone-list.component.ts @@ -55,8 +55,8 @@ export class ZoneListComponent implements OnInit { this.modalService .fromComponent(ZoneDetailDialogComponent, { locals: { zone: { name: '' } } }) .pipe( - switchMap(name => - name ? this.dataService.settings.createZone({ name, memberIds: [] }) : EMPTY, + switchMap(result => + result ? this.dataService.settings.createZone({ ...result, memberIds: [] }) : EMPTY, ), // refresh list switchMap(() => this.dataService.settings.getZones().single$), @@ -120,8 +120,8 @@ export class ZoneListComponent implements OnInit { this.modalService .fromComponent(ZoneDetailDialogComponent, { locals: { zone } }) .pipe( - switchMap(name => - name ? this.dataService.settings.updateZone({ id: zone.id, name }) : EMPTY, + switchMap(result => + result ? this.dataService.settings.updateZone({ id: zone.id, ...result }) : EMPTY, ), ) .subscribe( diff --git a/packages/dev-server/dev-config.ts b/packages/dev-server/dev-config.ts index 0cca184ecd..6eb3c67357 100644 --- a/packages/dev-server/dev-config.ts +++ b/packages/dev-server/dev-config.ts @@ -56,13 +56,16 @@ export const devConfig: VendureConfig = { paymentMethodHandlers: [dummyPaymentHandler], }, customFields: { - Country: [{ name: 'foo', type: 'localeString' }], - CustomerGroup: [{ name: 'foo', type: 'string' }], - PaymentMethod: [{ name: 'foo', type: 'string' }], - Promotion: [{ name: 'foo', type: 'string' }], - TaxCategory: [{ name: 'foo', type: 'string' }], - TaxRate: [{ name: 'foo', type: 'string' }], - Zone: [{ name: 'foo', type: 'string' }], + // Country: [ + // { name: 'foo', type: 'localeString' }, + // { name: 'rating', type: 'int' }, + // ], + // CustomerGroup: [{ name: 'foo', type: 'string' }], + // PaymentMethod: [{ name: 'foo', type: 'string' }], + // Promotion: [{ name: 'foo', type: 'string' }], + // TaxCategory: [{ name: 'foo', type: 'string' }], + // TaxRate: [{ name: 'foo', type: 'string' }], + // Zone: [{ name: 'foo', type: 'string' }], }, logger: new DefaultLogger({ level: LogLevel.Debug }), importExportOptions: {