diff --git a/packages/core/graphql/src/lib/documents/fragments/order.gql b/packages/core/graphql/src/lib/documents/fragments/order.gql index af83f5d..a75eabe 100644 --- a/packages/core/graphql/src/lib/documents/fragments/order.gql +++ b/packages/core/graphql/src/lib/documents/fragments/order.gql @@ -53,6 +53,7 @@ fragment OrderFragment on IoRestorecommerceOrderOrder { field1 field2 } + countryId country { id name @@ -87,6 +88,7 @@ fragment OrderFragment on IoRestorecommerceOrderOrder { field1 field2 } + countryId country { id name diff --git a/packages/core/graphql/src/lib/generated/generated.ts b/packages/core/graphql/src/lib/generated/generated.ts index 21fe74d..6e25ddc 100644 --- a/packages/core/graphql/src/lib/generated/generated.ts +++ b/packages/core/graphql/src/lib/generated/generated.ts @@ -6383,6 +6383,7 @@ export type OrderFragmentFragment = { buildingNumber?: string | null; locality?: string | null; region?: string | null; + countryId?: string | null; postcode?: string | null; businessAddress?: { __typename?: 'IoRestorecommerceAddressBusinessAddress'; @@ -6424,6 +6425,7 @@ export type OrderFragmentFragment = { buildingNumber?: string | null; locality?: string | null; region?: string | null; + countryId?: string | null; postcode?: string | null; businessAddress?: { __typename?: 'IoRestorecommerceAddressBusinessAddress'; @@ -8688,6 +8690,7 @@ export type OrderingOrderMutateMutation = { buildingNumber?: string | null; locality?: string | null; region?: string | null; + countryId?: string | null; postcode?: string | null; businessAddress?: { __typename?: 'IoRestorecommerceAddressBusinessAddress'; @@ -8729,6 +8732,7 @@ export type OrderingOrderMutateMutation = { buildingNumber?: string | null; locality?: string | null; region?: string | null; + countryId?: string | null; postcode?: string | null; businessAddress?: { __typename?: 'IoRestorecommerceAddressBusinessAddress'; @@ -9270,6 +9274,7 @@ export type OrderingOrderReadQuery = { buildingNumber?: string | null; locality?: string | null; region?: string | null; + countryId?: string | null; postcode?: string | null; businessAddress?: { __typename?: 'IoRestorecommerceAddressBusinessAddress'; @@ -9311,6 +9316,7 @@ export type OrderingOrderReadQuery = { buildingNumber?: string | null; locality?: string | null; region?: string | null; + countryId?: string | null; postcode?: string | null; businessAddress?: { __typename?: 'IoRestorecommerceAddressBusinessAddress'; @@ -9747,6 +9753,7 @@ export const OrderFragmentFragmentDoc = gql` field1 field2 } + countryId country { id name @@ -9781,6 +9788,7 @@ export const OrderFragmentFragmentDoc = gql` field1 field2 } + countryId country { id name diff --git a/packages/modules/order/src/lib/components/order-view.component.ts b/packages/modules/order/src/lib/components/order-view.component.ts index 6cdbce9..a38f58c 100644 --- a/packages/modules/order/src/lib/components/order-view.component.ts +++ b/packages/modules/order/src/lib/components/order-view.component.ts @@ -156,7 +156,8 @@ export class OrderViewComponent implements OnInit, OnDestroy { ? 'Shipping address' : 'Address', schema: buildOrderAddressSchema({ - addressType: addressType, + addressType, + order, }), }, }) diff --git a/packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts b/packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts index 6795465..cf132c7 100644 --- a/packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts +++ b/packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts @@ -1,16 +1,19 @@ -// import { Validators } from '@angular/forms'; +import { Validators } from '@angular/forms'; import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl'; -import { EAddressType } from '@console-core/types'; +import { EAddressType, IOrder } from '@console-core/types'; interface ISchemaOptions { addressType: EAddressType; + order: IOrder; } export const buildOrderAddressSchema = ( options: ISchemaOptions ): VCLFormFieldSchemaRoot => { + const addressWrapper = options.order[options.addressType]; + return { type: 'form', fields: [ @@ -26,8 +29,8 @@ export const buildOrderAddressSchema = ( name: 'buildingNumber', label: 'Building number', type: 'input', - // validators: [Validators.required], - defaultValue: '4', + validators: [Validators.required], + defaultValue: addressWrapper?.address?.buildingNumber || '', params: {}, hints: [ { @@ -41,8 +44,8 @@ export const buildOrderAddressSchema = ( name: 'street', label: 'Street', type: 'input', - // validators: [Validators.required], - defaultValue: 'Ossietzkystraße', + validators: [Validators.required], + defaultValue: addressWrapper?.address?.street || '', params: {}, hints: [ { @@ -56,8 +59,8 @@ export const buildOrderAddressSchema = ( name: 'locality', label: 'Locality', type: 'input', - // validators: [Validators.required], - defaultValue: 'Stuttgart', + validators: [Validators.required], + defaultValue: addressWrapper?.address?.locality || '', params: {}, hints: [ { @@ -71,8 +74,8 @@ export const buildOrderAddressSchema = ( name: 'region', label: 'Region', type: 'input', - // validators: [Validators.required], - defaultValue: 'Stuttgart', + validators: [Validators.required], + defaultValue: addressWrapper?.address?.region || '', params: {}, hints: [ { @@ -86,8 +89,8 @@ export const buildOrderAddressSchema = ( name: 'postcode', label: 'Postcode', type: 'input', - // validators: [Validators.required], - defaultValue: '70174', + validators: [Validators.required], + defaultValue: addressWrapper?.address?.postcode || '', params: {}, hints: [ { @@ -101,8 +104,8 @@ export const buildOrderAddressSchema = ( name: 'countryId', label: 'Country', type: 'select', - defaultValue: 'germany', - // validators: [Validators.required], + defaultValue: addressWrapper?.address?.countryId || '', + validators: [Validators.required], params: { placeholder: 'Country', options: [ @@ -128,54 +131,57 @@ export const buildOrderAddressSchema = ( }, ], }, - { - name: 'packStation', - type: 'object', - fields: [ - { - name: 'provider', - label: 'Provider', - type: 'input', - defaultValue: '', - params: {}, - hints: [ - { - type: 'error', - error: 'required', - message: 'This field is required.', - }, - ], - }, - { - name: 'stationNumber', - label: 'Station number', - type: 'input', - defaultValue: '', - params: {}, - hints: [ - { - type: 'error', - error: 'required', - message: 'This field is required.', - }, - ], - }, - { - name: 'postNumber', - label: 'Post number', - type: 'input', - defaultValue: '', - params: {}, - hints: [ - { - type: 'error', - error: 'required', - message: 'This field is required.', - }, - ], - }, - ], - }, + // { + // name: 'packStation', + // type: 'object', + // fields: [ + // { + // name: 'provider', + // label: 'Provider', + // type: 'input', + // defaultValue: + // addressWrapper?.address?.packStation?.provider || '', + // params: {}, + // hints: [ + // { + // type: 'error', + // error: 'required', + // message: 'This field is required.', + // }, + // ], + // }, + // { + // name: 'stationNumber', + // label: 'Station number', + // type: 'input', + // defaultValue: + // addressWrapper?.address?.packStation?.stationNumber || '', + // params: {}, + // hints: [ + // { + // type: 'error', + // error: 'required', + // message: 'This field is required.', + // }, + // ], + // }, + // { + // name: 'postNumber', + // label: 'Post number', + // type: 'input', + // defaultValue: + // addressWrapper?.address?.packStation?.postNumber || '', + // params: {}, + // hints: [ + // { + // type: 'error', + // error: 'required', + // message: 'This field is required.', + // }, + // ], + // }, + // ], + // }, ], }, { @@ -186,7 +192,7 @@ export const buildOrderAddressSchema = ( name: 'name', label: 'Name', type: 'input', - defaultValue: '', + defaultValue: addressWrapper?.contact?.name || '', params: {}, hints: [ { @@ -200,7 +206,7 @@ export const buildOrderAddressSchema = ( name: 'email', label: 'Email', type: 'input', - defaultValue: '', + defaultValue: addressWrapper?.contact?.email || '', params: {}, hints: [ { @@ -214,7 +220,7 @@ export const buildOrderAddressSchema = ( name: 'phone', label: 'Phone number', type: 'input', - defaultValue: '', + defaultValue: addressWrapper?.contact?.phone || '', params: {}, hints: [ { @@ -227,10 +233,10 @@ export const buildOrderAddressSchema = ( ], }, { - name: 'comment', + name: 'comments', label: 'Comment', type: 'textarea', - defaultValue: '', + defaultValue: addressWrapper?.comments || '', params: {}, hints: [ { diff --git a/packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html b/packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html index acbbd0e..1eaa5b1 100644 --- a/packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html +++ b/packages/modules/ui/src/lib/components/molecules/order-address/order-address.component.html @@ -28,32 +28,6 @@ - - - -