tf-checkout-react 1.6.6 → 1.7.2
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/README.md +401 -59
- package/dist/adapters/customFields.d.ts +1 -0
- package/dist/api/checkout.d.ts +2 -0
- package/dist/api/common.d.ts +1 -0
- package/dist/api/index.d.ts +2 -0
- package/dist/api/preRegistrationComplete.d.ts +1 -1
- package/dist/components/addonsContainer/AddonComponent.d.ts +6 -1
- package/dist/components/addonsContainer/SimpleAddonsContainer.d.ts +17 -0
- package/dist/components/addonsContainer/index.d.ts +6 -1
- package/dist/components/billing-info-container/hooks/index.d.ts +3 -0
- package/dist/components/billing-info-container/hooks/usePaymentContext.d.ts +5 -0
- package/dist/components/billing-info-container/hooks/usePaymentRedirect.d.ts +14 -0
- package/dist/components/billing-info-container/hooks/useStripePayment.d.ts +18 -0
- package/dist/components/billing-info-container/index.d.ts +13 -2
- package/dist/components/billing-info-container/utils.d.ts +26 -1
- package/dist/components/common/DatePickerField.d.ts +7 -1
- package/dist/components/common/PhoneNumberField.d.ts +1 -1
- package/dist/components/confirmationContainer/index.d.ts +4 -1
- package/dist/components/countdown/index.d.ts +1 -1
- package/dist/components/forgotPasswordModal/index.d.ts +2 -1
- package/dist/components/myTicketsContainer/index.d.ts +3 -2
- package/dist/components/orderDetailsContainer/index.d.ts +8 -1
- package/dist/components/paymentContainer/OrderDetails.d.ts +9 -0
- package/dist/components/paymentContainer/handlePayment.d.ts +15 -0
- package/dist/components/paymentContainer/index.d.ts +12 -6
- package/dist/components/preRegistration/FieldsSection.d.ts +7 -1
- package/dist/components/preRegistration/PreRegistrationComplete.d.ts +8 -0
- package/dist/components/preRegistration/constants.d.ts +2 -2
- package/dist/components/preRegistration/index.d.ts +6 -0
- package/dist/components/resetPasswordContainer/index.d.ts +2 -2
- package/dist/components/ticketsContainer/InfoIcon.d.ts +5 -0
- package/dist/components/ticketsContainer/TicketsSection.d.ts +3 -2
- package/dist/components/ticketsContainer/TimeSlotsSection.d.ts +25 -0
- package/dist/components/ticketsContainer/index.d.ts +29 -5
- package/dist/components/timerWidget/index.d.ts +2 -1
- package/dist/constants/index.d.ts +5 -0
- package/dist/index.d.ts +4 -1
- package/dist/tf-checkout-react.cjs.development.js +11284 -9565
- package/dist/tf-checkout-react.cjs.development.js.map +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js.map +1 -1
- package/dist/tf-checkout-react.esm.js +11293 -9577
- package/dist/tf-checkout-react.esm.js.map +1 -1
- package/dist/tf-checkout-styles.css +1 -1
- package/dist/types/add_on.d.ts +1 -0
- package/dist/types/checkoutPageConfigs.d.ts +1 -1
- package/dist/types/order-data.d.ts +3 -1
- package/dist/utils/auth.d.ts +8 -0
- package/dist/utils/createCheckoutDataBodyWithDefaultHolder.d.ts +1 -0
- package/dist/utils/customFields.d.ts +11 -0
- package/dist/utils/getDomain.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/setConfigs.d.ts +1 -0
- package/package.json +14 -8
- package/src/adapters/customFields.ts +7 -1
- package/src/api/auth.ts +2 -1
- package/src/api/checkout.ts +9 -4
- package/src/api/common.ts +49 -2
- package/src/api/index.ts +1 -0
- package/src/api/interceptors.ts +7 -23
- package/src/api/preRegistrationComplete.ts +1 -1
- package/src/api/publicRequest.ts +10 -0
- package/src/components/addonsContainer/AddonComponent.tsx +96 -11
- package/src/components/addonsContainer/SimpleAddonsContainer.tsx +420 -0
- package/src/components/addonsContainer/index.tsx +198 -47
- package/src/components/billing-info-container/hooks/index.ts +3 -0
- package/src/components/billing-info-container/hooks/usePaymentContext.ts +22 -0
- package/src/components/billing-info-container/hooks/usePaymentRedirect.ts +147 -0
- package/src/components/billing-info-container/hooks/useStripePayment.ts +121 -0
- package/src/components/billing-info-container/index.tsx +859 -418
- package/src/components/billing-info-container/{utils.ts → utils.tsx} +124 -1
- package/src/components/common/CheckboxField/index.tsx +1 -1
- package/src/components/common/CustomField.tsx +39 -3
- package/src/components/common/DatePickerField.tsx +25 -10
- package/src/components/common/PhoneNumberField.tsx +4 -2
- package/src/components/common/SnackbarAlert.tsx +32 -34
- package/src/components/confirmationContainer/config.ts +3 -3
- package/src/components/confirmationContainer/index.tsx +20 -1
- package/src/components/confirmationContainer/social-buttons.tsx +5 -3
- package/src/components/confirmationContainer/style.css +9 -5
- package/src/components/countdown/index.tsx +22 -22
- package/src/components/delegationsContainer/IssueComponent.tsx +2 -1
- package/src/components/forgotPasswordModal/index.tsx +44 -13
- package/src/components/loginForm/index.tsx +1 -1
- package/src/components/loginModal/index.tsx +19 -27
- package/src/components/loginModal/style.css +3 -1
- package/src/components/myTicketsContainer/index.tsx +13 -9
- package/src/components/orderDetailsContainer/index.tsx +206 -174
- package/src/components/paymentContainer/OrderDetails.tsx +257 -0
- package/src/components/paymentContainer/handlePayment.ts +86 -0
- package/src/components/paymentContainer/index.tsx +299 -259
- package/src/components/paymentContainer/style.css +141 -0
- package/src/components/preRegistration/FieldsSection.tsx +8 -0
- package/src/components/preRegistration/PreRegistrationComplete.tsx +138 -118
- package/src/components/preRegistration/PreRegistrationInformations.tsx +21 -15
- package/src/components/preRegistration/constants.tsx +10 -4
- package/src/components/preRegistration/index.tsx +233 -179
- package/src/components/preRegistration/style.css +3 -0
- package/src/components/registerForm/constants.tsx +3 -1
- package/src/components/registerForm/index.tsx +3 -3
- package/src/components/registerModal/index.tsx +47 -72
- package/src/components/resetPasswordContainer/index.tsx +20 -14
- package/src/components/seatMapContainer/TicketsSection.tsx +2 -2
- package/src/components/signupModal/index.tsx +13 -6
- package/src/components/ticketResale/index.tsx +7 -0
- package/src/components/ticketsContainer/InfoIcon.tsx +35 -0
- package/src/components/ticketsContainer/PromoCodeSection.tsx +34 -28
- package/src/components/ticketsContainer/TicketRow.tsx +1 -1
- package/src/components/ticketsContainer/TicketsSection.tsx +189 -57
- package/src/components/ticketsContainer/TimeSlotsSection.tsx +120 -0
- package/src/components/ticketsContainer/index.tsx +268 -106
- package/src/components/timerWidget/index.tsx +15 -3
- package/src/components/timerWidget/style.css +2 -1
- package/src/constants/index.ts +2 -0
- package/src/env.ts +14 -6
- package/src/hoc/CustomFields/index.tsx +9 -1
- package/src/index.ts +7 -2
- package/src/types/add_on.ts +1 -0
- package/src/types/api/cart.d.ts +8 -0
- package/src/types/api/checkout.d.ts +58 -7
- package/src/types/api/common.d.ts +30 -0
- package/src/types/api/orders.d.ts +19 -3
- package/src/types/api/payment.d.ts +6 -2
- package/src/types/api/preRegistrationComplete.d.ts +2 -2
- package/src/types/checkoutPageConfigs.ts +1 -1
- package/src/types/order-data.ts +3 -1
- package/src/types/pre-registration-complete.d.ts +6 -1
- package/src/utils/auth.ts +32 -0
- package/src/utils/cookies.ts +42 -11
- package/src/utils/createCheckoutDataBodyWithDefaultHolder.ts +3 -1
- package/src/utils/customFields.ts +22 -0
- package/src/utils/getDomain.ts +10 -4
- package/src/utils/index.ts +1 -1
- package/src/utils/setConfigs.ts +3 -1
- package/dist/components/stripePayment/index.d.ts +0 -24
- package/src/components/stripePayment/index.tsx +0 -281
- package/src/components/stripePayment/style.css +0 -60
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import { CircularProgress } from '@mui/material'
|
|
4
|
+
import { Form, Formik } from 'formik'
|
|
5
|
+
import _identity from 'lodash/identity'
|
|
6
|
+
import _map from 'lodash/map'
|
|
7
|
+
import React, { useEffect, useMemo, useState } from 'react'
|
|
8
|
+
import { Tooltip } from 'react-tooltip'
|
|
9
|
+
|
|
10
|
+
import { getAddons, getCart } from '../../api'
|
|
11
|
+
import { FEES_STYLES } from '../../constants'
|
|
12
|
+
import { currencyNormalizerCreator } from '../../normalizers'
|
|
13
|
+
import { CONFIGS, createMarkup } from '../../utils'
|
|
14
|
+
import InfoIcon from '../ticketsContainer/InfoIcon'
|
|
15
|
+
import { addonsWithGroupsAdapter, cartAdapter } from './adapters'
|
|
16
|
+
import AddonComponent from './AddonComponent'
|
|
17
|
+
import { getNormalizedPrice } from './normalizers'
|
|
18
|
+
import {
|
|
19
|
+
generateSelectOptions,
|
|
20
|
+
getAddonSelectOptions,
|
|
21
|
+
getSortedAddons,
|
|
22
|
+
getTicketRelatedAddons,
|
|
23
|
+
} from './utils'
|
|
24
|
+
|
|
25
|
+
export interface ISimpleAddonContainerProps {
|
|
26
|
+
classNamePrefix?: string;
|
|
27
|
+
onGetAddonsPageInfoSuccess?: (res: any) => void;
|
|
28
|
+
onGetAddonsPageInfoError?: (error: any) => void;
|
|
29
|
+
descriptionTrigger?: 'click' | 'hover' | 'always';
|
|
30
|
+
addOnDataWithCustomFields: any;
|
|
31
|
+
configs: any;
|
|
32
|
+
eventId: string;
|
|
33
|
+
onAddOnSelect?: (id: string, value: string, addon: any, fieldUpdates: any) => void;
|
|
34
|
+
handleConfirm?: (values: any) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ObjectLiteral {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const SimpleAddonsContainer = ({
|
|
42
|
+
classNamePrefix = 'add_on',
|
|
43
|
+
onGetAddonsPageInfoSuccess = _identity,
|
|
44
|
+
onGetAddonsPageInfoError = _identity,
|
|
45
|
+
descriptionTrigger = 'click',
|
|
46
|
+
addOnDataWithCustomFields,
|
|
47
|
+
configs,
|
|
48
|
+
eventId,
|
|
49
|
+
onAddOnSelect = _identity,
|
|
50
|
+
handleConfirm = _identity,
|
|
51
|
+
}: ISimpleAddonContainerProps) => {
|
|
52
|
+
const [addons, setAddons] = useState<any>(null)
|
|
53
|
+
const [addonsOptions, setAddonsOptions] = useState<any>({})
|
|
54
|
+
const [groupsWithSelectedVariants, setGroupsWithSelectedVariants] = useState<any>({})
|
|
55
|
+
const [groupsWithInitialVariantsValues, setGroupsWithInitialVariantsValues] =
|
|
56
|
+
useState<any>({})
|
|
57
|
+
const [loading, setLoading] = useState(true)
|
|
58
|
+
|
|
59
|
+
const [visibleDescription, setVisibleDescription] = useState<string | null>(null)
|
|
60
|
+
|
|
61
|
+
const handleDescriptionToggle = (ticketId: string) => {
|
|
62
|
+
setVisibleDescription(current => (current === ticketId ? null : ticketId))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// build { [fieldName]: value } for one addon from current Formik values
|
|
66
|
+
const collectAddonFieldUpdates = (addon: any, allValues: Record<string, any>) => {
|
|
67
|
+
const out: Record<string, any> = {}
|
|
68
|
+
if (!addOnDataWithCustomFields?.fields?.length) return out
|
|
69
|
+
addOnDataWithCustomFields.fields.forEach((group: any) => {
|
|
70
|
+
group.groupItems.forEach((item: any) => {
|
|
71
|
+
const k = `${addon.id}-${group.id}-${item.name}`
|
|
72
|
+
if (k in allValues) out[item.name] = allValues[k]
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
return out
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// live-sync a single custom field change into localStorage.add_on_data_capture
|
|
79
|
+
const handleCustomFieldChange = (
|
|
80
|
+
addon: any,
|
|
81
|
+
_groupId: string | number,
|
|
82
|
+
fieldName: string,
|
|
83
|
+
value: any
|
|
84
|
+
) => {
|
|
85
|
+
const existing = JSON.parse(localStorage.getItem('add_on_data_capture') || '{}')
|
|
86
|
+
const addonId = String(addon.id)
|
|
87
|
+
const next = {
|
|
88
|
+
...existing,
|
|
89
|
+
[addonId]: { ...(existing[addonId] || {}), [fieldName]: value },
|
|
90
|
+
}
|
|
91
|
+
localStorage.setItem('add_on_data_capture', JSON.stringify(next))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
const getAddonsPageInfo = async () => {
|
|
96
|
+
try {
|
|
97
|
+
if (eventId) {
|
|
98
|
+
setLoading(true)
|
|
99
|
+
|
|
100
|
+
// Get choosed ticket info (id, count) from Cart request for addons options calculations
|
|
101
|
+
const cart = await getCart()
|
|
102
|
+
const { id: choosedTicketID, quantity } = cartAdapter(cart)
|
|
103
|
+
const choosedTicketCount = Number(quantity)
|
|
104
|
+
|
|
105
|
+
// Get and collect addons data
|
|
106
|
+
const addonsData = await getAddons(eventId)
|
|
107
|
+
const adaptedAddons = addonsWithGroupsAdapter(addonsData)
|
|
108
|
+
const ticketRelatedAddons = getTicketRelatedAddons(
|
|
109
|
+
adaptedAddons,
|
|
110
|
+
choosedTicketID
|
|
111
|
+
)
|
|
112
|
+
const sortedTicketAddons = getSortedAddons(ticketRelatedAddons)
|
|
113
|
+
|
|
114
|
+
setAddons(sortedTicketAddons)
|
|
115
|
+
|
|
116
|
+
// Collect addons and addon group options
|
|
117
|
+
const {
|
|
118
|
+
addonsWithOptions,
|
|
119
|
+
groupsWithSelectedVariantsInfo,
|
|
120
|
+
groupsWithVariants,
|
|
121
|
+
} = getAddonSelectOptions(adaptedAddons, choosedTicketCount)
|
|
122
|
+
|
|
123
|
+
setAddonsOptions(addonsWithOptions)
|
|
124
|
+
setGroupsWithSelectedVariants(groupsWithSelectedVariantsInfo)
|
|
125
|
+
setGroupsWithInitialVariantsValues(groupsWithVariants)
|
|
126
|
+
|
|
127
|
+
// Success callback props
|
|
128
|
+
onGetAddonsPageInfoSuccess(addonsData)
|
|
129
|
+
}
|
|
130
|
+
} catch (e) {
|
|
131
|
+
// Callback error props
|
|
132
|
+
onGetAddonsPageInfoError(e)
|
|
133
|
+
} finally {
|
|
134
|
+
setLoading(false)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
getAddonsPageInfo()
|
|
139
|
+
}, [eventId, onGetAddonsPageInfoError, onGetAddonsPageInfoSuccess])
|
|
140
|
+
|
|
141
|
+
const recreateGroupVariantsSelectOptions = (groupId: any, changedGroupd: any) => {
|
|
142
|
+
const { choosedVariants, limit, selectedCount } = changedGroupd
|
|
143
|
+
const remainingGroupStock = limit - selectedCount
|
|
144
|
+
const recreatedVariantsOptions: ObjectLiteral = {}
|
|
145
|
+
|
|
146
|
+
// Regenerate variants allowed stock counts
|
|
147
|
+
for (const variant in choosedVariants) {
|
|
148
|
+
const variantId = variant
|
|
149
|
+
const variantCurrSelectedValue = choosedVariants[variant]
|
|
150
|
+
let allowedOptionCount
|
|
151
|
+
|
|
152
|
+
// Formula for regenerating
|
|
153
|
+
if (
|
|
154
|
+
remainingGroupStock >=
|
|
155
|
+
groupsWithInitialVariantsValues[groupId][variantId] - variantCurrSelectedValue
|
|
156
|
+
) {
|
|
157
|
+
allowedOptionCount = groupsWithInitialVariantsValues[groupId][variantId]
|
|
158
|
+
} else {
|
|
159
|
+
allowedOptionCount = remainingGroupStock + variantCurrSelectedValue
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
recreatedVariantsOptions[variantId] = generateSelectOptions(0, allowedOptionCount)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
setAddonsOptions((prevState: any) =>
|
|
166
|
+
Object.assign({}, prevState, recreatedVariantsOptions)
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const onFieldChange = (id: any, value: any, addon: any) => {
|
|
171
|
+
// If changeableGroup exsists it means that group with limitation variant was changed
|
|
172
|
+
const changeableGroup = groupsWithSelectedVariants[addon.id]
|
|
173
|
+
|
|
174
|
+
if (changeableGroup) {
|
|
175
|
+
const currGroupId = addon.id
|
|
176
|
+
const currSelectedVariantId = id
|
|
177
|
+
const currSelectedVariantCount = Number(value)
|
|
178
|
+
const currSelectedVariantPrevCount =
|
|
179
|
+
groupsWithSelectedVariants[currGroupId].choosedVariants[currSelectedVariantId]
|
|
180
|
+
|
|
181
|
+
const currSelectedGroupCount =
|
|
182
|
+
changeableGroup.selectedCount +
|
|
183
|
+
(currSelectedVariantCount - currSelectedVariantPrevCount)
|
|
184
|
+
|
|
185
|
+
// Update Group info
|
|
186
|
+
const updatedGroupsWithSelectedVariants = {
|
|
187
|
+
...groupsWithSelectedVariants,
|
|
188
|
+
[currGroupId]: {
|
|
189
|
+
...groupsWithSelectedVariants[currGroupId],
|
|
190
|
+
selectedCount: currSelectedGroupCount,
|
|
191
|
+
choosedVariants: {
|
|
192
|
+
...groupsWithSelectedVariants[currGroupId].choosedVariants,
|
|
193
|
+
[currSelectedVariantId]: currSelectedVariantCount,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
}
|
|
197
|
+
setGroupsWithSelectedVariants(updatedGroupsWithSelectedVariants)
|
|
198
|
+
|
|
199
|
+
// Recreate Select Options for Addon Group Variants
|
|
200
|
+
recreateGroupVariantsSelectOptions(
|
|
201
|
+
currGroupId,
|
|
202
|
+
updatedGroupsWithSelectedVariants[currGroupId]
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const initialValues = useMemo(() => {
|
|
208
|
+
const addOnsData: any = {}
|
|
209
|
+
if (addons?.length > 0 && addOnDataWithCustomFields?.fields?.length > 0) {
|
|
210
|
+
_map(addons, addon => {
|
|
211
|
+
_map(addOnDataWithCustomFields.fields, field => {
|
|
212
|
+
const { id, groupItems } = field
|
|
213
|
+
_map(groupItems, item => {
|
|
214
|
+
addOnsData[`${addon.id}-${id}-${item.name}`] = item.value
|
|
215
|
+
})
|
|
216
|
+
})
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return addOnsData
|
|
221
|
+
}, [addons, addOnDataWithCustomFields])
|
|
222
|
+
|
|
223
|
+
if (loading || !addons) {
|
|
224
|
+
return (
|
|
225
|
+
<div className={`${classNamePrefix}_loader`}>
|
|
226
|
+
<CircularProgress size={50} />
|
|
227
|
+
</div>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return (
|
|
232
|
+
<div className={`${classNamePrefix}_container`}>
|
|
233
|
+
<div className={`${classNamePrefix}_block`}>
|
|
234
|
+
<div className={`${classNamePrefix}_line_block`}>
|
|
235
|
+
{addons?.length > 0 && (
|
|
236
|
+
<div className={`${classNamePrefix}_title`}>UPGRADES & ADD-ONS</div>
|
|
237
|
+
)}
|
|
238
|
+
</div>
|
|
239
|
+
{addons?.length > 0 && (
|
|
240
|
+
<div className={`${classNamePrefix}_subtitle`}>
|
|
241
|
+
PLEASE SELECT FROM THE OPTIONAL ADD-ONS BELOW
|
|
242
|
+
</div>
|
|
243
|
+
)}
|
|
244
|
+
<Formik
|
|
245
|
+
initialValues={initialValues}
|
|
246
|
+
onSubmit={values => {
|
|
247
|
+
handleConfirm(values)
|
|
248
|
+
}}
|
|
249
|
+
validate={() => {
|
|
250
|
+
// Real-time validation can be handled here if needed
|
|
251
|
+
}}
|
|
252
|
+
>
|
|
253
|
+
{({ values, errors, setFieldTouched }) => (
|
|
254
|
+
<Form autoComplete="off" className="form_holder">
|
|
255
|
+
<>
|
|
256
|
+
{addons.map((addon: any) => {
|
|
257
|
+
const price = addon.feeIncluded ? addon.price : addon.cost
|
|
258
|
+
const isAddonFree = Number(addon?.price) === 0
|
|
259
|
+
|
|
260
|
+
const addOnNormalizedCost = isAddonFree
|
|
261
|
+
? 'FREE'
|
|
262
|
+
: currencyNormalizerCreator(
|
|
263
|
+
getNormalizedPrice(addon?.cost ?? 0),
|
|
264
|
+
addon.currency
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
const addonNormalizedPrice = isAddonFree
|
|
268
|
+
? 'FREE'
|
|
269
|
+
: currencyNormalizerCreator(
|
|
270
|
+
getNormalizedPrice(
|
|
271
|
+
CONFIGS.FEES_STYLE === FEES_STYLES.DISPLAY_BOTH
|
|
272
|
+
? addon?.price ?? price
|
|
273
|
+
: price
|
|
274
|
+
),
|
|
275
|
+
addon.currency
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
return (
|
|
279
|
+
<div key={addon.id} className={`${classNamePrefix}_product_block`}>
|
|
280
|
+
<div className={`${classNamePrefix}_product_images`}>
|
|
281
|
+
{addon.imageUrl && (
|
|
282
|
+
<div className={`${classNamePrefix}_product_image_block`}>
|
|
283
|
+
<img src={addon.imageUrl} alt="No Data" />
|
|
284
|
+
</div>
|
|
285
|
+
)}
|
|
286
|
+
</div>
|
|
287
|
+
<div className={`${classNamePrefix}_product_info_block`}>
|
|
288
|
+
<div className={`${classNamePrefix}_product_title`}>
|
|
289
|
+
{addon.name}
|
|
290
|
+
{addon.description && descriptionTrigger !== 'always' && (
|
|
291
|
+
<>
|
|
292
|
+
<span
|
|
293
|
+
aria-hidden
|
|
294
|
+
className="info-icon"
|
|
295
|
+
onClick={
|
|
296
|
+
descriptionTrigger === 'click'
|
|
297
|
+
? () => handleDescriptionToggle(addon.id)
|
|
298
|
+
: undefined
|
|
299
|
+
}
|
|
300
|
+
onMouseEnter={
|
|
301
|
+
descriptionTrigger === 'hover'
|
|
302
|
+
? () => setVisibleDescription(addon.id)
|
|
303
|
+
: undefined
|
|
304
|
+
}
|
|
305
|
+
onMouseLeave={
|
|
306
|
+
descriptionTrigger === 'hover'
|
|
307
|
+
? () => setVisibleDescription(null)
|
|
308
|
+
: undefined
|
|
309
|
+
}
|
|
310
|
+
style={{
|
|
311
|
+
marginLeft: 8,
|
|
312
|
+
cursor: 'pointer',
|
|
313
|
+
display: 'flex',
|
|
314
|
+
}}
|
|
315
|
+
data-tooltip-id={`tooltip-${addon.id}`}
|
|
316
|
+
data-tooltip-content="View Add-On info"
|
|
317
|
+
>
|
|
318
|
+
<InfoIcon size={14} />
|
|
319
|
+
</span>
|
|
320
|
+
<Tooltip id={`tooltip-${addon.id}`} place="top">
|
|
321
|
+
{addon.description || 'No description available'}
|
|
322
|
+
</Tooltip>
|
|
323
|
+
</>
|
|
324
|
+
)}
|
|
325
|
+
</div>
|
|
326
|
+
<div className={`${classNamePrefix}_product_price`}>
|
|
327
|
+
{CONFIGS.FEES_STYLE === FEES_STYLES.TRADITIONAL
|
|
328
|
+
? addonNormalizedPrice
|
|
329
|
+
: addOnNormalizedCost}
|
|
330
|
+
{!isAddonFree &&
|
|
331
|
+
CONFIGS.FEES_STYLE === FEES_STYLES.TRADITIONAL && (
|
|
332
|
+
<span className={`${classNamePrefix}_product_fee`}>
|
|
333
|
+
{addon.feeIncluded ? '(incl. Fees)' : '(excl. Fees)'}
|
|
334
|
+
</span>
|
|
335
|
+
)}
|
|
336
|
+
{!isAddonFree &&
|
|
337
|
+
CONFIGS.FEES_STYLE === FEES_STYLES.DISPLAY_BOTH && (
|
|
338
|
+
<>
|
|
339
|
+
<span className={`${classNamePrefix}_product_fee`}>
|
|
340
|
+
{`(${addonNormalizedPrice} with fees)`}
|
|
341
|
+
</span>
|
|
342
|
+
</>
|
|
343
|
+
)}
|
|
344
|
+
</div>
|
|
345
|
+
</div>
|
|
346
|
+
{(visibleDescription === addon.id ||
|
|
347
|
+
descriptionTrigger === 'always') && (
|
|
348
|
+
<div
|
|
349
|
+
className={`${classNamePrefix}_product_desc`}
|
|
350
|
+
dangerouslySetInnerHTML={createMarkup(addon.description)}
|
|
351
|
+
/>
|
|
352
|
+
)}
|
|
353
|
+
<div className={`${classNamePrefix}_product_select_container`}>
|
|
354
|
+
{addon.variants ? (
|
|
355
|
+
addon.variants.map((variant: any) => (
|
|
356
|
+
// Group Variants
|
|
357
|
+
<AddonComponent
|
|
358
|
+
key={variant.id}
|
|
359
|
+
data={variant}
|
|
360
|
+
selectOptions={addonsOptions[variant.id]}
|
|
361
|
+
classNamePrefix={classNamePrefix}
|
|
362
|
+
handleAddonChange={(id, value) => {
|
|
363
|
+
console.log('handleAddonChange', id, value)
|
|
364
|
+
onFieldChange(id, value, addon)
|
|
365
|
+
const fieldUpdates = collectAddonFieldUpdates(
|
|
366
|
+
addon,
|
|
367
|
+
values
|
|
368
|
+
)
|
|
369
|
+
onAddOnSelect(id, value, addon, fieldUpdates)
|
|
370
|
+
}}
|
|
371
|
+
onCustomFieldChange={handleCustomFieldChange}
|
|
372
|
+
addOnDataWithCustomFields={addOnDataWithCustomFields}
|
|
373
|
+
configs={configs}
|
|
374
|
+
values={values}
|
|
375
|
+
errors={errors}
|
|
376
|
+
/>
|
|
377
|
+
))
|
|
378
|
+
) : (
|
|
379
|
+
// Simple Addon
|
|
380
|
+
<AddonComponent
|
|
381
|
+
key={addon.id}
|
|
382
|
+
data={addon}
|
|
383
|
+
selectOptions={addonsOptions[addon.id]}
|
|
384
|
+
classNamePrefix={classNamePrefix}
|
|
385
|
+
handleAddonChange={(id, value) => {
|
|
386
|
+
onFieldChange(id, value, addon)
|
|
387
|
+
const fieldUpdates = collectAddonFieldUpdates(addon, values)
|
|
388
|
+
onAddOnSelect(id, value, addon, fieldUpdates)
|
|
389
|
+
_map(addOnDataWithCustomFields.fields, fieldGroup => {
|
|
390
|
+
const { id, groupItems } = fieldGroup
|
|
391
|
+
_map(groupItems, field => {
|
|
392
|
+
setFieldTouched(
|
|
393
|
+
`${addon.id}-${id}-${field.name}`,
|
|
394
|
+
true,
|
|
395
|
+
true
|
|
396
|
+
)
|
|
397
|
+
})
|
|
398
|
+
})
|
|
399
|
+
}}
|
|
400
|
+
onCustomFieldChange={handleCustomFieldChange}
|
|
401
|
+
addOnDataWithCustomFields={addOnDataWithCustomFields}
|
|
402
|
+
configs={configs}
|
|
403
|
+
values={values}
|
|
404
|
+
errors={errors}
|
|
405
|
+
/>
|
|
406
|
+
)}
|
|
407
|
+
</div>
|
|
408
|
+
</div>
|
|
409
|
+
)
|
|
410
|
+
})}
|
|
411
|
+
</>
|
|
412
|
+
</Form>
|
|
413
|
+
)}
|
|
414
|
+
</Formik>
|
|
415
|
+
</div>
|
|
416
|
+
</div>
|
|
417
|
+
)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export default SimpleAddonsContainer
|