Skip to content

Commit

Permalink
feat: pass variant data to the edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
belsman committed Aug 21, 2024
1 parent 4246b09 commit 90735d1
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 129 deletions.
3 changes: 3 additions & 0 deletions packages/core/graphql/src/lib/documents/fragments/product.gql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fragment ProductFragment on IoRestorecommerceProductProduct {
variants {
id
name
description
# images {
# id
# index
Expand All @@ -26,7 +27,9 @@ fragment ProductFragment on IoRestorecommerceProductProduct {
# url
# }
stockLevel
stockKeepingUnit
parentVariantId
taxIds
price {
currencyId
regularPrice
Expand Down
97 changes: 21 additions & 76 deletions packages/core/graphql/src/lib/generated/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5429,19 +5429,11 @@ export type CatalogProductMutateMutation = {
__typename?: 'IoRestorecommerceProductPhysicalVariant';
id?: string | null;
name?: string | null;
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
images?: Array<{
__typename?: 'IoRestorecommerceImageImage';
id?: string | null;
index?: number | null;
filename?: string | null;
caption?: string | null;
contentType?: string | null;
height?: number | null;
width?: number | null;
url?: string | null;
}> | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
currencyId?: string | null;
Expand Down Expand Up @@ -5534,19 +5526,11 @@ export type CatalogProductReadQuery = {
__typename?: 'IoRestorecommerceProductPhysicalVariant';
id?: string | null;
name?: string | null;
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
images?: Array<{
__typename?: 'IoRestorecommerceImageImage';
id?: string | null;
index?: number | null;
filename?: string | null;
caption?: string | null;
contentType?: string | null;
height?: number | null;
width?: number | null;
url?: string | null;
}> | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
currencyId?: string | null;
Expand Down Expand Up @@ -6015,19 +5999,11 @@ export type OrderFragmentFragment = {
__typename?: 'IoRestorecommerceProductPhysicalVariant';
id?: string | null;
name?: string | null;
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
images?: Array<{
__typename?: 'IoRestorecommerceImageImage';
id?: string | null;
index?: number | null;
filename?: string | null;
caption?: string | null;
contentType?: string | null;
height?: number | null;
width?: number | null;
url?: string | null;
}> | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
currencyId?: string | null;
Expand Down Expand Up @@ -6561,19 +6537,11 @@ export type ProductFragmentFragment = {
__typename?: 'IoRestorecommerceProductPhysicalVariant';
id?: string | null;
name?: string | null;
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
images?: Array<{
__typename?: 'IoRestorecommerceImageImage';
id?: string | null;
index?: number | null;
filename?: string | null;
caption?: string | null;
contentType?: string | null;
height?: number | null;
width?: number | null;
url?: string | null;
}> | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
currencyId?: string | null;
Expand Down Expand Up @@ -8294,19 +8262,11 @@ export type OrderingOrderMutateMutation = {
__typename?: 'IoRestorecommerceProductPhysicalVariant';
id?: string | null;
name?: string | null;
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
images?: Array<{
__typename?: 'IoRestorecommerceImageImage';
id?: string | null;
index?: number | null;
filename?: string | null;
caption?: string | null;
contentType?: string | null;
height?: number | null;
width?: number | null;
url?: string | null;
}> | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
currencyId?: string | null;
Expand Down Expand Up @@ -8840,19 +8800,11 @@ export type OrderingOrderReadQuery = {
__typename?: 'IoRestorecommerceProductPhysicalVariant';
id?: string | null;
name?: string | null;
description?: string | null;
stockLevel?: number | null;
stockKeepingUnit?: string | null;
parentVariantId?: string | null;
images?: Array<{
__typename?: 'IoRestorecommerceImageImage';
id?: string | null;
index?: number | null;
filename?: string | null;
caption?: string | null;
contentType?: string | null;
height?: number | null;
width?: number | null;
url?: string | null;
}> | null;
taxIds?: Array<string> | null;
price?: {
__typename?: 'IoRestorecommercePricePrice';
currencyId?: string | null;
Expand Down Expand Up @@ -9456,18 +9408,11 @@ export const ProductFragmentFragmentDoc = gql`
variants {
id
name
images {
id
index
filename
caption
contentType
height
width
url
}
description
stockLevel
stockKeepingUnit
parentVariantId
taxIds
price {
currencyId
regularPrice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ProductFacade {

update = (payload: IIoRestorecommerceProductProductList) => {
const tempPayload = addTemporaryMetaForCatalogSrv(payload);
console.log("tempPayload", tempPayload);
console.log('tempPayload', tempPayload);

this.store.dispatch(
productActions.productUpdateRequest({ payload: tempPayload })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { v4 as uuidv4 } from 'uuid';
import { ComponentLayerRef, JssFormComponent } from '@vcl/ng-vcl';

import {
IIoRestorecommerceProductPhysicalVariant,
IoRestorecommerceProductPhysicalVariant,
ModeType,
} from '@console-core/graphql';
Expand Down Expand Up @@ -45,7 +46,9 @@ export class ProductVariantEditComponent {
@ViewChild('variantModalForm')
variantModalForm!: JssFormComponent;

schema = buildProductVariantSchema({});
schema = buildProductVariantSchema({
product: this.variant,
});

get title(): string {
return this.layer.data.title;
Expand All @@ -55,6 +58,10 @@ export class ProductVariantEditComponent {
return this.layer.data.product;
}

get variant(): IIoRestorecommerceProductPhysicalVariant {
return this.layer.data.variant;
}

close(value?: string) {
this.layer.close({
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ export class ProductViewComponent implements OnInit, OnDestroy {
.subscribe();
}

onEditVariant(_: IIoRestorecommerceProductPhysicalVariant) {
onEditVariant(variant: IIoRestorecommerceProductPhysicalVariant) {
console.log('variant:', variant);
this.subscriptions.sink = this.addVariantLayer
.open({
data: {
title: `Edit product variant`,
// product,
variant,
},
})
.subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import { Validators } from '@angular/forms';

import { VCLFormFieldSchemaRoot } from '@vcl/ng-vcl';

import { IProduct } from '@console-core/types';
// import { IProduct } from '@console-core/types';
import { IoRestorecommerceProductPhysicalVariant } from '@console-core/graphql';

interface ISchemaOptions {
product?: IProduct;
product?: IoRestorecommerceProductPhysicalVariant;
}

export const buildProductVariantSchema = (
options: ISchemaOptions
): VCLFormFieldSchemaRoot => {
console.log('options?.product?.product', options?.product?.product);

return {
type: 'form',
fields: [
Expand Down Expand Up @@ -63,7 +62,7 @@ export const buildProductVariantSchema = (
label: 'Name',
type: 'input',
validators: [Validators.required],
defaultValue: 'Blue Type',
defaultValue: options?.product?.name || '',
params: {},
hints: [
{
Expand All @@ -78,16 +77,15 @@ export const buildProductVariantSchema = (
label: 'Description',
type: 'input',
validators: [],
defaultValue:
'A test decription about this type of particular variant!',
defaultValue: options?.product?.description || '',
params: {},
},
{
name: 'stockLevel',
label: 'Stock level',
type: 'input',
validators: [Validators.required],
defaultValue: 99,
defaultValue: options?.product?.stockLevel || '',
params: {
inputType: 'number',
},
Expand All @@ -104,7 +102,7 @@ export const buildProductVariantSchema = (
label: 'Stock keeping unit',
type: 'input',
validators: [],
defaultValue: 'qwerty1012',
defaultValue: options?.product?.stockKeepingUnit || '',
params: {},
hints: [
{
Expand All @@ -118,7 +116,7 @@ export const buildProductVariantSchema = (
name: 'taxIds',
label: 'Taxes',
type: 'select',
defaultValue: ['germany-reduced-rate', 'germany-standard-rate'],
defaultValue: options?.product?.taxIds || [],
validators: [Validators.required],
params: {
placeholder: 'Select taxes',
Expand Down Expand Up @@ -178,7 +176,7 @@ export const buildProductVariantSchema = (
label: 'Currency',
type: 'select',
// disabled: true,
defaultValue: 'USD',
defaultValue: options?.product?.price?.currencyId || '',
validators: [Validators.required],
params: {
placeholder: 'Select currency',
Expand Down Expand Up @@ -209,7 +207,7 @@ export const buildProductVariantSchema = (
label: 'Regular price',
type: 'input',
validators: [Validators.required],
defaultValue: 10,
defaultValue: options?.product?.price?.regularPrice || '',
params: {
inputType: 'number',
},
Expand All @@ -219,14 +217,19 @@ export const buildProductVariantSchema = (
error: 'required',
message: 'This field is required.',
},
{
type: 'error',
error: 'min',
message: '',
},
],
},
{
name: 'salePrice',
label: 'Sale price',
type: 'input',
validators: [Validators.required],
defaultValue: 10,
defaultValue: options?.product?.price?.salePrice || '',
params: {
inputType: 'number',
},
Expand All @@ -240,7 +243,7 @@ export const buildProductVariantSchema = (
},
{
type: 'checkbox',
defaultValue: false,
defaultValue: options?.product?.price?.sale || false,
name: 'sale',
label: 'On sales',
},
Expand Down
35 changes: 0 additions & 35 deletions packages/modules/product/src/lib/jss-forms/product.jss-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,41 +265,6 @@ export const buildProductSchema = (
},
],
},
// {
// name: 'offerings',
// label: 'Offerings',
// type: 'select',
// // disabled: true,
// defaultValue: '',
// validators: [Validators.required],
// params: {
// placeholder: 'Select offering',
// selectionMode: 'single',
// clearable: false,
// search: false,
// options: [
// {
// label: 'Physical',
// value: 'physical',
// },
// {
// label: 'Virtual',
// value: 'virtual',
// },
// {
// label: 'Service',
// value: 'service'
// }
// ],
// },
// hints: [
// {
// type: 'error',
// error: 'required',
// message: 'This field is required.',
// },
// ],
// },
{
type: 'buttons',
buttons: [
Expand Down

0 comments on commit 90735d1

Please sign in to comment.