@licklist/design 0.44.486-dev.40 → 0.44.486-dev.41
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.
- package/dist/iframe/order-process/components/CategoryProduct/CategoryProduct.d.ts.map +1 -1
- package/dist/iframe/order-process/components/CategoryProduct/CategoryProduct.js +1 -1
- package/dist/iframe/order-process/components/utils/useCategoryVerification.d.ts +1 -1
- package/dist/iframe/order-process/components/utils/useCategoryVerification.d.ts.map +1 -1
- package/dist/iframe/order-process/components/utils/useCategoryVerification.js +1 -1
- package/package.json +1 -1
- package/src/iframe/order-process/components/CategoryProduct/CategoryProduct.tsx +0 -10
- package/src/iframe/order-process/components/utils/useCategoryVerification.ts +32 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoryProduct.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/order-process/components/CategoryProduct/CategoryProduct.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AAExF,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG7D,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,wBAAwB,EAAE,CAAC;IAChD,eAAe,CAAC,EAAE,wBAAwB,EAAE,CAAC;CAC9C;AAED,eAAO,MAAM,eAAe,sFAMzB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"CategoryProduct.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/order-process/components/CategoryProduct/CategoryProduct.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AAExF,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG7D,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,kBAAkB,CAAC,EAAE,wBAAwB,EAAE,CAAC;IAChD,eAAe,CAAC,EAAE,wBAAwB,EAAE,CAAC;CAC9C;AAED,eAAO,MAAM,eAAe,sFAMzB,oBAAoB,gBA8LtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=require("tslib"),t=require("react"),i=e(t),n=require("@licklist/core/dist/Config"),a=require("react-i18next"),
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var r=require("tslib"),t=require("react"),i=e(t),n=require("@licklist/core/dist/Config"),a=require("react-i18next"),o=require("react-hook-form"),c=e(require("@licklist/plugins/dist/services/Form/HookFormService")),u=e(require("clsx")),s=require("react-intl"),d=require("../../../event/ticket-description/TicketDescription.js"),l=require("./components/ProductQuantityInput/ProductQuantityInput.js");exports.CategoryProduct=function(e){var m=e.product,p=e.category,v=e.canExpandDescription,f=void 0===v||v,y=e.productsWithErrors,g=e.soldOutProducts,E=s.useIntl().formatNumber,q=a.useTranslation(["Design","Validation"]).t,_=o.useFormContext(),x=_.control,N=_.clearErrors,A=_.setError,C=t.useMemo((function(){if(y){var e=y.find((function(e){return e.product_id===m.id}));return null==e?void 0:e.message}}),[y,m.id]),P=t.useMemo((function(){if(p.allowDeposits&&m.deposit&&!(null==m?void 0:m.isSoldOut)&&!(m.deposit>=m.price))return m.deposit}),[p,m]),D=function(){if(g&&!(null==m?void 0:m.isSoldOut)){var e=g.find((function(e){return e.product_id===m.id}));return!!(null==e?void 0:e.message)}};return t.useEffect((function(){C&&A("".concat(m.id),{message:C,type:"validate"})}),[C,m.id]),i.createElement(o.Controller,{control:x,name:"".concat(m.id),rules:{required:m.isRequired,validate:function(e){var r,t=m.isRequired,i=void 0!==t&&t,n=m.maxAmount,a=void 0===n?0:n,o=m.minAmount,c=void 0===o?0:o,u=null!==(r=null==e?void 0:e.quantity)&&void 0!==r?r:0;return!e||(!u&&!i||(!u&&i?q("Design:pleaseSelectAtLeastFrom",{min:1,type:"item",from:"this category"}):u<c?q("Validation:fieldMinNumber",{min:m.minAmount,attribute:m.name}):!(a&&u>=c&&a<u)||q("Validation:quantityMaxNumber",{max:m.maxAmount})))}},render:function(e){var t=e.field,a=t.onChange,o=t.value,s=void 0===o?{}:o,v=t.ref,y=e.fieldState,g=y.invalid,_=y.error;return i.createElement("div",{id:String(m.id),className:"iframe-event__category-product"},i.createElement("div",{className:u("iframe-event__product",g&&"error")},i.createElement(d.TicketDescription,{title:m.name,description:m.description,className:u("iframe-event__product-description"),images:m.images,isRequired:m.isRequired,canExpand:f})),i.createElement("div",{className:"iframe-event__product-price-wrapper"},i.createElement("span",{className:"product-price"},E(null!=P?P:m.price,{style:"currency",currency:n.Currency.GBP})),i.createElement(l.ProductQuantityInput,{onChange:a,productInfo:s,refCallback:v,clearErrors:N,product:r.__assign(r.__assign({},m),{isSoldOut:(null==m?void 0:m.isSoldOut)||D()}),category:p,invalid:g,deposit:P})),P&&!(null==p?void 0:p.remainderExpireAfter)&&i.createElement("div",{className:"mt-4"},q("Design:payNowAndUponArrival",{deposit:E(P,{style:"currency",currency:n.Currency.GBP}),remainder:E(m.price-P,{style:"currency",currency:n.Currency.GBP})})),P&&(null==p?void 0:p.remainderExpireAfter)>0&&i.createElement("div",{className:"mt-4"},q("Design:payNowAndReminderDays",{deposit:E(P,{style:"currency",currency:n.Currency.GBP}),remainder:E(m.price-P,{style:"currency",currency:n.Currency.GBP}),days:null==p?void 0:p.remainderExpireAfter})),g&&i.createElement("div",{className:"d-flex mt-3 w-100"},i.createElement("p",{className:"iframe-event__message-error"},c.hasError(_,"required")&&q("Design:pleaseSelectAtLeastFrom",{min:1,type:"item",from:"this category"}),c.hasError(_,"validate")&&_.message)))}})};
|
|
@@ -2,7 +2,7 @@ import { ProductCategory } from "@licklist/core/dist/DataMapper/Product/ProductC
|
|
|
2
2
|
import { Order } from "src/types";
|
|
3
3
|
interface CategoryError {
|
|
4
4
|
message: string;
|
|
5
|
-
id
|
|
5
|
+
id?: number;
|
|
6
6
|
}
|
|
7
7
|
export declare const useCategoryVerification: () => (values: Record<Order["id"], Order>, productCategories?: ProductCategory[]) => CategoryError | void;
|
|
8
8
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCategoryVerification.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/order-process/components/utils/useCategoryVerification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kEAAkE,CAAC;
|
|
1
|
+
{"version":3,"file":"useCategoryVerification.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/order-process/components/utils/useCategoryVerification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kEAAkE,CAAC;AAInG,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,UAAU,aAAa;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAGD,eAAO,MAAM,uBAAuB,iBAIxB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,sBACd,eAAe,EAAE,KACpC,aAAa,GAAG,IA8DpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react-i18next");exports.useCategoryVerification=function(){var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@licklist/core/dist/Config"),r=require("react-i18next"),t=require("react-intl");exports.useCategoryVerification=function(){var n=r.useTranslation("Validation").t,i=t.useIntl().formatNumber;return function(r,t){var u,a=t.reduce((function(e,r){return e+r.products.reduce((function(e,r){return e+((null==r?void 0:r.minSpend)?r.minSpend:0)}),0)}),0),o=Object.values(r).filter((function(e){return(null==e?void 0:e.quantity)>0})),c=o.reduce((function(e,r){return e+r.price*r.quantity}),0);if(t.forEach((function(e){var r=e.minSubItems,t=e.maxSubItems,i=e.id,a=e.name;if(r||t){var c=o.filter((function(e){return(null==e?void 0:e.productsCategoryId)===i})).length;if(r&&c<r){var d=n("Validation:fieldMinNumber",{min:r,attribute:"number of products in the ".concat(a," category")});u={id:i,message:d}}else if(t&&c>t){d=n("Validation:fieldMaxNumber",{max:t,attribute:"number of products in the ".concat(a," category")});u={id:i,message:d}}}})),c<a&&!u){var d=n("Design:minimumSpendSumValidation",{minSpend:i(a,{style:"currency",currency:e.Currency.GBP})});u={message:d}}return u}};
|
package/package.json
CHANGED
|
@@ -88,19 +88,9 @@ export const CategoryProduct = ({
|
|
|
88
88
|
isRequired = false,
|
|
89
89
|
maxAmount = 0,
|
|
90
90
|
minAmount = 0,
|
|
91
|
-
minSpend,
|
|
92
|
-
price,
|
|
93
91
|
} = product;
|
|
94
92
|
|
|
95
93
|
const currentQuantity = value?.quantity ?? 0;
|
|
96
|
-
if (minSpend && currentQuantity * price < minSpend) {
|
|
97
|
-
return t("Design:minimumSpendSumValidation", {
|
|
98
|
-
minSpend: formatNumber(minSpend, {
|
|
99
|
-
style: "currency",
|
|
100
|
-
currency: Config.Currency.GBP,
|
|
101
|
-
}),
|
|
102
|
-
}) as string;
|
|
103
|
-
}
|
|
104
94
|
|
|
105
95
|
if (!value) return true;
|
|
106
96
|
|
|
@@ -1,25 +1,44 @@
|
|
|
1
1
|
import { ProductCategory } from "@licklist/core/dist/DataMapper/Product/ProductCategoryDataMapper";
|
|
2
|
+
import { Currency } from "@licklist/core/dist/Config";
|
|
3
|
+
import { useIntl } from "react-intl";
|
|
2
4
|
import { useTranslation } from "react-i18next";
|
|
3
5
|
import { Order } from "src/types";
|
|
4
6
|
|
|
5
7
|
interface CategoryError {
|
|
6
8
|
message: string;
|
|
7
|
-
id
|
|
9
|
+
id?: number;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
// TODO it's temporary solution, please remove it later
|
|
11
13
|
export const useCategoryVerification = () => {
|
|
12
14
|
const { t } = useTranslation("Validation");
|
|
13
|
-
|
|
15
|
+
const { formatNumber } = useIntl();
|
|
14
16
|
return (
|
|
15
17
|
values: Record<Order["id"], Order>,
|
|
16
18
|
productCategories?: ProductCategory[]
|
|
17
19
|
): CategoryError | void => {
|
|
18
|
-
let errorMessage: { id
|
|
20
|
+
let errorMessage: { id?: number; message: string } | void;
|
|
21
|
+
|
|
22
|
+
const sumOfMinSpends = productCategories.reduce(
|
|
23
|
+
(acc, productCategories) => {
|
|
24
|
+
const { products } = productCategories;
|
|
25
|
+
|
|
26
|
+
const productMinSpends = products.reduce((productAcc, product) => {
|
|
27
|
+
const minSpendValue = !product?.minSpend ? 0 : product.minSpend;
|
|
28
|
+
return productAcc + minSpendValue;
|
|
29
|
+
}, 0);
|
|
19
30
|
|
|
31
|
+
return acc + productMinSpends;
|
|
32
|
+
},
|
|
33
|
+
0
|
|
34
|
+
);
|
|
20
35
|
const productArray = Object.values(values).filter(
|
|
21
36
|
(product) => product?.quantity > 0
|
|
22
37
|
);
|
|
38
|
+
const totalPrice = productArray.reduce(
|
|
39
|
+
(total, product) => total + product.price * product.quantity,
|
|
40
|
+
0
|
|
41
|
+
);
|
|
23
42
|
|
|
24
43
|
productCategories.forEach(({ minSubItems, maxSubItems, id, name }) => {
|
|
25
44
|
if (!minSubItems && !maxSubItems) return;
|
|
@@ -47,6 +66,16 @@ export const useCategoryVerification = () => {
|
|
|
47
66
|
}
|
|
48
67
|
});
|
|
49
68
|
|
|
69
|
+
if (totalPrice < sumOfMinSpends && !errorMessage) {
|
|
70
|
+
const message = t("Design:minimumSpendSumValidation", {
|
|
71
|
+
minSpend: formatNumber(sumOfMinSpends, {
|
|
72
|
+
style: "currency",
|
|
73
|
+
currency: Currency.GBP,
|
|
74
|
+
}),
|
|
75
|
+
}) as string;
|
|
76
|
+
errorMessage = { message };
|
|
77
|
+
}
|
|
78
|
+
|
|
50
79
|
return errorMessage;
|
|
51
80
|
};
|
|
52
81
|
};
|