Skip to content

Commit

Permalink
feat: populate the address field
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Sep 4, 2024
1 parent 3789f4d commit 75b7096
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 94 deletions.
2 changes: 2 additions & 0 deletions packages/core/graphql/src/lib/documents/fragments/order.gql
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fragment OrderFragment on IoRestorecommerceOrderOrder {
field1
field2
}
countryId
country {
id
name
Expand Down Expand Up @@ -87,6 +88,7 @@ fragment OrderFragment on IoRestorecommerceOrderOrder {
field1
field2
}
countryId
country {
id
name
Expand Down
8 changes: 8 additions & 0 deletions packages/core/graphql/src/lib/generated/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -9747,6 +9753,7 @@ export const OrderFragmentFragmentDoc = gql`
field1
field2
}
countryId
country {
id
name
Expand Down Expand Up @@ -9781,6 +9788,7 @@ export const OrderFragmentFragmentDoc = gql`
field1
field2
}
countryId
country {
id
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export class OrderViewComponent implements OnInit, OnDestroy {
? 'Shipping address'
: 'Address',
schema: buildOrderAddressSchema({
addressType: addressType,
addressType,
order,
}),
},
})
Expand Down
140 changes: 73 additions & 67 deletions packages/modules/order/src/lib/jss-forms/order-address-jss-form.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand All @@ -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: [
{
Expand All @@ -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: [
{
Expand All @@ -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: [
{
Expand All @@ -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: [
{
Expand All @@ -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: [
{
Expand All @@ -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: [
Expand All @@ -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.',
// },
// ],
// },
// ],
// },
],
},
{
Expand All @@ -186,7 +192,7 @@ export const buildOrderAddressSchema = (
name: 'name',
label: 'Name',
type: 'input',
defaultValue: '',
defaultValue: addressWrapper?.contact?.name || '',
params: {},
hints: [
{
Expand All @@ -200,7 +206,7 @@ export const buildOrderAddressSchema = (
name: 'email',
label: 'Email',
type: 'input',
defaultValue: '',
defaultValue: addressWrapper?.contact?.email || '',
params: {},
hints: [
{
Expand All @@ -214,7 +220,7 @@ export const buildOrderAddressSchema = (
name: 'phone',
label: 'Phone number',
type: 'input',
defaultValue: '',
defaultValue: addressWrapper?.contact?.phone || '',
params: {},
hints: [
{
Expand All @@ -227,10 +233,10 @@ export const buildOrderAddressSchema = (
],
},
{
name: 'comment',
name: 'comments',
label: 'Comment',
type: 'textarea',
defaultValue: '',
defaultValue: addressWrapper?.comments || '',
params: {},
hints: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,6 @@
</div>
</li>

<!-- <li class="row data-list-item justify-between">
<div class="flex text">Field 1:</div>
<div class="flex text align-right rc-lv-label">
<ng-container
*ngIf="
rcOrderAddress?.address?.addressAddition?.field1;
else naTemplate
"
>{{ rcOrderAddress?.address?.addressAddition?.field1 }}</ng-container
>
</div>
</li> -->

<!-- <li class="row data-list-item justify-between">
<div class="flex text">Field 2:</div>
<div class="flex text align-right rc-lv-label">
<ng-container
*ngIf="
rcOrderAddress?.address?.addressAddition?.field2;
else naTemplate
"
>{{ rcOrderAddress?.address?.addressAddition?.field2 }}</ng-container
>
</div>
</li> -->

<li class="row data-list-item justify-between">
<div class="flex text">Street:</div>
<div class="flex text align-right rc-lv-label">
Expand Down

0 comments on commit 75b7096

Please sign in to comment.