From 45c272691052dc3dbada0a430e091e805f44a92d Mon Sep 17 00:00:00 2001 From: Dawid Tarasiuk Date: Mon, 29 Nov 2021 13:32:51 +0100 Subject: [PATCH] Fix saving initial variant attributes (#1624) --- src/attributes/utils/data.ts | 11 +++++++++++ src/products/utils/data.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/attributes/utils/data.ts b/src/attributes/utils/data.ts index d50fafbaa..01feba939 100644 --- a/src/attributes/utils/data.ts +++ b/src/attributes/utils/data.ts @@ -7,6 +7,7 @@ import { AttributeErrorFragment } from "@saleor/fragments/types/AttributeErrorFr import { AttributeValueFragment } from "@saleor/fragments/types/AttributeValueFragment"; import { SelectedVariantAttributeFragment } from "@saleor/fragments/types/SelectedVariantAttributeFragment"; import { UploadErrorFragment } from "@saleor/fragments/types/UploadErrorFragment"; +import { VariantAttributeFragment } from "@saleor/fragments/types/VariantAttributeFragment"; import { FormsetData } from "@saleor/hooks/useFormset"; import { PageDetails_page_attributes } from "@saleor/pages/types/PageDetails"; import { ProductDetails_product_attributes } from "@saleor/products/types/ProductDetails"; @@ -132,6 +133,16 @@ export function getAttributeData( } } +export function getDefaultAttributeValues(attribute: VariantAttributeFragment) { + switch (attribute.inputType) { + case AttributeInputTypeEnum.BOOLEAN: + return ["false"]; + + default: + return []; + } +} + export function getSelectedAttributeValues( attribute: | PageDetails_page_attributes diff --git a/src/products/utils/data.ts b/src/products/utils/data.ts index 437bfc34a..8d2831d9c 100644 --- a/src/products/utils/data.ts +++ b/src/products/utils/data.ts @@ -1,4 +1,5 @@ import { + getDefaultAttributeValues, getSelectedAttributeValues, mergeChoicesWithValues } from "@saleor/attributes/utils/data"; @@ -97,7 +98,7 @@ export function getAttributeInputFromAttributes( }, id: attribute.id, label: attribute.name, - value: [] + value: getDefaultAttributeValues(attribute) })); }