tf-checkout-react 1.0.85 → 1.0.86
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/components/billing-info-container/index.d.ts +2 -1
- package/dist/tf-checkout-react.cjs.development.js +24 -36
- 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 +25 -37
- package/dist/tf-checkout-react.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/api/index.ts +4 -5
- package/src/components/billing-info-container/index.tsx +65 -102
- package/src/components/common/CustomField.tsx +15 -12
- package/src/components/ticketsContainer/index.tsx +1 -1
- package/src/components/waitingList/index.tsx +10 -4
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -33,6 +33,10 @@ publicRequest.interceptors.response.use(
|
|
|
33
33
|
window.localStorage.removeItem('auth_guest_token')
|
|
34
34
|
window.localStorage.removeItem('user_data')
|
|
35
35
|
window.localStorage.removeItem('access_token')
|
|
36
|
+
const errorType = error?.response?.data?.error
|
|
37
|
+
if (errorType === 'invalid_token') {
|
|
38
|
+
window.location.href = '/'
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
return Promise.reject(error)
|
|
@@ -224,11 +228,6 @@ export const getProfileData = (accessToken: any) =>
|
|
|
224
228
|
},
|
|
225
229
|
})
|
|
226
230
|
.catch((e: any) => {
|
|
227
|
-
const errorType = e?.response?.data?.error
|
|
228
|
-
if (isWindowDefined) {
|
|
229
|
-
const event = new window.CustomEvent('auth_error', { detail: errorType })
|
|
230
|
-
window.document.dispatchEvent(event)
|
|
231
|
-
}
|
|
232
231
|
return e
|
|
233
232
|
})
|
|
234
233
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC, useEffect, useState,
|
|
1
|
+
import React, { FC, useEffect, useState, useRef } from 'react'
|
|
2
2
|
import { AxiosError } from 'axios'
|
|
3
3
|
import {
|
|
4
4
|
Field,
|
|
@@ -14,6 +14,7 @@ import _map from 'lodash/map'
|
|
|
14
14
|
import _get from 'lodash/get'
|
|
15
15
|
import _includes from 'lodash/includes'
|
|
16
16
|
import _isEqual from 'lodash/isEqual'
|
|
17
|
+
import _isEmpty from 'lodash/isEmpty'
|
|
17
18
|
|
|
18
19
|
import './style.css'
|
|
19
20
|
import { combineValidators, requiredValidator } from '../../validators'
|
|
@@ -60,47 +61,36 @@ export interface IBillingInfoPage {
|
|
|
60
61
|
eventId: any,
|
|
61
62
|
res: any
|
|
62
63
|
) => void;
|
|
63
|
-
|
|
64
64
|
onRegisterSuccess?: (value: {
|
|
65
65
|
accessToken: string;
|
|
66
66
|
refreshToken: string;
|
|
67
67
|
}) => void;
|
|
68
|
-
|
|
69
68
|
onRegisterError?: (e: AxiosError, email: string) => void;
|
|
70
|
-
|
|
71
69
|
onSubmitError?: (e: AxiosError) => void;
|
|
72
|
-
|
|
73
70
|
onGetCartSuccess?: (res: any) => void;
|
|
74
|
-
|
|
75
71
|
onGetCartError?: (e: AxiosError) => void;
|
|
76
|
-
|
|
77
72
|
onGetCountriesSuccess?: (res: any) => void;
|
|
78
|
-
|
|
79
73
|
onGetCountriesError?: (e: AxiosError) => void;
|
|
80
|
-
|
|
81
74
|
onGetStatesSuccess?: (res: any) => void;
|
|
82
|
-
|
|
83
75
|
onGetStatesError?: (e: AxiosError) => void;
|
|
84
|
-
|
|
85
76
|
onGetProfileDataSuccess?: (res: any) => void;
|
|
86
|
-
|
|
87
77
|
onGetProfileDataError?: (e: AxiosError) => void;
|
|
88
|
-
|
|
89
78
|
onAuthorizeSuccess?: () => void;
|
|
90
|
-
|
|
91
79
|
onAuthorizeError?: (e: AxiosError) => void;
|
|
92
|
-
|
|
93
80
|
onLogin?: () => void;
|
|
94
81
|
onLoginSuccess?: () => void;
|
|
95
82
|
onErrorClose?: () => void;
|
|
96
|
-
|
|
97
83
|
initialValues?: FormikValues;
|
|
98
84
|
buttonName?: string;
|
|
99
85
|
theme?: 'light' | 'dark';
|
|
100
86
|
isLoggedIn?: boolean;
|
|
101
87
|
accountInfoTitle?: string | JSX.Element;
|
|
102
88
|
hideLogo?: boolean;
|
|
103
|
-
themeOptions?: ThemeOptions & {
|
|
89
|
+
themeOptions?: ThemeOptions & {
|
|
90
|
+
input?: CSSProperties;
|
|
91
|
+
checkbox?: CSSProperties;
|
|
92
|
+
};
|
|
93
|
+
hideErrorsAlertSection?: boolean
|
|
104
94
|
}
|
|
105
95
|
|
|
106
96
|
const LogicRunner: FC<{
|
|
@@ -118,7 +108,7 @@ const LogicRunner: FC<{
|
|
|
118
108
|
setValues,
|
|
119
109
|
setUserValues,
|
|
120
110
|
onGetStatesSuccess,
|
|
121
|
-
onGetStatesError
|
|
111
|
+
onGetStatesError,
|
|
122
112
|
}) => {
|
|
123
113
|
const prevCountry = useRef(values.country)
|
|
124
114
|
useEffect(() => {
|
|
@@ -162,7 +152,7 @@ const LogicRunner: FC<{
|
|
|
162
152
|
confirmEmail: parsedData?.email || '',
|
|
163
153
|
state: parsedData?.state || '',
|
|
164
154
|
street_address: parsedData?.street_address || '',
|
|
165
|
-
country: parsedData?.country ||
|
|
155
|
+
country: parsedData?.country || '1',
|
|
166
156
|
zip: parsedData?.zip || '',
|
|
167
157
|
brand_opt_in: parsedData?.brand_opt_in || '',
|
|
168
158
|
city: parsedData?.city || '',
|
|
@@ -180,10 +170,8 @@ const LogicRunner: FC<{
|
|
|
180
170
|
}
|
|
181
171
|
getStoredUserData()
|
|
182
172
|
}, [userDataEncoded, setValues, setUserValues])
|
|
183
|
-
|
|
184
173
|
return null
|
|
185
174
|
}
|
|
186
|
-
|
|
187
175
|
export const BillingInfoContainer = ({
|
|
188
176
|
data = [],
|
|
189
177
|
ticketHoldersFields = {
|
|
@@ -213,7 +201,8 @@ export const BillingInfoContainer = ({
|
|
|
213
201
|
accountInfoTitle = '',
|
|
214
202
|
hideLogo,
|
|
215
203
|
themeOptions,
|
|
216
|
-
onErrorClose = () => {}
|
|
204
|
+
onErrorClose = () => {},
|
|
205
|
+
hideErrorsAlertSection = false
|
|
217
206
|
}: IBillingInfoPage) => {
|
|
218
207
|
const themeMui = createTheme(themeOptions)
|
|
219
208
|
const isWindowDefined = typeof window !== 'undefined'
|
|
@@ -225,11 +214,9 @@ export const BillingInfoContainer = ({
|
|
|
225
214
|
isWindowDefined && window.localStorage.getItem('access_token')
|
|
226
215
|
? window.localStorage.getItem('access_token') || ''
|
|
227
216
|
: ''
|
|
228
|
-
|
|
229
217
|
const [dataWithUniqueIds, setDataWithUniqueIds] = useState<
|
|
230
218
|
IBillingInfoData[]
|
|
231
219
|
>(data)
|
|
232
|
-
|
|
233
220
|
const [isLoggedIn, setIsLoggedIn] = useState(!!access_token)
|
|
234
221
|
const [cartInfoData, setCartInfo] = useState<any>({})
|
|
235
222
|
const [countries, setCountries] = useState<any>([])
|
|
@@ -261,7 +248,6 @@ export const BillingInfoContainer = ({
|
|
|
261
248
|
_get(userData, 'first_name', '') || _get(userValues, 'first_name', '')
|
|
262
249
|
const lastNameLogged =
|
|
263
250
|
_get(userData, 'last_name', '') || _get(userValues, 'last_name', '')
|
|
264
|
-
|
|
265
251
|
const showDOB = getQueryVariable('age_required') === 'true'
|
|
266
252
|
const eventId = getQueryVariable('event_id')
|
|
267
253
|
const optedInFieldValue: boolean = _get(cartInfoData, 'optedIn', false)
|
|
@@ -270,7 +256,7 @@ export const BillingInfoContainer = ({
|
|
|
270
256
|
|
|
271
257
|
// Get prevProps
|
|
272
258
|
const prevData = useRef(data)
|
|
273
|
-
|
|
259
|
+
|
|
274
260
|
useEffect(() => {
|
|
275
261
|
const hasUniqueId = _get(dataWithUniqueIds, '[0].uniqueId')
|
|
276
262
|
const isEqualData = _isEqual(prevData.current, data)
|
|
@@ -281,7 +267,7 @@ export const BillingInfoContainer = ({
|
|
|
281
267
|
}
|
|
282
268
|
}
|
|
283
269
|
}, [dataWithUniqueIds, data])
|
|
284
|
-
|
|
270
|
+
|
|
285
271
|
const getQuantity = (cart: any = []) => {
|
|
286
272
|
let qty: any = 0
|
|
287
273
|
cart.forEach((item: any) => {
|
|
@@ -290,28 +276,11 @@ export const BillingInfoContainer = ({
|
|
|
290
276
|
return qty
|
|
291
277
|
}
|
|
292
278
|
|
|
293
|
-
const handleAuthErrors = useCallback((e) => {
|
|
294
|
-
setIsLoggedIn(false)
|
|
295
|
-
if (isWindowDefined && e?.detail === 'invalid_token') {
|
|
296
|
-
window.location.href = '/'
|
|
297
|
-
}
|
|
298
|
-
}, [])
|
|
299
|
-
|
|
300
|
-
useEffect(() => {
|
|
301
|
-
isWindowDefined &&
|
|
302
|
-
window.document.addEventListener('auth_error', handleAuthErrors)
|
|
303
|
-
return () => {
|
|
304
|
-
isWindowDefined &&
|
|
305
|
-
window.document.removeEventListener('auth_error', handleAuthErrors)
|
|
306
|
-
}
|
|
307
|
-
}, [handleAuthErrors])
|
|
308
|
-
|
|
309
279
|
useEffect(() => {
|
|
310
280
|
if ((pIsLoggedIn || access_token) && !isLoggedIn) {
|
|
311
281
|
setIsLoggedIn(true)
|
|
312
282
|
}
|
|
313
283
|
}, [pIsLoggedIn, isLoggedIn, access_token])
|
|
314
|
-
|
|
315
284
|
//just once
|
|
316
285
|
useEffect(() => {
|
|
317
286
|
// fetch countries data
|
|
@@ -335,7 +304,6 @@ export const BillingInfoContainer = ({
|
|
|
335
304
|
fetchCountries()
|
|
336
305
|
fetchCart()
|
|
337
306
|
}, [])
|
|
338
|
-
|
|
339
307
|
// fetch cart data
|
|
340
308
|
const fetchCart = async () => {
|
|
341
309
|
try {
|
|
@@ -354,7 +322,6 @@ export const BillingInfoContainer = ({
|
|
|
354
322
|
}
|
|
355
323
|
}
|
|
356
324
|
}
|
|
357
|
-
|
|
358
325
|
// fetch user data
|
|
359
326
|
const fetchUserData = async (token: string) => {
|
|
360
327
|
try {
|
|
@@ -362,7 +329,11 @@ export const BillingInfoContainer = ({
|
|
|
362
329
|
const userDataResponse = await getProfileData(token)
|
|
363
330
|
const profileSpecifiedData = _get(userDataResponse, 'data.data')
|
|
364
331
|
const profileDataObj = setLoggedUserData(profileSpecifiedData)
|
|
365
|
-
setUserValues({
|
|
332
|
+
setUserValues({
|
|
333
|
+
...profileDataObj,
|
|
334
|
+
firstName: profileDataObj.first_name,
|
|
335
|
+
lastName: profileDataObj.last_name,
|
|
336
|
+
})
|
|
366
337
|
window.localStorage.setItem(
|
|
367
338
|
'user_data',
|
|
368
339
|
JSON.stringify(profileDataObj)
|
|
@@ -375,11 +346,9 @@ export const BillingInfoContainer = ({
|
|
|
375
346
|
}
|
|
376
347
|
}
|
|
377
348
|
}
|
|
378
|
-
|
|
379
349
|
useEffect(() => {
|
|
380
350
|
fetchUserData(access_token)
|
|
381
351
|
}, [access_token])
|
|
382
|
-
|
|
383
352
|
return (
|
|
384
353
|
<ThemeProvider theme={themeMui}>
|
|
385
354
|
<Formik
|
|
@@ -387,8 +356,8 @@ export const BillingInfoContainer = ({
|
|
|
387
356
|
dataWithUniqueIds,
|
|
388
357
|
{
|
|
389
358
|
...initialValues,
|
|
390
|
-
country: _get(userData, 'country', '') ||
|
|
391
|
-
state: _get(userData, 'state', '') ||
|
|
359
|
+
country: _get(userData, 'country', '') || '1',
|
|
360
|
+
state: _get(userData, 'state', '') || '1',
|
|
392
361
|
brand_opt_in: optedInFieldValue,
|
|
393
362
|
ttf_opt_in: ttfOptIn,
|
|
394
363
|
},
|
|
@@ -425,7 +394,6 @@ export const BillingInfoContainer = ({
|
|
|
425
394
|
)
|
|
426
395
|
return
|
|
427
396
|
}
|
|
428
|
-
|
|
429
397
|
const checkoutBodyForRegistration = createCheckoutDataBody(
|
|
430
398
|
ticketsQuantity.length,
|
|
431
399
|
values,
|
|
@@ -436,7 +404,6 @@ export const BillingInfoContainer = ({
|
|
|
436
404
|
values,
|
|
437
405
|
checkoutBodyForRegistration
|
|
438
406
|
)
|
|
439
|
-
|
|
440
407
|
let access_token_register = null
|
|
441
408
|
try {
|
|
442
409
|
const resRegister = await register(bodyFormData)
|
|
@@ -449,12 +416,10 @@ export const BillingInfoContainer = ({
|
|
|
449
416
|
'data.data.attributes.refresh_token'
|
|
450
417
|
)
|
|
451
418
|
handleSetAccessToken(access_token_register)
|
|
452
|
-
|
|
453
419
|
const tokens = {
|
|
454
420
|
accessToken: access_token_register,
|
|
455
421
|
refreshToken,
|
|
456
422
|
}
|
|
457
|
-
|
|
458
423
|
onRegisterSuccess(tokens)
|
|
459
424
|
} catch (e) {
|
|
460
425
|
if (axios.isAxiosError(e)) {
|
|
@@ -462,7 +427,6 @@ export const BillingInfoContainer = ({
|
|
|
462
427
|
if (_includes(error, 'You must be aged')) {
|
|
463
428
|
formikHelpers.setFieldError('holderAge', error)
|
|
464
429
|
}
|
|
465
|
-
|
|
466
430
|
if (error?.password) {
|
|
467
431
|
formikHelpers.setFieldError('password', error.password)
|
|
468
432
|
formikHelpers.setFieldError(
|
|
@@ -470,7 +434,6 @@ export const BillingInfoContainer = ({
|
|
|
470
434
|
error.password
|
|
471
435
|
)
|
|
472
436
|
}
|
|
473
|
-
|
|
474
437
|
if (error?.email && !onLogin) {
|
|
475
438
|
// False will stand for outside controll
|
|
476
439
|
setAlreadyHasUser(true)
|
|
@@ -480,7 +443,6 @@ export const BillingInfoContainer = ({
|
|
|
480
443
|
}
|
|
481
444
|
return
|
|
482
445
|
}
|
|
483
|
-
|
|
484
446
|
const profileData = await getProfileData(access_token_register)
|
|
485
447
|
const profileSpecifiedData = _get(profileData, 'data.data')
|
|
486
448
|
const profileDataObj = setLoggedUserData(profileSpecifiedData)
|
|
@@ -490,7 +452,6 @@ export const BillingInfoContainer = ({
|
|
|
490
452
|
JSON.stringify(profileDataObj)
|
|
491
453
|
)
|
|
492
454
|
}
|
|
493
|
-
|
|
494
455
|
const checkoutBody = createCheckoutDataBody(
|
|
495
456
|
ticketsQuantity.length,
|
|
496
457
|
values,
|
|
@@ -542,7 +503,7 @@ export const BillingInfoContainer = ({
|
|
|
542
503
|
onGetStatesError={onGetStatesError}
|
|
543
504
|
/>
|
|
544
505
|
<div className={`billing-info-container ${theme}`}>
|
|
545
|
-
{error && (
|
|
506
|
+
{error && !hideErrorsAlertSection && (
|
|
546
507
|
<Alert severity="error" onClose={onErrorClose} variant="filled">
|
|
547
508
|
{error}
|
|
548
509
|
</Alert>
|
|
@@ -653,49 +614,51 @@ export const BillingInfoContainer = ({
|
|
|
653
614
|
</React.Fragment>
|
|
654
615
|
)
|
|
655
616
|
})}
|
|
656
|
-
|
|
657
|
-
<
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
<
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
<div
|
|
666
|
-
{
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
617
|
+
{!_isEmpty(ticketHoldersFields.fields) && (
|
|
618
|
+
<div className="ticket-holders-fields">
|
|
619
|
+
<p>{ticketHoldersFields.label}</p>
|
|
620
|
+
{_map(ticketsQuantity, (_item, index) => (
|
|
621
|
+
<div key={_item}>
|
|
622
|
+
<h5>Ticket {index + 1}</h5>
|
|
623
|
+
{_map(ticketHoldersFields.fields, group => {
|
|
624
|
+
const { groupClassname, groupItems } = group
|
|
625
|
+
return (
|
|
626
|
+
<div key={group.id}>
|
|
627
|
+
<div className={groupClassname}>
|
|
628
|
+
{_map(groupItems, element => (
|
|
629
|
+
<div
|
|
630
|
+
className={element.className}
|
|
631
|
+
key={element.name}
|
|
632
|
+
>
|
|
633
|
+
<Field
|
|
634
|
+
name={`${element.name}-${index}`}
|
|
635
|
+
label={element.label}
|
|
636
|
+
type={element.type}
|
|
637
|
+
required={true}
|
|
638
|
+
component={
|
|
639
|
+
element.type === 'checkbox'
|
|
640
|
+
? CheckboxField
|
|
641
|
+
: CustomField
|
|
642
|
+
}
|
|
643
|
+
validate={combineValidators(
|
|
644
|
+
element.required
|
|
645
|
+
? requiredValidator
|
|
646
|
+
: () => {},
|
|
647
|
+
element.onValidate
|
|
648
|
+
? element.onValidate
|
|
649
|
+
: () => {}
|
|
650
|
+
)}
|
|
651
|
+
/>
|
|
652
|
+
</div>
|
|
653
|
+
))}
|
|
654
|
+
</div>
|
|
692
655
|
</div>
|
|
693
|
-
|
|
694
|
-
)
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
656
|
+
)
|
|
657
|
+
})}
|
|
658
|
+
</div>
|
|
659
|
+
))}
|
|
660
|
+
</div>
|
|
661
|
+
)}
|
|
699
662
|
<div className="button-container">
|
|
700
663
|
<Button
|
|
701
664
|
type="submit"
|
|
@@ -59,23 +59,26 @@ export const CustomField = ({
|
|
|
59
59
|
className: theme,
|
|
60
60
|
MenuProps: { className: theme },
|
|
61
61
|
}}
|
|
62
|
-
InputLabelProps={{
|
|
62
|
+
InputLabelProps={{
|
|
63
|
+
sx: customTheme?.input,
|
|
64
|
+
shrink: field.name === 'holderAge' ? true : undefined,
|
|
65
|
+
}}
|
|
63
66
|
inputProps={{
|
|
64
|
-
sx: customTheme?.input
|
|
67
|
+
sx: customTheme?.input,
|
|
65
68
|
}}
|
|
66
69
|
{...field}
|
|
67
70
|
>
|
|
68
71
|
{isSelectField
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
? _map(selectOptions, option => (
|
|
73
|
+
<option
|
|
74
|
+
key={option.value}
|
|
75
|
+
value={option.value}
|
|
76
|
+
disabled={option.disabled}
|
|
77
|
+
>
|
|
78
|
+
{option.label}
|
|
79
|
+
</option>
|
|
80
|
+
))
|
|
81
|
+
: null}
|
|
79
82
|
</TextField>
|
|
80
83
|
)
|
|
81
84
|
}
|
|
@@ -351,7 +351,7 @@ export const TicketsContainer = ({
|
|
|
351
351
|
isAccessCodeEnabled={isAccessCodeEnabled}
|
|
352
352
|
isAllTicketsSoldOut={isAllTicketsSoldOut}
|
|
353
353
|
/>
|
|
354
|
-
{isTicketOnSale && (
|
|
354
|
+
{(isTicketOnSale || !event?.salesEnded) && (
|
|
355
355
|
<Button
|
|
356
356
|
aria-hidden={true}
|
|
357
357
|
className={`book-button ${
|
|
@@ -33,8 +33,14 @@ const generateQuantity = (n: number) => {
|
|
|
33
33
|
}
|
|
34
34
|
return quantityList
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
const WaitingList = ({ tickets = {}, eventId }: WaitingListProps) => {
|
|
38
|
+
const isWindowDefined = typeof window !== 'undefined'
|
|
39
|
+
const userData =
|
|
40
|
+
isWindowDefined && window.localStorage.getItem('user_data')
|
|
41
|
+
? JSON.parse(window.localStorage.getItem('user_data') || '')
|
|
42
|
+
: {}
|
|
43
|
+
|
|
38
44
|
const [showSuccessMessage, setShowSuccessMessage] = useState(false)
|
|
39
45
|
const [loading, setLoading] = useState(false)
|
|
40
46
|
const ticketTypesList = Object.values(tickets).map((d: any) => ({
|
|
@@ -77,9 +83,9 @@ const WaitingList = ({ tickets = {}, eventId }: WaitingListProps) => {
|
|
|
77
83
|
initialValues={{
|
|
78
84
|
ticketTypeId: '',
|
|
79
85
|
quantity: '',
|
|
80
|
-
firstName: '',
|
|
81
|
-
lastName: '',
|
|
82
|
-
email: '',
|
|
86
|
+
firstName: userData.first_name || '',
|
|
87
|
+
lastName: userData.last_name || '',
|
|
88
|
+
email: userData.email || '',
|
|
83
89
|
}}
|
|
84
90
|
onSubmit={handleSubmit}
|
|
85
91
|
>
|