@licklist/design 0.44.486-dev.40 → 0.44.486-dev.42

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
- {"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,gBAwMtB,CAAC"}
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"),c=require("react-hook-form"),o=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,y=e.canExpandDescription,v=void 0===y||y,f=e.productsWithErrors,g=e.soldOutProducts,E=s.useIntl().formatNumber,q=a.useTranslation(["Design","Validation"]).t,_=c.useFormContext(),x=_.control,N=_.clearErrors,C=_.setError,S=t.useMemo((function(){if(f){var e=f.find((function(e){return e.product_id===m.id}));return null==e?void 0:e.message}}),[f,m.id]),A=t.useMemo((function(){if(p.allowDeposits&&m.deposit&&!(null==m?void 0:m.isSoldOut)&&!(m.deposit>=m.price))return m.deposit}),[p,m]),P=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(){S&&C("".concat(m.id),{message:S,type:"validate"})}),[S,m.id]),i.createElement(c.Controller,{control:x,name:"".concat(m.id),rules:{required:m.isRequired,validate:function(e){var r,t=m.isRequired,i=void 0!==t&&t,a=m.maxAmount,c=void 0===a?0:a,o=m.minAmount,u=void 0===o?0:o,s=m.minSpend,d=m.price,l=null!==(r=null==e?void 0:e.quantity)&&void 0!==r?r:0;return s&&l*d<s?q("Design:minimumSpendSumValidation",{minSpend:E(s,{style:"currency",currency:n.Currency.GBP})}):!e||(!l&&!i||(!l&&i?q("Design:pleaseSelectAtLeastFrom",{min:1,type:"item",from:"this category"}):l<u?q("Validation:fieldMinNumber",{min:m.minAmount,attribute:m.name}):!(c&&l>=u&&c<l)||q("Validation:quantityMaxNumber",{max:m.maxAmount})))}},render:function(e){var t=e.field,a=t.onChange,c=t.value,s=void 0===c?{}:c,y=t.ref,f=e.fieldState,g=f.invalid,_=f.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:v})),i.createElement("div",{className:"iframe-event__product-price-wrapper"},i.createElement("span",{className:"product-price"},E(null!=A?A:m.price,{style:"currency",currency:n.Currency.GBP})),i.createElement(l.ProductQuantityInput,{onChange:a,productInfo:s,refCallback:y,clearErrors:N,product:r.__assign(r.__assign({},m),{isSoldOut:(null==m?void 0:m.isSoldOut)||P()}),category:p,invalid:g,deposit:A})),A&&!(null==p?void 0:p.remainderExpireAfter)&&i.createElement("div",{className:"mt-4"},q("Design:payNowAndUponArrival",{deposit:E(A,{style:"currency",currency:n.Currency.GBP}),remainder:E(m.price-A,{style:"currency",currency:n.Currency.GBP})})),A&&(null==p?void 0:p.remainderExpireAfter)>0&&i.createElement("div",{className:"mt-4"},q("Design:payNowAndReminderDays",{deposit:E(A,{style:"currency",currency:n.Currency.GBP}),remainder:E(m.price-A,{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"},o.hasError(_,"required")&&q("Design:pleaseSelectAtLeastFrom",{min:1,type:"item",from:"this category"}),o.hasError(_,"validate")&&_.message)))}})};
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: number;
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;AAEnG,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,UAAU,aAAa;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAGD,eAAO,MAAM,uBAAuB,iBAIxB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,sBACd,eAAe,EAAE,KACpC,aAAa,GAAG,IAmCpB,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,IAkEpB,CAAC"}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react-i18next");exports.useCategoryVerification=function(){var t=e.useTranslation("Validation").t;return function(e,r){var i,n=Object.values(e).filter((function(e){return(null==e?void 0:e.quantity)>0}));return r.forEach((function(e){var r=e.minSubItems,a=e.maxSubItems,u=e.id,o=e.name;if(r||a){var c=n.filter((function(e){return(null==e?void 0:e.productsCategoryId)===u})).length;if(r&&c<r){var s=t("Validation:fieldMinNumber",{min:r,attribute:"number of products in the ".concat(o," category")});i={id:u,message:s}}else if(a&&c>a){s=t("Validation:fieldMaxNumber",{max:a,attribute:"number of products in the ".concat(o," category")});i={id:u,message:s}}}})),i}};
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=Object.values(r).filter((function(e){return(null==e?void 0:e.quantity)>0})),o=t.reduce((function(e,r){var t=r.products.filter((function(e){return a.map((function(e){return e.id})).includes(null==e?void 0:e.id)}));return t.length?e+t.reduce((function(e,r){return e+((null==r?void 0:r.minSpend)||0)}),0):0}),0),c=a.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,o=e.name;if(r||t){var c=a.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(o," category")});u={id:i,message:d}}else if(t&&c>t){d=n("Validation:fieldMaxNumber",{max:t,attribute:"number of products in the ".concat(o," category")});u={id:i,message:d}}}})),c<o&&!u){var d=n("Design:minimumSpendSumValidation",{minSpend:i(o,{style:"currency",currency:e.Currency.GBP})});u={message:d}}return u}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@licklist/design",
3
- "version": "0.44.486-dev.40",
3
+ "version": "0.44.486-dev.42",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+ssh://git@bitbucket.org/artelogicsoft/licklist_design.git"
@@ -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,48 @@
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: number;
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: number; message: string } | void;
19
-
20
+ let errorMessage: { id?: number; message: string } | void;
20
21
  const productArray = Object.values(values).filter(
21
22
  (product) => product?.quantity > 0
22
23
  );
24
+ const sumOfMinSpends = productCategories.reduce((acc, productCategory) => {
25
+ const { products } = productCategory;
26
+ const selectedProducts = products.filter((product) =>
27
+ productArray.map((el) => el.id).includes(product?.id)
28
+ );
29
+
30
+ if (!selectedProducts.length) {
31
+ return 0;
32
+ }
33
+
34
+ const productMinSpendsSum = selectedProducts.reduce(
35
+ (sum, product) => sum + (product?.minSpend || 0),
36
+ 0
37
+ );
38
+
39
+ return acc + productMinSpendsSum;
40
+ }, 0);
41
+
42
+ const totalPrice = productArray.reduce(
43
+ (total, product) => total + product.price * product.quantity,
44
+ 0
45
+ );
23
46
 
24
47
  productCategories.forEach(({ minSubItems, maxSubItems, id, name }) => {
25
48
  if (!minSubItems && !maxSubItems) return;
@@ -47,6 +70,16 @@ export const useCategoryVerification = () => {
47
70
  }
48
71
  });
49
72
 
73
+ if (totalPrice < sumOfMinSpends && !errorMessage) {
74
+ const message = t("Design:minimumSpendSumValidation", {
75
+ minSpend: formatNumber(sumOfMinSpends, {
76
+ style: "currency",
77
+ currency: Currency.GBP,
78
+ }),
79
+ }) as string;
80
+ errorMessage = { message };
81
+ }
82
+
50
83
  return errorMessage;
51
84
  };
52
85
  };