@licklist/design 0.44.485-dev.70 → 0.44.485-dev.71
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/index.d.ts +1 -1
- package/dist/iframe/index.d.ts.map +1 -1
- package/dist/iframe/order-process/components/CalendarStepsForm/CalendarStepsForm.d.ts.map +1 -1
- package/dist/iframe/order-process/components/CalendarStepsForm/CalendarStepsForm.js +1 -1
- package/dist/iframe/order-process/components/Category/Category.d.ts +3 -3
- package/dist/iframe/order-process/components/Category/Category.d.ts.map +1 -1
- package/dist/iframe/order-process/components/CategoryProduct/CategoryProduct.d.ts +3 -3
- package/dist/iframe/order-process/components/CategoryProduct/CategoryProduct.d.ts.map +1 -1
- package/dist/iframe/order-process/components/ErrorModal/ErrorModal.d.ts.map +1 -0
- package/dist/iframe/order-process/components/ErrorModal/ErrorModal.js +1 -0
- package/dist/iframe/order-process/components/ErrorModal/index.d.ts +2 -0
- package/dist/iframe/order-process/components/ErrorModal/index.d.ts.map +1 -0
- package/dist/iframe/order-process/components/utils/useCategoryVerification.d.ts +8 -0
- package/dist/iframe/order-process/components/utils/useCategoryVerification.d.ts.map +1 -0
- package/dist/iframe/order-process/components/utils/useCategoryVerification.js +1 -0
- package/dist/iframe/order-process/index.d.ts +3 -1
- package/dist/iframe/order-process/index.d.ts.map +1 -1
- package/dist/iframe/payment/payment-page/PaymentPage.js +1 -1
- package/dist/iframe/payment/payment-page/PaymentTimer.js +1 -1
- package/dist/iframe/payment/payment-status-page/PaymentStatusPage.js +1 -1
- package/dist/index.js +1 -1
- package/dist/product-set/product-category/ProductCategoryControl.js +1 -1
- package/dist/sales/manual-booking/controll/ManualBookingStepsControll.js +1 -1
- package/dist/snippet/snippet-template/preview/Preview.js +1 -1
- package/dist/types/iframe.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/iframe/index.ts +3 -1
- package/src/iframe/order-process/components/CalendarStepsForm/CalendarStepsForm.tsx +4 -3
- package/src/iframe/order-process/components/Category/Category.tsx +3 -3
- package/src/iframe/order-process/components/CategoryProduct/CategoryProduct.tsx +3 -3
- package/src/iframe/order-process/components/{CalendarStepsForm/components → ErrorModal}/ErrorModal.tsx +1 -1
- package/src/iframe/order-process/components/ErrorModal/index.ts +1 -0
- package/src/iframe/order-process/components/utils/{category.ts → useCategoryVerification.ts} +15 -10
- package/src/iframe/order-process/index.ts +3 -1
- package/src/product-set/product-category/ProductCategoryControl.tsx +1 -1
- package/src/sales/manual-booking/controll/ManualBookingStepsControll.tsx +1 -1
- package/src/types/iframe.ts +2 -0
- package/dist/iframe/order-process/components/CalendarStepsForm/components/ErrorModal.d.ts.map +0 -1
- package/dist/iframe/order-process/components/CalendarStepsForm/components/ErrorModal.js +0 -1
- package/dist/iframe/order-process/components/StepsForm/StepsForm.d.ts +0 -19
- package/dist/iframe/order-process/components/StepsForm/StepsForm.d.ts.map +0 -1
- package/dist/iframe/order-process/components/StepsForm/StepsForm.js +0 -1
- package/dist/iframe/order-process/components/StepsForm/index.d.ts +0 -2
- package/dist/iframe/order-process/components/StepsForm/index.d.ts.map +0 -1
- package/dist/iframe/order-process/components/utils/category.d.ts +0 -10
- package/dist/iframe/order-process/components/utils/category.d.ts.map +0 -1
- package/dist/iframe/order-process/components/utils/category.js +0 -1
- package/src/iframe/order-process/OrderProcess.stories.tsx +0 -363
- package/src/iframe/order-process/components/StepsForm/StepsForm.tsx +0 -176
- package/src/iframe/order-process/components/StepsForm/index.ts +0 -1
- /package/dist/iframe/order-process/components/{CalendarStepsForm/components → ErrorModal}/ErrorModal.d.ts +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
import { DeepMap, FieldError } from "react-hook-form";
|
|
4
|
+
import { ProductQuantityCheckResponse } from "@licklist/plugins/dist/types/Api/verifyStock";
|
|
4
5
|
import { ProductCategory } from "../../../../types";
|
|
5
6
|
import { CategoryProduct } from "../CategoryProduct";
|
|
6
|
-
import { StepsFormProps } from "../StepsForm/StepsForm";
|
|
7
7
|
|
|
8
8
|
interface CategoryProps {
|
|
9
9
|
productCategories: ProductCategory[];
|
|
10
|
-
productsWithErrors?:
|
|
11
|
-
soldOutProducts?:
|
|
10
|
+
productsWithErrors?: ProductQuantityCheckResponse["products"];
|
|
11
|
+
soldOutProducts?: ProductQuantityCheckResponse["products"];
|
|
12
12
|
errors?: DeepMap<Record<string, any>, FieldError>;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -5,17 +5,17 @@ import { useTranslation } from "react-i18next";
|
|
|
5
5
|
import { useIntl } from "react-intl";
|
|
6
6
|
import * as Config from "@licklist/core/dist/Config";
|
|
7
7
|
import HookFormService from "@licklist/plugins/dist/services/Form/HookFormService";
|
|
8
|
+
import { ProductQuantityCheckResponse } from "@licklist/plugins/dist/types/Api/verifyStock";
|
|
8
9
|
import { TicketDescription } from "../../../event/ticket-description";
|
|
9
10
|
import { ProductCategory, Product } from "../../../../types";
|
|
10
|
-
import { StepsFormProps } from "../StepsForm/StepsForm";
|
|
11
11
|
import { ProductQuantityInput } from "./components/ProductQuantityInput";
|
|
12
12
|
|
|
13
13
|
interface CategoryProductProps {
|
|
14
14
|
product: Product;
|
|
15
15
|
category: ProductCategory;
|
|
16
16
|
canExpandDescription?: boolean;
|
|
17
|
-
productsWithErrors?:
|
|
18
|
-
soldOutProducts?:
|
|
17
|
+
productsWithErrors?: ProductQuantityCheckResponse["products"];
|
|
18
|
+
soldOutProducts?: ProductQuantityCheckResponse["products"];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const CategoryProduct = ({
|
|
@@ -5,7 +5,7 @@ import ModalHeader from "react-bootstrap/ModalHeader";
|
|
|
5
5
|
import ModalTitle from "react-bootstrap/ModalTitle";
|
|
6
6
|
import ModalBody from "react-bootstrap/ModalBody";
|
|
7
7
|
import Modal from "react-bootstrap/Modal";
|
|
8
|
-
import Icon from "
|
|
8
|
+
import Icon from "../../../../static/Icon";
|
|
9
9
|
|
|
10
10
|
export interface ErrorModalProps {
|
|
11
11
|
isOpen: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ErrorModal } from "./ErrorModal";
|
package/src/iframe/order-process/components/utils/{category.ts → useCategoryVerification.ts}
RENAMED
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
import { useTranslation } from "react-i18next";
|
|
2
|
-
import { MenuStep } from "
|
|
2
|
+
import { MenuStep, Order } from "src/types";
|
|
3
3
|
|
|
4
4
|
interface CategoryError {
|
|
5
5
|
message: string;
|
|
6
6
|
id: number;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
// TODO it's temporary solution, please remove it later
|
|
10
|
+
export const useCategoryVerification = () => {
|
|
9
11
|
const { t } = useTranslation("Validation");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
values: Record<Order["id"], Order>,
|
|
12
15
|
step: MenuStep
|
|
13
16
|
): CategoryError | void => {
|
|
14
17
|
let errorMessage;
|
|
18
|
+
|
|
15
19
|
const productArray = Object.values(values).filter(
|
|
16
20
|
(product) => product?.quantity > 0
|
|
17
21
|
);
|
|
22
|
+
|
|
18
23
|
step?.productCategories.forEach(
|
|
19
24
|
({ minSubItems, maxSubItems, id, name }) => {
|
|
20
|
-
if (!minSubItems && !maxSubItems)
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
25
|
+
if (!minSubItems && !maxSubItems) return;
|
|
23
26
|
|
|
24
27
|
const categoryProductsQuantity = productArray.filter(
|
|
25
|
-
(product) =>
|
|
28
|
+
(product) => product?.productsCategoryId === id
|
|
26
29
|
).length;
|
|
27
|
-
|
|
30
|
+
|
|
31
|
+
if (minSubItems && categoryProductsQuantity < minSubItems) {
|
|
28
32
|
const message = t("Validation:fieldMinNumber", {
|
|
29
33
|
min: minSubItems,
|
|
30
34
|
attribute: `number of products in the ${name} category`,
|
|
@@ -33,6 +37,7 @@ export const useCategory = () => {
|
|
|
33
37
|
|
|
34
38
|
return;
|
|
35
39
|
}
|
|
40
|
+
|
|
36
41
|
if (maxSubItems && categoryProductsQuantity > maxSubItems) {
|
|
37
42
|
const message = t("Validation:fieldMaxNumber", {
|
|
38
43
|
max: maxSubItems,
|
|
@@ -42,7 +47,7 @@ export const useCategory = () => {
|
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
);
|
|
50
|
+
|
|
45
51
|
return errorMessage;
|
|
46
52
|
};
|
|
47
|
-
return { verifyCategoryItems };
|
|
48
53
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { BookingSummary } from "./components/BookingSummary";
|
|
2
2
|
export { NavigationSteps } from "./components/NavigationSteps";
|
|
3
|
-
export { StepsForm } from "./components/StepsForm";
|
|
4
3
|
export { Timer } from "./components/Timer";
|
|
5
4
|
export { NavigationFooter } from "./components/NavigationFooter";
|
|
6
5
|
export { PaymentCard } from "./components/PaymentCard";
|
|
@@ -8,3 +7,6 @@ export { BookingSummaryFooter } from "./components/BookingSummaryFooter";
|
|
|
8
7
|
export type { BookingSummaryFooterProps } from "./components/BookingSummaryFooter";
|
|
9
8
|
export { CalendarStepsForm } from "./components/CalendarStepsForm";
|
|
10
9
|
export type { CalendarStepsFormProps } from "./components/CalendarStepsForm";
|
|
10
|
+
export { useCategoryVerification } from "./components/utils/useCategoryVerification";
|
|
11
|
+
export { Category } from "./components/Category";
|
|
12
|
+
export { ErrorModal } from "./components/ErrorModal";
|
|
@@ -105,7 +105,7 @@ export function ProductCategoryControl({
|
|
|
105
105
|
|
|
106
106
|
const allowDepositsId = useId();
|
|
107
107
|
const remainderExpireAfterId = useId();
|
|
108
|
-
const { providerHasBookingManagement, zones } = useContext(
|
|
108
|
+
const { providerHasBookingManagement, zones = [] } = useContext(
|
|
109
109
|
ProductSetLoadingContext
|
|
110
110
|
);
|
|
111
111
|
|
|
@@ -4,7 +4,7 @@ import { useFormContext } from "react-hook-form";
|
|
|
4
4
|
import { useTranslation } from "react-i18next";
|
|
5
5
|
import { ProductQuantityCheckResponse } from "@licklist/plugins/dist/types/Api/verifyStock";
|
|
6
6
|
import { OrderProduct } from "@licklist/core/dist/DataMapper/Order/OrderProductDataMapper";
|
|
7
|
-
import { ErrorModal } from "../../../iframe/order-process/components/
|
|
7
|
+
import { ErrorModal } from "../../../iframe/order-process/components/ErrorModal/ErrorModal";
|
|
8
8
|
import { MenuStep } from "../../../types";
|
|
9
9
|
import { CollapsibleInputGroup } from "../../../collapsible-input-group";
|
|
10
10
|
import { CategoryProducts } from "../category-products/CategoryProducts";
|
package/src/types/iframe.ts
CHANGED
package/dist/iframe/order-process/components/CalendarStepsForm/components/ErrorModal.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorModal.d.ts","sourceRoot":"","sources":["../../../../../../src/iframe/order-process/components/CalendarStepsForm/components/ErrorModal.tsx"],"names":[],"mappings":";AASA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,UAAU,qCAIpB,eAAe,gBA2CjB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),r=require("react-i18next"),a=require("react-bootstrap"),o=require("../../../../../static/Icon.js"),n=e(require("react-bootstrap/ModalHeader")),s=e(require("react-bootstrap/ModalTitle")),i=e(require("react-bootstrap/ModalBody")),c=e(require("react-bootstrap/Modal"));exports.ErrorModal=function(e){var l=e.isOpen,m=void 0!==l&&l,u=e.onClose,d=e.messageKey,f=r.useTranslation("Design").t,p=function(){u&&u()};return t.createElement(c,{show:m,onHide:p,animation:!1,centered:!0,contentClassName:"rounded"},t.createElement(n,{className:"align-items-center border-0"},t.createElement(s,{as:"h6"},f("formHasErrors")),t.createElement(a.Button,{variant:"danger",className:"btn-sm rounded",onClick:p},t.createElement(o.default,{type:"times",height:"1rem"}))),t.createElement(i,{className:"confirmation-modal-body"},t.createElement("div",{className:"d-flex m-5 justify-content-center manual-form-error"},d?f(d):t.createElement(r.Trans,{t:f,i18nKey:"pleaseSelectAtLeastFrom",values:{min:1,type:"item",from:"those categories"}}))))};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { ProductQuantityCheckResponse } from "@licklist/plugins/dist/types/Api/verifyStock";
|
|
3
|
-
import { MenuStep } from "../../../../types";
|
|
4
|
-
export interface StepsFormProps {
|
|
5
|
-
step: MenuStep;
|
|
6
|
-
isLastMenuStep: boolean;
|
|
7
|
-
onSubmit: (values: Record<string, any>) => void;
|
|
8
|
-
setFormValues: (values: Record<string, any>) => void;
|
|
9
|
-
defaultValues: Record<string, any>;
|
|
10
|
-
setFormErrors?: (errors: Record<string, any>) => void;
|
|
11
|
-
id?: string;
|
|
12
|
-
productsWithErrors?: ProductQuantityCheckResponse["products"];
|
|
13
|
-
soldOutProducts?: ProductQuantityCheckResponse["products"];
|
|
14
|
-
}
|
|
15
|
-
export type StepsFormRef = {
|
|
16
|
-
getFormValues: () => Record<string, any>;
|
|
17
|
-
};
|
|
18
|
-
export declare const StepsForm: React.ForwardRefExoticComponent<StepsFormProps & React.RefAttributes<StepsFormRef>>;
|
|
19
|
-
//# sourceMappingURL=StepsForm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"StepsForm.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/order-process/components/StepsForm/StepsForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAKN,MAAM,OAAO,CAAC;AAWf,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAE5F,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAO7C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IAChD,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IACrD,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IACtD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,kBAAkB,CAAC,EAAE,4BAA4B,CAAC,UAAU,CAAC,CAAC;IAC9D,eAAe,CAAC,EAAE,4BAA4B,CAAC,UAAU,CAAC,CAAC;CAC5D;AAED,MAAM,MAAM,YAAY,GAAG;IACzB,aAAa,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC1C,CAAC;AAEF,eAAO,MAAM,SAAS,qFAsIrB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("tslib"),t=require("react"),s=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,o=require("react-i18next"),u=require("react-bootstrap"),i=require("react-hook-form"),a=require("lodash"),l=require("@licklist/plugins/dist/hooks/Value/usePreviousValue"),n=require("@licklist/plugins/dist/utils/ScrollUtils"),c=require("@licklist/plugins/dist/utils/FormValues"),d=require("../Category/Category.js"),m=require("../../constants.js"),f=require("../CalendarStepsForm/components/ErrorModal.js"),E=require("../utils/category.js"),p="NO_ORDER_ITEMS_ERROR",g=t.forwardRef((function(e,g){var v=e.step,y=e.isLastMenuStep,q=e.setFormValues,F=e.defaultValues,S=e.onSubmit,V=e.setFormErrors,_=e.id,C=void 0===_?m.STEP_FORM_ID:_,h=e.productsWithErrors,O=e.soldOutProducts,P=i.useForm({defaultValues:F}),b=o.useTranslation(["Design","Validation"]).t,j=r.__read(t.useState(""),2),R=j[0],T=j[1],k=E.useCategory().verifyCategoryItems,M=P.control,x=P.formState.errors,I=P.getValues,D=P.setError,K=P.clearErrors,N=P.reset,W=i.useWatch({control:M}),L=l.usePreviousValue(x);t.useImperativeHandle(g,(function(){return{getFormValues:function(){return I()}}})),t.useEffect((function(){h&&T(b("soldOutProduct"))}),[h]);return t.useEffect((function(){x&&setTimeout(K,0),q(W)}),[W]),t.useEffect((function(){c.isFormValuesEmpty(W)||K(p)}),[W,K]),t.useEffect((function(){N(F)}),[F]),t.useEffect((function(){!a.isEqual(x,L)&&V&&V(x)}),[x,L,V]),s.createElement(u.Form,{onSubmit:P.handleSubmit((function(e){if(y&&c.isFormValuesEmpty(e))return D(p,{}),void n.scrollToError(p);var r=k(e,v);if(r)return T(r.message),void D("category_".concat(r.id),{message:r.message});S(e)}),(function(e){n.scrollToError(c.getFirstErrorKey(e)),T(b("pleaseCheckSelectedProducts"))})),id:C},s.createElement(i.FormProvider,r.__assign({},P),s.createElement(f.ErrorModal,{isOpen:Boolean(R),messageKey:R,onClose:function(){return T("")}}),s.createElement("div",null,s.createElement("div",{className:"iframe-event"},s.createElement(d.Category,{productCategories:null==v?void 0:v.productCategories,productsWithErrors:h,errors:x,soldOutProducts:O}),x[p]&&s.createElement("div",{className:"d-flex m-5 justify-content-center form-error",id:p},s.createElement(o.Trans,{t:b,i18nKey:"pleaseSelectAtLeastFrom",values:{min:1,type:"item",from:"those categories"}}))))))}));exports.StepsForm=g;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/order-process/components/StepsForm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { MenuStep } from "../../../../types";
|
|
2
|
-
interface CategoryError {
|
|
3
|
-
message: string;
|
|
4
|
-
id: number;
|
|
5
|
-
}
|
|
6
|
-
export declare const useCategory: () => {
|
|
7
|
-
verifyCategoryItems: (values: Record<string, any>, step: MenuStep) => CategoryError | void;
|
|
8
|
-
};
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=category.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"category.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/order-process/components/utils/category.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,UAAU,aAAa;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AACD,eAAO,MAAM,WAAW;kCAGZ,OAAO,MAAM,EAAE,GAAG,CAAC,QACrB,QAAQ,KACb,aAAa,GAAG,IAAI;CAmCxB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react-i18next");exports.useCategory=function(){var t=e.useTranslation("Validation").t;return{verifyCategoryItems:function(e,r){var i,n=Object.values(e).filter((function(e){return(null==e?void 0:e.quantity)>0}));return null==r||r.productCategories.forEach((function(e){var r=e.minSubItems,a=e.maxSubItems,u=e.id,o=e.name;if(r||a){var s=n.filter((function(e){return Number(null==e?void 0:e.productsCategoryId)===Number(u)})).length;if(s<r){var c=t("Validation:fieldMinNumber",{min:r,attribute:"number of products in the ".concat(o," category")});i={id:u,message:c}}else if(a&&s>a){c=t("Validation:fieldMaxNumber",{max:a,attribute:"number of products in the ".concat(o," category")});i={id:u,message:c}}}})),i}}};
|
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useEffect,
|
|
3
|
-
useState,
|
|
4
|
-
useContext,
|
|
5
|
-
createContext,
|
|
6
|
-
useRef,
|
|
7
|
-
useMemo,
|
|
8
|
-
} from "react";
|
|
9
|
-
import { MemoryRouter, Route, useHistory } from "react-router-dom";
|
|
10
|
-
import { Meta } from "@storybook/react";
|
|
11
|
-
import { Timer } from "./components/Timer";
|
|
12
|
-
import { BookingSummary } from "./components/BookingSummary";
|
|
13
|
-
import { NavigationSteps } from "./components/NavigationSteps";
|
|
14
|
-
import { StepsForm } from "./components/StepsForm";
|
|
15
|
-
import { Page, PageBody, PageHeader } from "../page";
|
|
16
|
-
import { StepsFormRef } from "./components/StepsForm/StepsForm";
|
|
17
|
-
import { BookingSummaryFooter } from "./components/BookingSummaryFooter";
|
|
18
|
-
import { Order } from "../../types";
|
|
19
|
-
// eslint-disable-next-line max-len
|
|
20
|
-
import { RenderNumberOfPeopleInputComponent } from "../event/event-details/components/number-of-people-input/component/RenderNumberOfPeopleInputComponent";
|
|
21
|
-
|
|
22
|
-
const ROUTES = [
|
|
23
|
-
{ pathname: "/step1", key: "/step1", name: "Burger" },
|
|
24
|
-
{ pathname: "/step2", key: "/step2", name: "Cheese" },
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
const IMAGES = [
|
|
28
|
-
{
|
|
29
|
-
id: 1,
|
|
30
|
-
path: "test",
|
|
31
|
-
imageType: "image",
|
|
32
|
-
url: "https://fastly.picsum.photos/id/13/2500/1667.jpg?hmac=SoX9UoHhN8HyklRA4A3vcCWJMVtiBXUg0W4ljWTor7s",
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
const productCategories = [
|
|
37
|
-
{
|
|
38
|
-
id: 1,
|
|
39
|
-
name: "Early Bird General Admission",
|
|
40
|
-
allowDeposits: true,
|
|
41
|
-
minSubItems: 2,
|
|
42
|
-
products: [
|
|
43
|
-
{
|
|
44
|
-
id: 7,
|
|
45
|
-
name: "Beer",
|
|
46
|
-
description: `Ticket <em>is</em> valid for students and non students.
|
|
47
|
-
You do not need student ID for this event but do require regular age ID e.g. driving licence or passport.
|
|
48
|
-
Ticket valid for entry before 11.30pm for 12.30am showtime.`,
|
|
49
|
-
|
|
50
|
-
price: 5,
|
|
51
|
-
deposit: 3,
|
|
52
|
-
minSub: 10,
|
|
53
|
-
isRequired: true,
|
|
54
|
-
images: IMAGES,
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
id: 8,
|
|
58
|
-
name: "Wine",
|
|
59
|
-
description: `Ticket is valid for students and non students.
|
|
60
|
-
You do not need <strong>student ID</strong> for this event but do require regular age ID e.g. driving licence or passport.
|
|
61
|
-
Ticket valid for entry before 11.30pm for 12.30am showtime.`,
|
|
62
|
-
|
|
63
|
-
price: 1,
|
|
64
|
-
images: IMAGES,
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
id: 2,
|
|
70
|
-
name: "Nice",
|
|
71
|
-
maxSubItems: 1,
|
|
72
|
-
products: [
|
|
73
|
-
{
|
|
74
|
-
id: 3,
|
|
75
|
-
name: "Beer",
|
|
76
|
-
description: `Ticket is valid for students and non students.
|
|
77
|
-
You do not need student ID for this event but do require regular age ID e.g. driving licence or passport.
|
|
78
|
-
Ticket valid for entry before 11.30pm for 12.30am showtime.`,
|
|
79
|
-
|
|
80
|
-
price: 1,
|
|
81
|
-
images: IMAGES,
|
|
82
|
-
maxAmount: 1,
|
|
83
|
-
minAmount: 1,
|
|
84
|
-
isRequired: true,
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
id: 5,
|
|
88
|
-
name: "Wine",
|
|
89
|
-
description: `Ticket is valid for students and non students.
|
|
90
|
-
You do not need <strong>student ID</strong> for this event but do require regular age ID e.g. driving licence or passport.
|
|
91
|
-
Ticket valid for entry before 11.30pm for 12.30am showtime.`,
|
|
92
|
-
|
|
93
|
-
price: 1,
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
const productCategories2 = [
|
|
100
|
-
{
|
|
101
|
-
id: 3,
|
|
102
|
-
name: "fine",
|
|
103
|
-
products: [
|
|
104
|
-
{
|
|
105
|
-
id: 9,
|
|
106
|
-
name: "Beer",
|
|
107
|
-
description: `Ticket is valid for students and non students.
|
|
108
|
-
You do not need student ID for this event but do require regular age ID e.g. driving licence or passport.
|
|
109
|
-
Ticket valid for entry before 11.30pm for 12.30am showtime.`,
|
|
110
|
-
|
|
111
|
-
price: 1,
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
id: 10,
|
|
115
|
-
name: "Wine",
|
|
116
|
-
description: `Ticket is valid for students and non students.
|
|
117
|
-
You do not need student ID for this event but do require regular age ID e.g. driving licence or passport.
|
|
118
|
-
Ticket valid for entry before 11.30pm for 12.30am showtime.`,
|
|
119
|
-
|
|
120
|
-
price: 1,
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
id: 4,
|
|
126
|
-
name: "Twice",
|
|
127
|
-
products: [
|
|
128
|
-
{
|
|
129
|
-
id: 11,
|
|
130
|
-
name: "Beer",
|
|
131
|
-
description: `Ticket is valid for students and non students.
|
|
132
|
-
You do not need student ID for this event but do require regular age ID e.g. driving licence or passport.
|
|
133
|
-
Ticket valid for entry before 11.30pm for 12.30am showtime.`,
|
|
134
|
-
|
|
135
|
-
price: 1,
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
id: 12,
|
|
139
|
-
name: "Wine",
|
|
140
|
-
description: `Ticket is valid for students and non students.
|
|
141
|
-
You do not need student ID for this event but do require regular age ID e.g. driving licence or passport.
|
|
142
|
-
Ticket valid for entry before 11.30pm for 12.30am showtime.`,
|
|
143
|
-
|
|
144
|
-
price: 1,
|
|
145
|
-
},
|
|
146
|
-
],
|
|
147
|
-
},
|
|
148
|
-
];
|
|
149
|
-
|
|
150
|
-
const menuSteps = [
|
|
151
|
-
{
|
|
152
|
-
id: 1,
|
|
153
|
-
name: "Burger",
|
|
154
|
-
productCategories,
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
id: 2,
|
|
158
|
-
name: "Cheese",
|
|
159
|
-
productCategories: productCategories2,
|
|
160
|
-
},
|
|
161
|
-
];
|
|
162
|
-
|
|
163
|
-
const OrderProcessContext = createContext<{
|
|
164
|
-
orderFormValues: Record<string, any>;
|
|
165
|
-
setOrderFormValues: (values: Record<string, any>) => void;
|
|
166
|
-
formValues: Record<string, any>;
|
|
167
|
-
setFormValues: (values: Record<string, any>) => void;
|
|
168
|
-
}>({
|
|
169
|
-
orderFormValues: {},
|
|
170
|
-
setOrderFormValues: () => undefined,
|
|
171
|
-
formValues: {},
|
|
172
|
-
setFormValues: () => undefined,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const OrderProcessContextProvider: React.FC = ({ children }) => {
|
|
176
|
-
const [orderFormValues, setOrderFormValues] = useState<Record<string, any>>(
|
|
177
|
-
{}
|
|
178
|
-
);
|
|
179
|
-
const [formValues, setFormValues] = useState<Record<string, any>>({});
|
|
180
|
-
|
|
181
|
-
return (
|
|
182
|
-
<OrderProcessContext.Provider
|
|
183
|
-
value={{
|
|
184
|
-
orderFormValues,
|
|
185
|
-
setOrderFormValues,
|
|
186
|
-
formValues,
|
|
187
|
-
setFormValues,
|
|
188
|
-
}}
|
|
189
|
-
>
|
|
190
|
-
{children}
|
|
191
|
-
</OrderProcessContext.Provider>
|
|
192
|
-
);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export default {
|
|
196
|
-
title: "Iframe/Order-Process/OrderProcess",
|
|
197
|
-
component: Default,
|
|
198
|
-
} as Meta;
|
|
199
|
-
|
|
200
|
-
const TimerWrapper = () => {
|
|
201
|
-
const [timer, setTimer] = useState(120000);
|
|
202
|
-
const updateTimerState = () => {
|
|
203
|
-
setTimer((prevValue) => {
|
|
204
|
-
if (prevValue <= 0) {
|
|
205
|
-
return 0;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const nexValue = prevValue - 1000;
|
|
209
|
-
|
|
210
|
-
return nexValue;
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
useEffect(() => {
|
|
215
|
-
setInterval(updateTimerState, 1000);
|
|
216
|
-
}, []);
|
|
217
|
-
|
|
218
|
-
return <Timer timer={timer} />;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
export function Default() {
|
|
222
|
-
const externalHistory = useHistory();
|
|
223
|
-
const formRef = useRef<StepsFormRef | null>(null);
|
|
224
|
-
const [peopleAmount, setPeopleAmount] = useState(0);
|
|
225
|
-
const [peopleAmountError, setPeopleAmountError] = useState(false);
|
|
226
|
-
|
|
227
|
-
return (
|
|
228
|
-
<MemoryRouter initialEntries={ROUTES} initialIndex={0}>
|
|
229
|
-
<OrderProcessContextProvider>
|
|
230
|
-
{ROUTES.map(({ pathname }, index) => {
|
|
231
|
-
const step = menuSteps[index];
|
|
232
|
-
|
|
233
|
-
return (
|
|
234
|
-
<Route
|
|
235
|
-
path={pathname}
|
|
236
|
-
exact
|
|
237
|
-
key={pathname}
|
|
238
|
-
component={() => {
|
|
239
|
-
const history = useHistory();
|
|
240
|
-
const {
|
|
241
|
-
orderFormValues,
|
|
242
|
-
setOrderFormValues,
|
|
243
|
-
formValues,
|
|
244
|
-
setFormValues,
|
|
245
|
-
} = useContext(OrderProcessContext);
|
|
246
|
-
const relyOnPeopleCategoryIds = [4];
|
|
247
|
-
const onPrevStep = () => {
|
|
248
|
-
if (formRef.current?.getFormValues()) {
|
|
249
|
-
setFormValues(formRef.current?.getFormValues());
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (index === 0) {
|
|
253
|
-
// external History push
|
|
254
|
-
externalHistory.push("/");
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
history.push(ROUTES[index - 1].pathname);
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
const onNextStep = (values: Record<string, any>) => {
|
|
262
|
-
setOrderFormValues(values);
|
|
263
|
-
const nextRoute = ROUTES[index + 1];
|
|
264
|
-
if (nextRoute) {
|
|
265
|
-
history.push(ROUTES[index + 1].pathname);
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
const shouldShowPeopleInput = useMemo(() => {
|
|
270
|
-
const values = Object.values(formValues).filter(
|
|
271
|
-
Boolean
|
|
272
|
-
) as Order[];
|
|
273
|
-
const filteredValues = values.filter(
|
|
274
|
-
(product) =>
|
|
275
|
-
relyOnPeopleCategoryIds.includes(
|
|
276
|
-
product.productsCategoryId
|
|
277
|
-
) && product.quantity > 0
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
return Boolean(filteredValues.length);
|
|
281
|
-
}, [formValues, relyOnPeopleCategoryIds]);
|
|
282
|
-
const onChangePeopleAmount = (value: number) => {
|
|
283
|
-
if (!setPeopleAmount) {
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
setPeopleAmount(value);
|
|
287
|
-
if (value > 0) {
|
|
288
|
-
if (peopleAmountError) {
|
|
289
|
-
setPeopleAmountError(false);
|
|
290
|
-
}
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
setPeopleAmountError(true);
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
return (
|
|
298
|
-
<Page
|
|
299
|
-
headerBlock={
|
|
300
|
-
<PageHeader
|
|
301
|
-
showCloseButton
|
|
302
|
-
onCloseButtonClick={onPrevStep}
|
|
303
|
-
showBackButton
|
|
304
|
-
onBackButtonClick={onPrevStep}
|
|
305
|
-
>
|
|
306
|
-
<TimerWrapper />
|
|
307
|
-
<NavigationSteps steps={ROUTES} />
|
|
308
|
-
</PageHeader>
|
|
309
|
-
}
|
|
310
|
-
>
|
|
311
|
-
<PageBody
|
|
312
|
-
leftBlock={
|
|
313
|
-
<PageBody.LeftBlock title={step.name}>
|
|
314
|
-
<StepsForm
|
|
315
|
-
isLastMenuStep={!ROUTES[index + 1]}
|
|
316
|
-
step={step as any}
|
|
317
|
-
setFormValues={setFormValues}
|
|
318
|
-
defaultValues={orderFormValues}
|
|
319
|
-
onSubmit={onNextStep}
|
|
320
|
-
ref={formRef}
|
|
321
|
-
/>
|
|
322
|
-
</PageBody.LeftBlock>
|
|
323
|
-
}
|
|
324
|
-
rightBlock={
|
|
325
|
-
<PageBody.RightBlock
|
|
326
|
-
bottomBlock={
|
|
327
|
-
<BookingSummaryFooter>
|
|
328
|
-
{shouldShowPeopleInput && (
|
|
329
|
-
<RenderNumberOfPeopleInputComponent
|
|
330
|
-
peopleAmount={peopleAmount || 0}
|
|
331
|
-
onChangePeopleAmount={onChangePeopleAmount}
|
|
332
|
-
peopleAmountError={peopleAmountError}
|
|
333
|
-
/>
|
|
334
|
-
)}
|
|
335
|
-
<BookingSummary.SummaryTotal
|
|
336
|
-
formValues={formValues}
|
|
337
|
-
totalWithDiscount={5}
|
|
338
|
-
/>
|
|
339
|
-
</BookingSummaryFooter>
|
|
340
|
-
}
|
|
341
|
-
>
|
|
342
|
-
<BookingSummary
|
|
343
|
-
hasPeopleInput={shouldShowPeopleInput}
|
|
344
|
-
date="29 Sept 2022 at 09:00"
|
|
345
|
-
menuSteps={menuSteps as any}
|
|
346
|
-
formValues={formValues}
|
|
347
|
-
peopleAmount={peopleAmount}
|
|
348
|
-
totalWithDiscount={5}
|
|
349
|
-
eventName="Glam!"
|
|
350
|
-
/>
|
|
351
|
-
</PageBody.RightBlock>
|
|
352
|
-
}
|
|
353
|
-
/>
|
|
354
|
-
</Page>
|
|
355
|
-
);
|
|
356
|
-
}}
|
|
357
|
-
/>
|
|
358
|
-
);
|
|
359
|
-
})}
|
|
360
|
-
</OrderProcessContextProvider>
|
|
361
|
-
</MemoryRouter>
|
|
362
|
-
);
|
|
363
|
-
}
|