From 9e8f453c99c3c950f2e2be93cc51cb1febb368f9 Mon Sep 17 00:00:00 2001 From: Dawid Tarasiuk Date: Wed, 16 Sep 2020 13:55:49 +0200 Subject: [PATCH] Add no warehouses info in variant creator --- locale/defaultMessages.json | 4 + .../ProductVariantCreatorStock.tsx | 370 +++++++++--------- 2 files changed, 196 insertions(+), 178 deletions(-) diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index 546019980..3721f20ef 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -302,6 +302,10 @@ "context": "variant stock, header", "string": "Stock" }, + "productVariantCreatorWarehouseSectionDescription": { + "context": "no warehouses info", + "string": "There are no warehouses set up for your store. You can configure your variants without providing stock quantites." + }, "productVariantCreatorWarehouseSectionHeader": { "context": "header", "string": "Warehouses" diff --git a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorStock.tsx b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorStock.tsx index 51770851a..11066b09b 100644 --- a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorStock.tsx +++ b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorStock.tsx @@ -123,192 +123,206 @@ const ProductVariantCreatorStock: React.FC = pr })} /> - {warehouses.length > 1 && ( + {!warehouses.length ? ( + + + + ) : ( <> - - - - - acc + attr.values.length, - 0 - ) - }} - /> - -
- {warehouses.map(warehouse => ( - a === b - )} - name={`warehouse:${warehouse.id}`} - label={warehouse.name} - onChange={() => onWarehouseToggle(warehouse.id)} - key={warehouse.id} - /> - ))} -
- -
- - - )} - - - - - } - label={intl.formatMessage({ - defaultMessage: "Apply single stock to all SKUs" - })} - onChange={() => onApplyToAllChange("all")} - /> - {data.stock.mode === "all" && ( -
- {data.warehouses.map((warehouseId, warehouseIndex) => ( -
- - { - warehouses.find(warehouse => warehouse.id === warehouseId) - .name - } - - - onApplyToAllStockChange( - parseInt(event.target.value, 10), - warehouseIndex - ) - } + {warehouses.length > 1 && ( + <> + + + + + acc + attr.values.length, + 0 + ) + }} + /> + +
+ {warehouses.map(warehouse => ( + a === b + )} + name={`warehouse:${warehouse.id}`} + label={warehouse.name} + onChange={() => onWarehouseToggle(warehouse.id)} + key={warehouse.id} + /> + ))}
- ))} -
- )} - - } - label={intl.formatMessage({ - defaultMessage: "Apply unique stock by attribute to each SKU" - })} - onChange={() => onApplyToAllChange("attribute")} - /> - {data.stock.mode === "attribute" && ( - <> - - onAttributeSelect(event.target.value)} + +
+ + + )} + + - {stockAttributeValues && ( - <> -
- -
-
-
- {data.stock.attribute && - data.warehouses.map(warehouseId => ( - - { - warehouses.find( - warehouse => warehouse.id === warehouseId - ).name - } - - ))} - {stockAttributeValues.map(attributeValue => ( - - {attributeValue.name} - {data.warehouses.map( - (warehouseId, warehouseIndex) => ( - value.slug === attributeValue.slug - ).value[warehouseIndex] - } - onChange={event => - onAttributeValueChange( - attributeValue.slug, - parseInt(event.target.value, 10), - warehouseIndex - ) - } - key={warehouseId} - /> - ) - )} - - ))} + + + } + label={intl.formatMessage({ + defaultMessage: "Apply single stock to all SKUs" + })} + onChange={() => onApplyToAllChange("all")} + /> + {data.stock.mode === "all" && ( +
+ {data.warehouses.map((warehouseId, warehouseIndex) => ( +
+ + { + warehouses.find( + warehouse => warehouse.id === warehouseId + ).name + } + + + onApplyToAllStockChange( + parseInt(event.target.value, 10), + warehouseIndex + ) + } + />
-
+ ))} +
+ )} + + } + label={intl.formatMessage({ + defaultMessage: "Apply unique stock by attribute to each SKU" + })} + onChange={() => onApplyToAllChange("attribute")} + /> + {data.stock.mode === "attribute" && ( + <> + + onAttributeSelect(event.target.value)} + /> + {stockAttributeValues && ( + <> +
+ +
+
+
+ {data.stock.attribute && + data.warehouses.map(warehouseId => ( + + { + warehouses.find( + warehouse => warehouse.id === warehouseId + ).name + } + + ))} + {stockAttributeValues.map(attributeValue => ( + + {attributeValue.name} + {data.warehouses.map( + (warehouseId, warehouseIndex) => ( + + value.slug === attributeValue.slug + ).value[warehouseIndex] + } + onChange={event => + onAttributeValueChange( + attributeValue.slug, + parseInt(event.target.value, 10), + warehouseIndex + ) + } + key={warehouseId} + /> + ) + )} + + ))} +
+
+ + )} + + )} + {data.stock.mode === "attribute" && !!data.stock.attribute && ( + <> + +
)} - - )} - {data.stock.mode === "attribute" && !!data.stock.attribute && ( - <> -
- - )} - - } - label={intl.formatMessage({ - defaultMessage: "Skip stock for now" - })} - onChange={() => onApplyToAllChange("skip")} - /> - + } + label={intl.formatMessage({ + defaultMessage: "Skip stock for now" + })} + onChange={() => onApplyToAllChange("skip")} + /> + + + )} );