@licklist/design 0.44.529 → 0.44.530
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@licklist/core/dist/Config"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@licklist/core/dist/Config"),n=require("react-i18next"),r=require("react-intl");exports.useCategoryVerification=function(){var t=n.useTranslation("Validation").t,i=r.useIntl().formatNumber;return function(n,r,u){var a,o=Object.values(n).filter((function(e){return(null==e?void 0:e.quantity)>0})),c=r.reduce((function(e,n){return e+n.products.filter((function(e){return o.map((function(e){return e.id})).includes(null==e?void 0:e.id)})).reduce((function(e,n){var r,t=(null===(r=o.find((function(e){return e.id===n.id})))||void 0===r?void 0:r.quantity)||1;return e+n.minSpend*t}),0)}),0),d=o.reduce((function(e,n){return e+n.price*n.quantity}),0);if(r.forEach((function(e){var n=e.minSubItems,r=e.maxSubItems,i=e.id,u=e.name;if(n||r){var c=o.filter((function(e){return(null==e?void 0:e.productsCategoryId)===i})).length;if(n&&c<n){var d=t("Validation:fieldMinNumber",{min:n,attribute:"number of products in the ".concat(u," category")});a={id:i,message:d}}else if(r&&c>r){d=t("Validation:fieldMaxNumber",{max:r,attribute:"number of products in the ".concat(u," category")});a={id:i,message:d}}}})),d<c&&!a&&u){var l=t("Design:minimumSpendSumValidation",{minSpend:i(c,{style:"currency",currency:e.Currency.GBP})});a={message:l}}return a}};
|
package/package.json
CHANGED
|
@@ -27,12 +27,12 @@ export const useCategoryVerification = () => {
|
|
|
27
27
|
const selectedProducts = products.filter((product) =>
|
|
28
28
|
productArray.map((el) => el.id).includes(product?.id)
|
|
29
29
|
);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const productMinSpendsSum = selectedProducts.reduce((sum, product) => {
|
|
31
|
+
const quantity =
|
|
32
|
+
productArray.find((selected) => selected.id === product.id)
|
|
33
|
+
?.quantity || 1;
|
|
34
|
+
return sum + product.minSpend * quantity;
|
|
35
|
+
}, 0);
|
|
36
36
|
|
|
37
37
|
return acc + productMinSpendsSum;
|
|
38
38
|
}, 0);
|