@licklist/design 0.71.18-dev.1 → 0.71.18-dev.11
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/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.js +1 -0
- package/dist/events/event-statistic-modal/utils/index.js +3 -3
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetForm.d.ts +18 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetForm.d.ts.map +1 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetForm.js +295 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetModal.d.ts +15 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetModal.d.ts.map +1 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetModal.js +89 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ModifierSetControll.d.ts +14 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ModifierSetControll.d.ts.map +1 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ModifierSetControll.js +404 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ProductControll.d.ts +10 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ProductControll.d.ts.map +1 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ProductControll.js +87 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/index.d.ts +2 -0
- package/dist/iframe/ProductWithModifierModal/ModifierSetModal/index.d.ts.map +1 -0
- package/dist/iframe/ProductWithModifierModal/index.d.ts +2 -0
- package/dist/iframe/ProductWithModifierModal/index.d.ts.map +1 -0
- package/dist/iframe/ProductWithModifierModal/utils.d.ts +5 -0
- package/dist/iframe/ProductWithModifierModal/utils.d.ts.map +1 -0
- package/dist/iframe/ProductWithModifierModal/utils.js +21 -0
- package/dist/iframe/activity-card/ActivityCard.d.ts +1 -2
- package/dist/iframe/activity-card/ActivityCard.d.ts.map +1 -1
- package/dist/iframe/activity-card/ActivityCard.js +1 -7
- package/dist/iframe/event/ticket-description/TicketDescription.d.ts +2 -1
- package/dist/iframe/event/ticket-description/TicketDescription.d.ts.map +1 -1
- package/dist/iframe/event/ticket-description/TicketDescription.js +4 -3
- package/dist/iframe/order-process/components/BookingSummary/BookingSummary.d.ts +1 -1
- package/dist/iframe/order-process/components/BookingSummary/BookingSummary.d.ts.map +1 -1
- package/dist/iframe/order-process/components/BookingSummary/BookingSummary.js +2 -1
- package/dist/iframe/order-process/components/BookingSummary/components/ProductSummary/ProductSummary.d.ts.map +1 -1
- package/dist/iframe/order-process/components/BookingSummary/components/ProductSummary/ProductSummary.js +15 -2
- package/dist/iframe/order-process/components/BookingSummary/types/index.d.ts +1 -0
- package/dist/iframe/order-process/components/BookingSummary/types/index.d.ts.map +1 -1
- package/dist/iframe/order-process/components/BookingSummary/utils/index.d.ts +4 -0
- package/dist/iframe/order-process/components/BookingSummary/utils/index.d.ts.map +1 -1
- package/dist/iframe/order-process/components/BookingSummary/utils/index.js +29 -2
- package/dist/iframe/order-process/components/CategoryProduct/CategoryProduct.d.ts.map +1 -1
- package/dist/iframe/order-process/components/CategoryProduct/CategoryProduct.js +106 -2
- package/dist/iframe/order-process/components/CategoryProduct/components/ProductQuantityInput/ProductQuantityInput.d.ts +3 -1
- package/dist/iframe/order-process/components/CategoryProduct/components/ProductQuantityInput/ProductQuantityInput.d.ts.map +1 -1
- package/dist/iframe/order-process/components/CategoryProduct/components/ProductQuantityInput/ProductQuantityInput.js +95 -1
- package/dist/iframe/order-process/components/CategoryProduct/components/ProductWithModifier/ProductWithModifier.d.ts +23 -0
- package/dist/iframe/order-process/components/CategoryProduct/components/ProductWithModifier/ProductWithModifier.d.ts.map +1 -0
- package/dist/iframe/order-process/components/CategoryProduct/components/ProductWithModifier/ProductWithModifier.js +62 -0
- package/dist/iframe/order-process/components/CategoryProduct/constants.d.ts +2 -0
- package/dist/iframe/order-process/components/CategoryProduct/constants.d.ts.map +1 -0
- package/dist/iframe/order-process/components/CategoryProduct/constants.js +4 -0
- package/dist/iframe/order-process/components/utils/useOnWindowUnmount.d.ts +6 -0
- package/dist/iframe/order-process/components/utils/useOnWindowUnmount.d.ts.map +1 -0
- package/dist/iframe/order-process/components/utils/useOnWindowUnmount.js +18 -0
- package/dist/iframe/payment/order-items-table/hooks/useTableData.d.ts.map +1 -1
- package/dist/iframe/payment/order-items-table/hooks/useTableData.js +83 -10
- package/dist/iframe/payment/order-items-table/utils/index.d.ts.map +1 -1
- package/dist/iframe/payment/order-items-table/utils/index.js +15 -0
- package/dist/iframe/payment/order-items-table/utils/paymentSummary.js +2 -2
- package/dist/iframe/payment/payment-page/PaymentPage.d.ts.map +1 -1
- package/dist/iframe/payment/payment-page/PaymentPage.js +4 -1
- package/dist/index.js +1 -1
- package/dist/product-set/form/ProductSetForm.d.ts +3 -1
- package/dist/product-set/form/ProductSetForm.d.ts.map +1 -1
- package/dist/product-set/form/ProductSetForm.js +6 -4
- package/dist/product-set/form/ProductsControl.d.ts.map +1 -1
- package/dist/product-set/form/ProductsControl.js +24 -5
- package/dist/product-set/form/context.d.ts +3 -1
- package/dist/product-set/form/context.d.ts.map +1 -1
- package/dist/product-set/form/context.js +2 -1
- package/dist/product-set/product/ProductControl.d.ts +8 -0
- package/dist/product-set/product/ProductControl.d.ts.map +1 -1
- package/dist/product-set/product/ProductControl.js +25 -1
- package/dist/product-set/utils/index.d.ts +88 -0
- package/dist/product-set/utils/index.d.ts.map +1 -1
- package/dist/product-set/utils/index.js +19 -1
- package/dist/report/ReportRunnerModal/ReportRunnerModal.d.ts +1 -1
- package/dist/report/ReportRunnerModal/ReportRunnerModal.d.ts.map +1 -1
- package/dist/sales/coupon/utils/index.d.ts +2 -1
- package/dist/sales/coupon/utils/index.d.ts.map +1 -1
- package/dist/sales/modals/refund-modal/RefundModal.d.ts +6 -2
- package/dist/sales/modals/refund-modal/RefundModal.d.ts.map +1 -1
- package/dist/sales/modals/refund-modal/RefundModal.js +8 -4
- package/dist/sales/modals/refund-modal/index.d.ts +2 -2
- package/dist/sales/modals/refund-modal/index.d.ts.map +1 -1
- package/dist/styles/date-time-button/DateTimeButton.scss +8 -1
- package/dist/styles/events/EditEventModal.scss +2 -0
- package/dist/styles/iframe-page/Page.scss +16 -0
- package/dist/styles/iframe-page/PageBody.scss +4 -0
- package/dist/styles/modals/Modals.scss +16 -0
- package/dist/styles/product-set/EditProductSetElement.scss +1 -0
- package/dist/styles/product-set/ProductSetForm.scss +11 -0
- package/dist/styles/sales/ManualBooking.scss +6 -0
- package/dist/styles/themes/bookedit/index.scss +19 -0
- package/package.json +6 -6
- package/src/events/event-statistic-modal/utils/index.ts +4 -4
- package/src/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetForm.tsx +212 -0
- package/src/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetModal.tsx +75 -0
- package/src/iframe/ProductWithModifierModal/ModifierSetModal/controll/ModifierSetControll.tsx +393 -0
- package/src/iframe/ProductWithModifierModal/ModifierSetModal/controll/ProductControll.tsx +98 -0
- package/src/iframe/ProductWithModifierModal/ModifierSetModal/index.ts +1 -0
- package/src/iframe/ProductWithModifierModal/index.ts +1 -0
- package/src/iframe/ProductWithModifierModal/utils.ts +29 -0
- package/src/iframe/activity-card/ActivityCard.stories.tsx +0 -2
- package/src/iframe/activity-card/ActivityCard.tsx +0 -4
- package/src/iframe/event/ticket-description/TicketDescription.tsx +5 -3
- package/src/iframe/order-process/components/BookingSummary/BookingSummary.tsx +2 -0
- package/src/iframe/order-process/components/BookingSummary/components/ProductSummary/ProductSummary.tsx +21 -1
- package/src/iframe/order-process/components/BookingSummary/types/index.ts +1 -0
- package/src/iframe/order-process/components/BookingSummary/utils/index.ts +42 -1
- package/src/iframe/order-process/components/CategoryProduct/CategoryProduct.tsx +155 -75
- package/src/iframe/order-process/components/CategoryProduct/components/ProductQuantityInput/ProductQuantityInput.tsx +58 -1
- package/src/iframe/order-process/components/CategoryProduct/components/ProductWithModifier/ProductWithModifier.tsx +86 -0
- package/src/iframe/order-process/components/CategoryProduct/constants.ts +1 -0
- package/src/iframe/order-process/components/utils/useOnWindowUnmount.ts +25 -0
- package/src/iframe/payment/order-items-table/hooks/useTableData.tsx +84 -14
- package/src/iframe/payment/order-items-table/utils/index.ts +23 -0
- package/src/iframe/payment/order-items-table/utils/paymentSummary.tsx +2 -2
- package/src/iframe/payment/payment-page/PaymentPage.tsx +8 -10
- package/src/product-set/form/ProductSetForm.tsx +11 -3
- package/src/product-set/form/ProductsControl.tsx +33 -15
- package/src/product-set/form/context.tsx +5 -0
- package/src/product-set/product/ProductControl.tsx +37 -1
- package/src/product-set/utils/index.ts +19 -0
- package/src/report/ReportRunnerModal/ReportRunnerModal.tsx +2 -2
- package/src/sales/coupon/utils/index.ts +5 -3
- package/src/sales/modals/refund-modal/RefundModal.tsx +15 -6
- package/src/sales/modals/refund-modal/index.ts +7 -2
- package/src/styles/date-time-button/DateTimeButton.scss +8 -1
- package/src/styles/events/EditEventModal.scss +2 -0
- package/src/styles/iframe-page/Page.scss +16 -0
- package/src/styles/iframe-page/PageBody.scss +4 -0
- package/src/styles/modals/Modals.scss +16 -0
- package/src/styles/product-set/EditProductSetElement.scss +1 -0
- package/src/styles/product-set/ProductSetForm.scss +11 -0
- package/src/styles/sales/ManualBooking.scss +6 -0
- package/src/styles/themes/bookedit/index.scss +19 -0
- package/yarn.lock +334 -333
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { Controller, FormProvider, useForm } from 'react-hook-form'
|
|
3
|
+
import { Button, Form } from 'react-bootstrap'
|
|
4
|
+
import { isEmpty, uniqBy } from 'lodash'
|
|
5
|
+
import { useTranslation } from 'react-i18next'
|
|
6
|
+
import { useIntl } from 'react-intl'
|
|
7
|
+
import { Currency } from '@licklist/core/dist/Config'
|
|
8
|
+
import { MenuStep } from '@licklist/plugins/dist/types/context/sale/menuSteps'
|
|
9
|
+
import { OrderModifierByProduct } from '@licklist/core/dist/DataMapper/Order/OrderModifiierByProduct'
|
|
10
|
+
import { Product } from '@licklist/plugins/dist/types/context/sale/menuSteps'
|
|
11
|
+
import { OrderModifier } from '@licklist/core/dist/DataMapper/Order/OrderModifierDataMapper'
|
|
12
|
+
import { NumberInputHorizontal } from 'src/sales'
|
|
13
|
+
import clsx from 'clsx'
|
|
14
|
+
import { ProductCategory } from 'dist/product-set/types'
|
|
15
|
+
import { MAX_PRODUCT_NUMBER } from '../../order-process/components/CategoryProduct/constants'
|
|
16
|
+
import { FormOrderItem } from '../../order-process/components/CategoryProduct/components/ProductQuantityInput/ProductQuantityInput'
|
|
17
|
+
import { getOrderProductModifiersPrice } from '../../order-process/components/BookingSummary/utils'
|
|
18
|
+
import { ProductControl } from './controll/ProductControll'
|
|
19
|
+
|
|
20
|
+
export interface ManualBookingFormValues {
|
|
21
|
+
steps: MenuStep[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface ProductWithModifierSetFormProps {
|
|
25
|
+
onHide: () => void
|
|
26
|
+
product: Product
|
|
27
|
+
category: ProductCategory
|
|
28
|
+
editOrderModifier?: OrderModifierByProduct
|
|
29
|
+
onChange: (product: FormOrderItem) => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const filteredOrderModifierSets = (
|
|
33
|
+
modifiersSet: OrderModifier[],
|
|
34
|
+
): OrderModifier[] => {
|
|
35
|
+
if (!modifiersSet) return []
|
|
36
|
+
const orderModifier = modifiersSet
|
|
37
|
+
?.flat()
|
|
38
|
+
.filter((modifier) => !!modifier?.quantity)
|
|
39
|
+
|
|
40
|
+
const filteredOrderModifier = uniqBy(
|
|
41
|
+
orderModifier,
|
|
42
|
+
(item) => `${item.modifierId}-${item.modifierSetId}`,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return filteredOrderModifier || []
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const ProductWithModifierSetForm = ({
|
|
49
|
+
product,
|
|
50
|
+
category,
|
|
51
|
+
editOrderModifier,
|
|
52
|
+
onChange,
|
|
53
|
+
}: ProductWithModifierSetFormProps) => {
|
|
54
|
+
const form = useForm({ mode: 'onChange' })
|
|
55
|
+
const { t } = useTranslation(['App', 'Sale', 'Validation'])
|
|
56
|
+
|
|
57
|
+
const {
|
|
58
|
+
formState: { errors, isSubmitting, isValid },
|
|
59
|
+
control,
|
|
60
|
+
trigger,
|
|
61
|
+
watch,
|
|
62
|
+
} = form
|
|
63
|
+
const defaultProductQuantity = editOrderModifier?.productQuantity ?? 0
|
|
64
|
+
|
|
65
|
+
const valuesOrder = watch()
|
|
66
|
+
const productQuantity = valuesOrder?.product?.quantity ?? defaultProductQuantity
|
|
67
|
+
|
|
68
|
+
const orderModifiersSets =
|
|
69
|
+
valuesOrder[`${product.id}`]?.orderProductModifiers || []
|
|
70
|
+
|
|
71
|
+
const filteredOrderModifiers = filteredOrderModifierSets(orderModifiersSets)
|
|
72
|
+
|
|
73
|
+
const orderModifierSets: OrderModifierByProduct[] = useMemo(() => [
|
|
74
|
+
{
|
|
75
|
+
productQuantity: productQuantity ?? 1,
|
|
76
|
+
modifiers: filteredOrderModifiers,
|
|
77
|
+
},
|
|
78
|
+
]
|
|
79
|
+
, [filteredOrderModifiers, productQuantity])
|
|
80
|
+
|
|
81
|
+
const onSubmit = (event) => {
|
|
82
|
+
event.preventDefault()
|
|
83
|
+
trigger(`${product.id}`)
|
|
84
|
+
|
|
85
|
+
if (!isValid) return undefined
|
|
86
|
+
const productOrder: FormOrderItem = {
|
|
87
|
+
id: product.id,
|
|
88
|
+
name: product.name,
|
|
89
|
+
deposit: product?.deposit,
|
|
90
|
+
hasDeposit: category.allowDeposits && product?.deposit < product.price,
|
|
91
|
+
price: product.price,
|
|
92
|
+
productCategoryId: category.id,
|
|
93
|
+
quantity: productQuantity,
|
|
94
|
+
capacity: product?.capacity,
|
|
95
|
+
orderModifiersSets: orderModifierSets,
|
|
96
|
+
}
|
|
97
|
+
if (productOrder) {
|
|
98
|
+
return onChange(productOrder)
|
|
99
|
+
}
|
|
100
|
+
return undefined
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const handleProductQuantityChange = (
|
|
104
|
+
value: number,
|
|
105
|
+
onChange: (val: number) => void,
|
|
106
|
+
) => {
|
|
107
|
+
if (value < 0) {
|
|
108
|
+
onChange(0)
|
|
109
|
+
} else if (value > MAX_PRODUCT_NUMBER) {
|
|
110
|
+
onChange(MAX_PRODUCT_NUMBER)
|
|
111
|
+
} else {
|
|
112
|
+
onChange(value)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const disabledAddButton = useMemo(() => {
|
|
117
|
+
if (defaultProductQuantity) return false
|
|
118
|
+
return !productQuantity || !isEmpty(errors)
|
|
119
|
+
}, [defaultProductQuantity, productQuantity, errors])
|
|
120
|
+
|
|
121
|
+
const modifierPrice = getOrderProductModifiersPrice(orderModifierSets[0])
|
|
122
|
+
const productWithModifierPrice =
|
|
123
|
+
(product.price * productQuantity || 0) + modifierPrice
|
|
124
|
+
const { formatNumber } = useIntl()
|
|
125
|
+
const formatToCurrency = (value: number) =>
|
|
126
|
+
formatNumber(value, { style: 'currency', currency: Currency.GBP })
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<FormProvider {...form}>
|
|
130
|
+
<Form>
|
|
131
|
+
<div className='manual-booking-form'>
|
|
132
|
+
<ProductControl
|
|
133
|
+
product={product}
|
|
134
|
+
editOrderModifier={editOrderModifier}
|
|
135
|
+
/>
|
|
136
|
+
<div className='bg-light m-2 p-2 rounded'>
|
|
137
|
+
<Controller
|
|
138
|
+
control={control}
|
|
139
|
+
name='product.quantity'
|
|
140
|
+
rules={{
|
|
141
|
+
min: {
|
|
142
|
+
value: 1,
|
|
143
|
+
message: t('Validation:fieldMinNumber', {
|
|
144
|
+
attribute: t('product'),
|
|
145
|
+
min: 1,
|
|
146
|
+
}) as string,
|
|
147
|
+
},
|
|
148
|
+
max: {
|
|
149
|
+
value: !product.isUnlimited
|
|
150
|
+
? product.maxQuantity
|
|
151
|
+
: MAX_PRODUCT_NUMBER,
|
|
152
|
+
message: t('Validation:fieldMaxNumber', {
|
|
153
|
+
attribute: t('product'),
|
|
154
|
+
max: product.maxQuantity,
|
|
155
|
+
}) as string,
|
|
156
|
+
},
|
|
157
|
+
}}
|
|
158
|
+
render={({
|
|
159
|
+
field: { onChange, value, ref },
|
|
160
|
+
fieldState: { invalid, error },
|
|
161
|
+
}) => (
|
|
162
|
+
<div className='mb-8 d-flex flex-column'>
|
|
163
|
+
<div className='quantity-container-product w-100'>
|
|
164
|
+
<NumberInputHorizontal
|
|
165
|
+
ref={ref}
|
|
166
|
+
size='big'
|
|
167
|
+
onChange={(val) =>
|
|
168
|
+
handleProductQuantityChange(val, onChange)
|
|
169
|
+
}
|
|
170
|
+
onMinusClick={(val) =>
|
|
171
|
+
handleProductQuantityChange(val, onChange)
|
|
172
|
+
}
|
|
173
|
+
onPlusClick={(val) => {
|
|
174
|
+
handleProductQuantityChange(val, onChange)
|
|
175
|
+
}}
|
|
176
|
+
min={0}
|
|
177
|
+
max={100}
|
|
178
|
+
value={value || defaultProductQuantity}
|
|
179
|
+
className={clsx(invalid && 'error')}
|
|
180
|
+
isLoading={isSubmitting}
|
|
181
|
+
/>
|
|
182
|
+
</div>
|
|
183
|
+
<div className=' d-flex flex-column align-items-center justify-content-center'>
|
|
184
|
+
<div className='modifier-price pb-4 pl-5'>
|
|
185
|
+
{formatToCurrency(product.price)}
|
|
186
|
+
</div>
|
|
187
|
+
{error?.message && (
|
|
188
|
+
<div className='d-flex justify-content-center mt-3 w-100'>
|
|
189
|
+
<p className='iframe-event__message-error'>
|
|
190
|
+
{error.message}
|
|
191
|
+
</p>
|
|
192
|
+
</div>
|
|
193
|
+
)}
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
)}
|
|
197
|
+
/>
|
|
198
|
+
<Button
|
|
199
|
+
as='button'
|
|
200
|
+
variant='primary'
|
|
201
|
+
className='w-100'
|
|
202
|
+
disabled={disabledAddButton}
|
|
203
|
+
onClick={onSubmit}
|
|
204
|
+
>
|
|
205
|
+
{`${t('Design:add')}${modifierPrice ? ` (${formatToCurrency(productWithModifierPrice)})` : ''}`}
|
|
206
|
+
</Button>
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
</Form>
|
|
210
|
+
</FormProvider>
|
|
211
|
+
)
|
|
212
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useDialogContext, DialogContextProvider } from 'src/modals'
|
|
2
|
+
import { Modal } from 'react-bootstrap'
|
|
3
|
+
import { OrderModifierByProduct } from '@licklist/core/dist/DataMapper/Order/OrderModifiierByProduct'
|
|
4
|
+
import { Product } from '@licklist/plugins/dist/types/context/sale/menuSteps'
|
|
5
|
+
import { TicketDescription } from 'src/iframe/event'
|
|
6
|
+
import clsx from 'clsx'
|
|
7
|
+
import { ProductCategory } from 'dist/product-set/types'
|
|
8
|
+
import { FormOrderItem } from '../../order-process/components/CategoryProduct/components/ProductQuantityInput/ProductQuantityInput'
|
|
9
|
+
import { useOnWindowUnmount } from '../../order-process/components/utils/useOnWindowUnmount'
|
|
10
|
+
import { ProductWithModifierSetForm } from './ProductWithModifierSetForm'
|
|
11
|
+
|
|
12
|
+
interface ProductWithModifierSetModalProps {
|
|
13
|
+
show: boolean
|
|
14
|
+
onHide: () => void
|
|
15
|
+
product: Product
|
|
16
|
+
category: ProductCategory
|
|
17
|
+
editOrderModifier?: OrderModifierByProduct
|
|
18
|
+
onChange: (product: FormOrderItem) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const ProductWithModifierSetModal = ({
|
|
22
|
+
show,
|
|
23
|
+
onHide,
|
|
24
|
+
product,
|
|
25
|
+
category,
|
|
26
|
+
onChange,
|
|
27
|
+
editOrderModifier,
|
|
28
|
+
}: ProductWithModifierSetModalProps) => {
|
|
29
|
+
const { onBeforeUnload, onPopState } = useDialogContext()
|
|
30
|
+
useOnWindowUnmount({ onBeforeUnload, onPopState })
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<DialogContextProvider>
|
|
34
|
+
<Modal
|
|
35
|
+
onHide={onHide}
|
|
36
|
+
show={show}
|
|
37
|
+
className='m-0 manual-booking-form-modal mt-0 h-100 p-0'
|
|
38
|
+
dialogClassName='manual-booking-dialog mt-0'
|
|
39
|
+
>
|
|
40
|
+
<div className='close-button'>
|
|
41
|
+
<button
|
|
42
|
+
type='button'
|
|
43
|
+
onClick={onHide}
|
|
44
|
+
onKeyPress={onHide}
|
|
45
|
+
className='btn btn-light rounded-circle position-absolute top-0 end-0 m-2'
|
|
46
|
+
>
|
|
47
|
+
×
|
|
48
|
+
</button>
|
|
49
|
+
</div>
|
|
50
|
+
<div className='right-block' id='select-event-container'>
|
|
51
|
+
<div className='manual-booking-container'>
|
|
52
|
+
<div className='manual-booking-header'>
|
|
53
|
+
<TicketDescription
|
|
54
|
+
title={product.name}
|
|
55
|
+
description={product.description}
|
|
56
|
+
className={clsx('iframe-event__product-description', !product.images && 'mt-4')}
|
|
57
|
+
classNameProductModal='d-block'
|
|
58
|
+
images={product.images}
|
|
59
|
+
isRequired={product.isRequired}
|
|
60
|
+
canExpand
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
<ProductWithModifierSetForm
|
|
64
|
+
product={product}
|
|
65
|
+
onHide={onHide}
|
|
66
|
+
editOrderModifier={editOrderModifier}
|
|
67
|
+
onChange={onChange}
|
|
68
|
+
category={category}
|
|
69
|
+
/>
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
</Modal>
|
|
73
|
+
</DialogContextProvider>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import { Col, Form } from 'react-bootstrap'
|
|
2
|
+
import { useTranslation } from 'react-i18next'
|
|
3
|
+
import { OrderModifier } from '@licklist/core/dist/DataMapper/Order/OrderModifierDataMapper'
|
|
4
|
+
import { Modifier } from '@licklist/core/dist/DataMapper/Product/ModifierDataMapper'
|
|
5
|
+
import { ModifierSet } from '@licklist/core/dist/DataMapper/Product/ModifierSetDataMapper'
|
|
6
|
+
import { ChangeEvent, useEffect, useMemo } from 'react'
|
|
7
|
+
import { useId } from '@mantine/hooks'
|
|
8
|
+
import { Controller, useFormContext } from 'react-hook-form'
|
|
9
|
+
import { xor } from 'lodash'
|
|
10
|
+
import clsx from 'clsx'
|
|
11
|
+
import { Currency } from '@licklist/core/dist/Config'
|
|
12
|
+
import { useIntl } from 'react-intl'
|
|
13
|
+
import { MAX_PRODUCT_NUMBER } from 'src/iframe/order-process/components/CategoryProduct/constants'
|
|
14
|
+
import { NumberInputHorizontal } from 'src/sales'
|
|
15
|
+
import { selectModifierType } from '../../utils'
|
|
16
|
+
|
|
17
|
+
interface ModifiersSetControllProps {
|
|
18
|
+
modifiers?: Modifier[]
|
|
19
|
+
modifierSet: ModifierSet
|
|
20
|
+
isLoading?: boolean
|
|
21
|
+
isEditMode?: boolean
|
|
22
|
+
productId: number
|
|
23
|
+
orderProductModifierSets?: OrderModifier[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const ModifiersSetControl = ({
|
|
27
|
+
modifierSet,
|
|
28
|
+
modifiers,
|
|
29
|
+
productId,
|
|
30
|
+
isLoading = false,
|
|
31
|
+
isEditMode = false,
|
|
32
|
+
orderProductModifierSets,
|
|
33
|
+
}: ModifiersSetControllProps) => {
|
|
34
|
+
const { control, watch, setValue, trigger } = useFormContext()
|
|
35
|
+
const { t } = useTranslation('App')
|
|
36
|
+
|
|
37
|
+
const orderModifiersSets = watch(`${productId}.orderProductModifiers`)
|
|
38
|
+
|
|
39
|
+
const { formatNumber } = useIntl()
|
|
40
|
+
const formatToCurrency = (value: number) =>
|
|
41
|
+
formatNumber(value, { style: 'currency', currency: Currency.GBP })
|
|
42
|
+
|
|
43
|
+
const currentOrderModifiersSets = useMemo(
|
|
44
|
+
() =>
|
|
45
|
+
orderProductModifierSets?.filter(
|
|
46
|
+
(modifier) => modifier.modifierSetId === modifierSet.id,
|
|
47
|
+
) || [],
|
|
48
|
+
[orderProductModifierSets, modifierSet.id],
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
const onChangeModifiers = (
|
|
52
|
+
e: ChangeEvent<HTMLInputElement>,
|
|
53
|
+
type: selectModifierType,
|
|
54
|
+
quantity?: number,
|
|
55
|
+
) => {
|
|
56
|
+
if (!modifiers) return
|
|
57
|
+
|
|
58
|
+
const selectedModifier = modifiers?.find(
|
|
59
|
+
(item) => item.id === Number(e.target.defaultValue || e.target.id),
|
|
60
|
+
)
|
|
61
|
+
const checkSelectedModifier =
|
|
62
|
+
orderModifiersSets?.find(
|
|
63
|
+
(modifier) => modifier?.modifierId === selectedModifier?.id,
|
|
64
|
+
)?.quantity === 1
|
|
65
|
+
|
|
66
|
+
if (selectedModifier && type === 'radio') {
|
|
67
|
+
modifiers.forEach((modifier) => {
|
|
68
|
+
const isSelected = modifier.id === selectedModifier.id
|
|
69
|
+
const orderModifiers: OrderModifier = {
|
|
70
|
+
modifierId: modifier.id,
|
|
71
|
+
price: modifier.price,
|
|
72
|
+
productId,
|
|
73
|
+
name: modifier.name,
|
|
74
|
+
quantity: isSelected ? 1 : 0,
|
|
75
|
+
modifierSetId: modifierSet.id,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setValue(
|
|
79
|
+
`${productId}.orderProductModifiers.${modifierSet.id}.${orderModifiers.modifierId}`,
|
|
80
|
+
orderModifiers,
|
|
81
|
+
)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (selectedModifier && type === 'checkbox') {
|
|
86
|
+
const orderModifiers: OrderModifier = {
|
|
87
|
+
modifierId: selectedModifier.id,
|
|
88
|
+
price: selectedModifier.price,
|
|
89
|
+
productId,
|
|
90
|
+
name: selectedModifier.name,
|
|
91
|
+
quantity: checkSelectedModifier ? 0 : 1,
|
|
92
|
+
modifierSetId: modifierSet.id,
|
|
93
|
+
}
|
|
94
|
+
setValue(
|
|
95
|
+
`${productId}.orderProductModifiers.${modifierSet.id}.${selectedModifier.id}`,
|
|
96
|
+
orderModifiers,
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (selectedModifier && type === 'selector') {
|
|
101
|
+
const orderModifiers: OrderModifier = {
|
|
102
|
+
modifierId: selectedModifier.id,
|
|
103
|
+
price: selectedModifier.price,
|
|
104
|
+
productId,
|
|
105
|
+
quantity,
|
|
106
|
+
name: selectedModifier.name,
|
|
107
|
+
modifierSetId: modifierSet.id,
|
|
108
|
+
}
|
|
109
|
+
setValue(
|
|
110
|
+
`${productId}.orderProductModifiers.${modifierSet.id}.${selectedModifier.id}`,
|
|
111
|
+
orderModifiers,
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
trigger(`${productId}.orderProductModifiers`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!orderProductModifierSets?.length) return
|
|
120
|
+
orderProductModifierSets.forEach((orderModifier) =>
|
|
121
|
+
setValue(
|
|
122
|
+
`${productId}.orderProductModifiers.${orderModifier.modifierSetId}.${orderModifier.modifierId}`,
|
|
123
|
+
orderModifier,
|
|
124
|
+
),
|
|
125
|
+
)
|
|
126
|
+
}, [isEditMode])
|
|
127
|
+
|
|
128
|
+
const radioButtonDefaultModifier = currentOrderModifiersSets.find((modifier) =>
|
|
129
|
+
modifierSet.modifiers.some((rl) => rl.id === modifier.modifierId)
|
|
130
|
+
)?.modifierId.toString();
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<>
|
|
134
|
+
{modifierSet?.maxItems === 1 &&
|
|
135
|
+
modifiers.every((modifier) => modifier.maxItems === 1) ? (
|
|
136
|
+
<>
|
|
137
|
+
<Controller
|
|
138
|
+
name={`${productId}.modifier`}
|
|
139
|
+
control={control}
|
|
140
|
+
rules={{
|
|
141
|
+
required: {
|
|
142
|
+
value: !!modifierSet.minItems,
|
|
143
|
+
message: t('Validation:fieldRequired') as string,
|
|
144
|
+
},
|
|
145
|
+
}}
|
|
146
|
+
render={({ field, fieldState }) => {
|
|
147
|
+
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
148
|
+
onChangeModifiers(e, 'radio')
|
|
149
|
+
field.onChange(e.target.id)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<>
|
|
154
|
+
{modifiers.map((modifier) => {
|
|
155
|
+
const selectedOrderModifierId = currentOrderModifiersSets
|
|
156
|
+
?.find(
|
|
157
|
+
(orderModifier) =>
|
|
158
|
+
orderModifier.modifierId === modifier.id,
|
|
159
|
+
)
|
|
160
|
+
?.modifierId?.toString()
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<Col key={modifier.id}>
|
|
164
|
+
<div className='modifier-container d-flex flex-column p-2'>
|
|
165
|
+
<Form.Check
|
|
166
|
+
className='custom-radio p-2'
|
|
167
|
+
inline
|
|
168
|
+
id={modifier.id.toString()}
|
|
169
|
+
defaultChecked={!!selectedOrderModifierId}
|
|
170
|
+
defaultValue={selectedOrderModifierId || modifier.id.toString()}
|
|
171
|
+
checked={field.value === modifier.id.toString()}
|
|
172
|
+
onChange={onChange}
|
|
173
|
+
type='radio'
|
|
174
|
+
label={modifier.name}
|
|
175
|
+
name={modifier.name}
|
|
176
|
+
/>
|
|
177
|
+
<div className='mt-3 w-100 pl-2'>
|
|
178
|
+
<p>{modifier.description}</p>
|
|
179
|
+
<div className='modifier-price'>
|
|
180
|
+
+ {formatToCurrency(modifier.price)}
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</Col>
|
|
185
|
+
)
|
|
186
|
+
})}
|
|
187
|
+
{fieldState.error && (
|
|
188
|
+
<div className='invalid-feedback d-block'>
|
|
189
|
+
{fieldState.error.message}
|
|
190
|
+
</div>
|
|
191
|
+
)}
|
|
192
|
+
</>
|
|
193
|
+
)
|
|
194
|
+
}}
|
|
195
|
+
defaultValue={radioButtonDefaultModifier}
|
|
196
|
+
/>
|
|
197
|
+
</>
|
|
198
|
+
) : (
|
|
199
|
+
<>
|
|
200
|
+
{modifiers?.map((modifier, index) => {
|
|
201
|
+
const selectedOrderModifier = currentOrderModifiersSets?.find(
|
|
202
|
+
(orderModifier) => orderModifier.modifierId === modifier.id,
|
|
203
|
+
)?.quantity
|
|
204
|
+
|
|
205
|
+
return (
|
|
206
|
+
<>
|
|
207
|
+
{modifier.maxItems === 1 ? (
|
|
208
|
+
<>
|
|
209
|
+
<Controller
|
|
210
|
+
name={`${productId}.${modifierSet.id}.modifiers[${index}]`}
|
|
211
|
+
control={control}
|
|
212
|
+
rules={{
|
|
213
|
+
required: {
|
|
214
|
+
value: !!modifier.minItems,
|
|
215
|
+
message: t('Validation:fieldRequired') as string,
|
|
216
|
+
},
|
|
217
|
+
validate: (value) => {
|
|
218
|
+
const { maxItems, minItems } = modifier
|
|
219
|
+
if (value?.length > maxItems) {
|
|
220
|
+
return t('Validation:quantityMaxNumberModifier', {
|
|
221
|
+
max: maxItems,
|
|
222
|
+
}) as string
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (value?.length < minItems) {
|
|
226
|
+
return t('Validation:quantityMinNumberModifier', {
|
|
227
|
+
min: minItems,
|
|
228
|
+
}) as string
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return true
|
|
232
|
+
},
|
|
233
|
+
}}
|
|
234
|
+
render={({ field, fieldState: { error } }) => {
|
|
235
|
+
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
236
|
+
onChangeModifiers(e, 'checkbox')
|
|
237
|
+
field.onChange(
|
|
238
|
+
xor(field.value, [Number(e.target.value)]),
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<Col
|
|
244
|
+
className='modifier-container pl-4'
|
|
245
|
+
key={modifier.id.toString()}
|
|
246
|
+
>
|
|
247
|
+
<div className='d-flex justify-content-between pl-2 align-items-center'>
|
|
248
|
+
<Checkbox
|
|
249
|
+
value={modifier.id}
|
|
250
|
+
onChange={onChange}
|
|
251
|
+
label={modifier.name}
|
|
252
|
+
defaultChecked={!!selectedOrderModifier}
|
|
253
|
+
/>
|
|
254
|
+
</div>
|
|
255
|
+
<div className='mt-3 w-100 pl-2'>
|
|
256
|
+
<p>{modifier.description}</p>
|
|
257
|
+
<div className='modifier-price'>
|
|
258
|
+
+ {formatToCurrency(modifier.price)}
|
|
259
|
+
</div>
|
|
260
|
+
</div>
|
|
261
|
+
{error?.message && (
|
|
262
|
+
<div className='invalid-feedback d-flex'>
|
|
263
|
+
{error?.message}
|
|
264
|
+
</div>
|
|
265
|
+
)}
|
|
266
|
+
</Col>
|
|
267
|
+
)
|
|
268
|
+
}}
|
|
269
|
+
/>
|
|
270
|
+
</>
|
|
271
|
+
) : (
|
|
272
|
+
<>
|
|
273
|
+
<div className='modifier-header m-0'>
|
|
274
|
+
<div className='title'>{modifier.name}</div>
|
|
275
|
+
</div>
|
|
276
|
+
<Controller
|
|
277
|
+
control={control}
|
|
278
|
+
name={`${productId}.${modifierSet.id}.modifiers[${index}].quantity`}
|
|
279
|
+
rules={{
|
|
280
|
+
required: {
|
|
281
|
+
value: !!modifier.minItems,
|
|
282
|
+
message: t('Validation:fieldRequired') as string,
|
|
283
|
+
},
|
|
284
|
+
validate: (value) => {
|
|
285
|
+
const { maxItems, minItems } = modifier
|
|
286
|
+
if (value > maxItems) {
|
|
287
|
+
return t('Validation:quantityMaxNumberModifier', {
|
|
288
|
+
max: maxItems,
|
|
289
|
+
}) as string
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (value < minItems) {
|
|
293
|
+
return t('Validation:quantityMinNumberModifier', {
|
|
294
|
+
min: minItems,
|
|
295
|
+
}) as string
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return true
|
|
299
|
+
},
|
|
300
|
+
}}
|
|
301
|
+
render={({
|
|
302
|
+
field: { onChange, value, ref },
|
|
303
|
+
fieldState: { invalid, error },
|
|
304
|
+
}) => {
|
|
305
|
+
const onChangeProductQuantity = (val: number) => {
|
|
306
|
+
const quantity = Math.min(
|
|
307
|
+
MAX_PRODUCT_NUMBER,
|
|
308
|
+
Math.max(0, Math.ceil(val)),
|
|
309
|
+
)
|
|
310
|
+
onChange(quantity)
|
|
311
|
+
trigger(
|
|
312
|
+
`${productId}.${modifierSet.id}.modifiers[${index}].quantity`,
|
|
313
|
+
)
|
|
314
|
+
onChangeModifiers(
|
|
315
|
+
{ target: { id: modifier.id.toString() } },
|
|
316
|
+
'selector',
|
|
317
|
+
quantity,
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return (
|
|
322
|
+
<div className='modifier-container'>
|
|
323
|
+
<div className='d-flex align-items-center column mb-8 pl-6 pt-2'>
|
|
324
|
+
<div className='quantity-container mb-0'>
|
|
325
|
+
<NumberInputHorizontal
|
|
326
|
+
ref={ref}
|
|
327
|
+
size='big'
|
|
328
|
+
onChange={onChangeProductQuantity}
|
|
329
|
+
onMinusClick={onChangeProductQuantity}
|
|
330
|
+
onPlusClick={onChangeProductQuantity}
|
|
331
|
+
min={0}
|
|
332
|
+
max={MAX_PRODUCT_NUMBER}
|
|
333
|
+
value={value ?? selectedOrderModifier ?? 0}
|
|
334
|
+
className={clsx(invalid && 'error')}
|
|
335
|
+
isLoading={isLoading}
|
|
336
|
+
/>
|
|
337
|
+
</div>
|
|
338
|
+
</div>
|
|
339
|
+
<div className='p-2 mt-3 w-100 pl-4'>
|
|
340
|
+
<p className='pl-2'>{modifier.description}</p>
|
|
341
|
+
<div className='pl-2 modifier-price'>
|
|
342
|
+
+ {formatToCurrency(modifier.price)}
|
|
343
|
+
</div>
|
|
344
|
+
{error?.message && (
|
|
345
|
+
<div className='d-flex mt-3 w-100'>
|
|
346
|
+
<p className='iframe-event__message-error'>
|
|
347
|
+
{error.message}
|
|
348
|
+
</p>
|
|
349
|
+
</div>
|
|
350
|
+
)}
|
|
351
|
+
</div>
|
|
352
|
+
</div>
|
|
353
|
+
)
|
|
354
|
+
}}
|
|
355
|
+
/>
|
|
356
|
+
</>
|
|
357
|
+
)}
|
|
358
|
+
</>
|
|
359
|
+
)
|
|
360
|
+
})}
|
|
361
|
+
</>
|
|
362
|
+
)}
|
|
363
|
+
</>
|
|
364
|
+
)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
type CheckboxProps = {
|
|
368
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void
|
|
369
|
+
value: number
|
|
370
|
+
label: string
|
|
371
|
+
defaultChecked: boolean
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const Checkbox = ({
|
|
375
|
+
onChange,
|
|
376
|
+
value,
|
|
377
|
+
label,
|
|
378
|
+
defaultChecked,
|
|
379
|
+
}: CheckboxProps) => {
|
|
380
|
+
const checkboxId = useId()
|
|
381
|
+
|
|
382
|
+
return (
|
|
383
|
+
<Form.Group controlId={checkboxId} className='custom-checkbox mt-0'>
|
|
384
|
+
<Form.Check
|
|
385
|
+
label={label}
|
|
386
|
+
value={value}
|
|
387
|
+
defaultChecked={defaultChecked}
|
|
388
|
+
onChange={onChange}
|
|
389
|
+
type='checkbox'
|
|
390
|
+
/>
|
|
391
|
+
</Form.Group>
|
|
392
|
+
)
|
|
393
|
+
}
|