tf-checkout-react 1.2.2 → 1.2.3

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.2",
2
+ "version": "1.2.3",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/src/api/index.ts CHANGED
@@ -161,13 +161,14 @@ export const handleSetAccessToken = (token: string) => {
161
161
  }
162
162
 
163
163
  export function getEvent(id: string | number) {
164
- let referralValue = ""
164
+ let referralValue = ''
165
165
  if (isWindowDefined) {
166
166
  const params = new URL(`${window.location}`)
167
167
  const referralId = params.searchParams.get('ttf_r') || ''
168
168
  const referral_key = window.localStorage.getItem('referral_key')
169
- let referralIdlocal = ""
169
+ let referralIdlocal = ''
170
170
  if (referral_key) {
171
+ // eslint-disable-next-line prefer-destructuring
171
172
  referralIdlocal = referral_key.split('.')[1]
172
173
  }
173
174
  referralValue = referralId || referralIdlocal
@@ -175,10 +176,12 @@ export function getEvent(id: string | number) {
175
176
 
176
177
  const response = publicRequest
177
178
  .get(`v1/event/${id}`, {
178
- headers: { ...ttfHeaders,
179
- "Referer-Url": isDocumentDefined ? document.referrer : '',
180
- "Referrer-Id": isWindowDefined ? referralValue : ''
181
- } })
179
+ headers: {
180
+ ...ttfHeaders,
181
+ 'Referer-Url': isDocumentDefined ? document.referrer : '',
182
+ 'Referrer-Id': isWindowDefined ? referralValue : '',
183
+ },
184
+ })
182
185
  .catch(error => {
183
186
  throw error
184
187
  })
@@ -203,12 +206,15 @@ export function getTickets(id: string | number, promoCode: string) {
203
206
  }
204
207
 
205
208
  export const addToCart = (id: string | number, data: any) => {
206
- const res = publicRequest.post(`v1/event/${id}/add-to-cart/`, {
207
- data,
208
- headers: {
209
- "Referer-Url": isDocumentDefined ? document.referrer : '',
209
+ const res = publicRequest.post(
210
+ `v1/event/${id}/add-to-cart/`,
211
+ { data },
212
+ {
213
+ headers: {
214
+ 'Referer-Url': isDocumentDefined ? document.referrer : '',
215
+ },
210
216
  }
211
- })
217
+ )
212
218
  return res
213
219
  }
214
220
 
@@ -247,8 +253,8 @@ export const getPaymentData = (hash: string) => {
247
253
  const response = publicRequest
248
254
  .get(`v1/order/${hash}/review/`, {
249
255
  headers: {
250
- "Referer-Url": isDocumentDefined ? document.referrer : '' ,
251
- }
256
+ 'Referer-Url': isDocumentDefined ? document.referrer : '',
257
+ },
252
258
  })
253
259
  .catch(error => {
254
260
  throw error
@@ -269,10 +275,10 @@ export const handlePaymentData = (orderHash: string, data: any) => {
269
275
 
270
276
  export const handlePaymentSuccess = (orderHash: string) => {
271
277
  const res = publicRequest
272
- .post(`v1/order/${orderHash}/success`, {
278
+ .post(`v1/order/${orderHash}/success`, undefined, {
273
279
  headers: {
274
- "Referer-Url": isDocumentDefined ? document.referrer : ''
275
- }
280
+ 'Referer-Url': isDocumentDefined ? document.referrer : '',
281
+ },
276
282
  })
277
283
  .catch(error => {
278
284
  throw error
@@ -282,10 +288,10 @@ export const handlePaymentSuccess = (orderHash: string) => {
282
288
 
283
289
  export const handleFreeSuccess = (orderHash: string) => {
284
290
  const res = publicRequest
285
- .post(`v1/order/${orderHash}/complete_free_registration`, {
291
+ .post(`v1/order/${orderHash}/complete_free_registration`, undefined, {
286
292
  headers: {
287
- "Referer-Url": isDocumentDefined ? document.referrer : ''
288
- }
293
+ 'Referer-Url': isDocumentDefined ? document.referrer : '',
294
+ },
289
295
  })
290
296
  .catch(error => {
291
297
  throw error
@@ -3,7 +3,7 @@ import './style.css'
3
3
  import { CircularProgress, ThemeOptions } from '@mui/material'
4
4
  import Backdrop from '@mui/material/Backdrop'
5
5
  import Button from '@mui/material/Button'
6
- import { createTheme,ThemeProvider } from '@mui/material/styles'
6
+ import { createTheme, ThemeProvider } from '@mui/material/styles'
7
7
  import { CSSProperties } from '@mui/styles'
8
8
  import axios, { AxiosError } from 'axios'
9
9
  import {
@@ -21,7 +21,7 @@ import _isEmpty from 'lodash/isEmpty'
21
21
  import _isEqual from 'lodash/isEqual'
22
22
  import _map from 'lodash/map'
23
23
  import { nanoid } from 'nanoid'
24
- import React, { FC, useEffect, useRef,useState } from 'react'
24
+ import React, { FC, useEffect, useRef, useState } from 'react'
25
25
 
26
26
  import {
27
27
  getCart,
@@ -33,12 +33,20 @@ import {
33
33
  setCustomHeader,
34
34
  } from '../../api'
35
35
  import { IBillingInfoData } from '../../types'
36
- import { createCheckoutDataBodyWithDefaultHolder, getCookieByName } from '../../utils'
36
+ import {
37
+ createCheckoutDataBodyWithDefaultHolder,
38
+ getCookieByName,
39
+ } from '../../utils'
37
40
  import { ErrorFocus } from '../../utils/formikErrorFocus'
38
41
  import { getQueryVariable } from '../../utils/getQueryVariable'
39
42
  import { combineValidators, requiredValidator } from '../../validators'
40
43
  import { DatePickerField } from '../common/DatePickerField'
41
- import { CheckboxField, CustomField, PhoneNumberField,SelectField } from '../common/index'
44
+ import {
45
+ CheckboxField,
46
+ CustomField,
47
+ PhoneNumberField,
48
+ SelectField,
49
+ } from '../common/index'
42
50
  import SnackbarAlert from '../common/SnackbarAlert'
43
51
  import { ForgotPasswordModal } from '../forgotPasswordModal'
44
52
  import { LoginModal } from '../loginModal'
@@ -169,8 +177,10 @@ const LogicRunner: FC<{
169
177
  city: parsedData?.city || '',
170
178
  confirmPassword: '',
171
179
  password: '',
172
- 'holderFirstName-0': parsedData?.first_name || parsedData?.firstName || '',
173
- 'holderLastName-0': parsedData?.last_name || parsedData?.lastName || '',
180
+ 'holderFirstName-0':
181
+ parsedData?.first_name || parsedData?.firstName || '',
182
+ 'holderLastName-0':
183
+ parsedData?.last_name || parsedData?.lastName || '',
174
184
  'holderEmail-0': parsedData?.email || '',
175
185
  }
176
186
  setValues({ ...values, ...mappedValues })
@@ -225,7 +235,7 @@ export const BillingInfoContainer = ({
225
235
  enableTimer = false,
226
236
  logo,
227
237
  showForgotPasswordButton = false,
228
- showSignUpButton = false
238
+ showSignUpButton = false,
229
239
  }: IBillingInfoPage) => {
230
240
  const themeMui = createTheme(themeOptions)
231
241
  const isWindowDefined = typeof window !== 'undefined'
@@ -306,7 +316,7 @@ export const BillingInfoContainer = ({
306
316
  }
307
317
 
308
318
  useEffect(() => {
309
- if ((pIsLoggedIn !== isLoggedIn) || xtfCookie) {
319
+ if (pIsLoggedIn !== isLoggedIn || xtfCookie) {
310
320
  setIsLoggedIn(!!(pIsLoggedIn || xtfCookie))
311
321
  }
312
322
  }, [pIsLoggedIn, isLoggedIn, xtfCookie])
@@ -363,10 +373,7 @@ export const BillingInfoContainer = ({
363
373
  firstName: profileDataObj.first_name,
364
374
  lastName: profileDataObj.last_name,
365
375
  })
366
- window.localStorage.setItem(
367
- 'user_data',
368
- JSON.stringify(profileDataObj)
369
- )
376
+ window.localStorage.setItem('user_data', JSON.stringify(profileDataObj))
370
377
  onGetProfileDataSuccess(userDataResponse.data)
371
378
  }
372
379
  } catch (e) {
@@ -403,8 +410,10 @@ export const BillingInfoContainer = ({
403
410
  collectPaymentData()
404
411
  }, [skipPage, ticketsQuantity])
405
412
 
406
-
407
- const collectCheckoutBody = (values: Record<string, unknown>, profileData?: any): Record<string, unknown> => {
413
+ const collectCheckoutBody = (
414
+ values: Record<string, unknown>,
415
+ profileData?: any
416
+ ): Record<string, unknown> => {
408
417
  let checkoutBody = {}
409
418
 
410
419
  // Auto collect ticket holders name when it was skipped optionally
@@ -413,7 +422,7 @@ export const BillingInfoContainer = ({
413
422
  ticketsQuantity.length,
414
423
  values,
415
424
  true,
416
- { emailLogged, firstNameLogged, lastNameLogged },
425
+ { emailLogged, firstNameLogged, lastNameLogged }
417
426
  )
418
427
  } else {
419
428
  checkoutBody = createCheckoutDataBody(
@@ -421,8 +430,10 @@ export const BillingInfoContainer = ({
421
430
  values,
422
431
  {
423
432
  emailLogged: emailLogged || profileData.email,
424
- firstNameLogged: firstNameLogged || profileData.first_name || profileData.firstName,
425
- lastNameLogged: lastNameLogged || profileData.last_name || profileData.lastName,
433
+ firstNameLogged:
434
+ firstNameLogged || profileData.first_name || profileData.firstName,
435
+ lastNameLogged:
436
+ lastNameLogged || profileData.last_name || profileData.lastName,
426
437
  },
427
438
  showDOB
428
439
  )
@@ -435,7 +446,10 @@ export const BillingInfoContainer = ({
435
446
  localStorage.removeItem('referral_key')
436
447
  }
437
448
 
438
- if (loading || (enableTimer && !expirationTime && typeof window !== 'undefined')) {
449
+ if (
450
+ loading ||
451
+ (enableTimer && !expirationTime && typeof window !== 'undefined')
452
+ ) {
439
453
  if (expirationTime === 0) {
440
454
  // Redirect to homepage (countdown finished and browser reloaded case)
441
455
  window.location.href = '/'
@@ -511,15 +525,24 @@ export const BillingInfoContainer = ({
511
525
  setLoading(true)
512
526
  const resRegister = await register(bodyFormData)
513
527
  const xtfCookie = _get(resRegister, 'headers.x-tf-ecommerce')
514
- const accessToken = _get(resRegister, 'data.data.attributes.access_token')
515
- const refreshToken = _get(resRegister, 'data.data.attributes.refresh_token')
516
- const userProfile = _get(resRegister, 'data.data.attributes.user_profile')
528
+ const accessToken = _get(
529
+ resRegister,
530
+ 'data.data.attributes.access_token'
531
+ )
532
+ const refreshToken = _get(
533
+ resRegister,
534
+ 'data.data.attributes.refresh_token'
535
+ )
536
+ const userProfile = _get(
537
+ resRegister,
538
+ 'data.data.attributes.user_profile'
539
+ )
517
540
 
518
541
  onRegisterSuccess({
519
542
  xtfCookie,
520
543
  accessToken,
521
544
  refreshToken,
522
- userProfile
545
+ userProfile,
523
546
  })
524
547
  } catch (e) {
525
548
  setLoading(false)
@@ -657,7 +680,6 @@ export const BillingInfoContainer = ({
657
680
  const { groupClassname, groupItems } = group
658
681
  return (
659
682
  <React.Fragment key={group.uniqueId}>
660
-
661
683
  <div className={groupClassname}>
662
684
  {_map(
663
685
  groupItems.filter(el => {
@@ -678,7 +700,7 @@ export const BillingInfoContainer = ({
678
700
  'confirmPassword',
679
701
  'password-info',
680
702
  ].includes(element.name) &&
681
- isLoggedIn ? null : (
703
+ isLoggedIn ? null : (
682
704
  <React.Fragment key={element.uniqueId}>
683
705
  <div className={element.className}>
684
706
  {element.component ? (
@@ -686,9 +708,15 @@ export const BillingInfoContainer = ({
686
708
  ) : (
687
709
  <Field
688
710
  name={element.name}
689
- label={element.name === 'phone'
690
- ? `${element.label}${flagRequirePhone ? '' : ' (optional)'} `
691
- : element.label}
711
+ label={
712
+ element.name === 'phone'
713
+ ? `${element.label}${
714
+ flagRequirePhone
715
+ ? ''
716
+ : ' (optional)'
717
+ } `
718
+ : element.label
719
+ }
692
720
  type={element.type}
693
721
  validate={getValidateFunctions(
694
722
  element,
@@ -712,11 +740,13 @@ export const BillingInfoContainer = ({
712
740
  element.name === 'country'
713
741
  ? countries
714
742
  : element.name === 'state'
715
- ? states
716
- : []
743
+ ? states
744
+ : []
717
745
  }
718
746
  theme={theme}
719
- disableDropdown={element.disableDropdown}
747
+ disableDropdown={
748
+ element.disableDropdown
749
+ }
720
750
  />
721
751
  )}
722
752
  </div>
@@ -761,10 +791,16 @@ export const BillingInfoContainer = ({
761
791
  validate={combineValidators(
762
792
  element.required
763
793
  ? requiredValidator
764
- : () => {},
794
+ : () =>
795
+ props.errors[
796
+ `${element.name}-${index}`
797
+ ],
765
798
  element.onValidate
766
799
  ? element.onValidate
767
- : () => {}
800
+ : () =>
801
+ props.errors[
802
+ `${element.name}-${index}`
803
+ ]
768
804
  )}
769
805
  disableDropdown={element.disableDropdown}
770
806
  />
@@ -71,6 +71,7 @@ export interface IPaymentPage {
71
71
  onCountdownFinish?: () => void;
72
72
  enableTimer?: boolean;
73
73
  enablePaymentPlan?: boolean;
74
+ paymentButtonText?: string;
74
75
  }
75
76
 
76
77
  const initialOrderValues: IOrderData = {
@@ -98,16 +99,17 @@ export const PaymentContainer = ({
98
99
  errorText,
99
100
  checkoutData,
100
101
  onErrorClose = _identity,
101
- onGetPaymentDataSuccess = () => {},
102
- onGetPaymentDataError = () => {},
103
- onPaymentError = () => {},
102
+ onGetPaymentDataSuccess = () => { },
103
+ onGetPaymentDataError = () => { },
104
+ onPaymentError = () => { },
104
105
  stripeCardOptions = {},
105
106
  disableZipSection = false,
106
107
  themeOptions,
107
108
  elementsOptions,
108
- onCountdownFinish = () => {},
109
+ onCountdownFinish = () => { },
109
110
  enableTimer = false,
110
111
  enablePaymentPlan = false,
112
+ paymentButtonText
111
113
  }: IPaymentPage) => {
112
114
  const [reviewData, setReviewData] = useState(initialReviewValues)
113
115
  const [orderData, setOrderData] = useState(initialOrderValues)
@@ -166,10 +168,10 @@ export const PaymentContainer = ({
166
168
  setConditions(
167
169
  conditionsInfo
168
170
  ? conditionsInfo.map((item: string) => ({
169
- id: nanoid(),
170
- text: item,
171
- checked: false,
172
- }))
171
+ id: nanoid(),
172
+ text: item,
173
+ checked: false,
174
+ }))
173
175
  : []
174
176
  )
175
177
  }
@@ -316,15 +318,15 @@ export const PaymentContainer = ({
316
318
  conditions={conditions}
317
319
  stripeCardOptions={stripeCardOptions}
318
320
  disableZipSection={disableZipSection}
321
+ paymentButtonText={paymentButtonText}
319
322
  />
320
323
  </Elements>
321
324
  </div>
322
325
  </div>
323
326
  ) : (
324
327
  <div
325
- className={`payment_button ${
326
- paymentIsLoading ? 'disabled-payment-button' : ''
327
- }`}
328
+ className={`payment_button ${paymentIsLoading ? 'disabled-payment-button' : ''
329
+ }`}
328
330
  >
329
331
  <button
330
332
  disabled={paymentIsLoading}
@@ -47,6 +47,7 @@ export interface ICheckoutForm {
47
47
  handleSetLoading: (loading: any) => void;
48
48
  conditions: any;
49
49
  disableZipSection: boolean;
50
+ paymentButtonText?: string;
50
51
  }
51
52
 
52
53
  interface AddressTypes {
@@ -65,9 +66,10 @@ const CheckoutForm = ({
65
66
  currency,
66
67
  billing_info,
67
68
  isLoading = false,
68
- handleSetLoading = () => {},
69
+ handleSetLoading = () => { },
69
70
  conditions = [],
70
71
  disableZipSection,
72
+ paymentButtonText
71
73
  }: ICheckoutForm) => {
72
74
  const stripe = useStripe()
73
75
  const elements = useElements()
@@ -101,7 +103,7 @@ const CheckoutForm = ({
101
103
  line1: billing_info.street_address,
102
104
  state: billing_info.state,
103
105
  }
104
-
106
+
105
107
  if (!disableZipSection) {
106
108
  address.postal_code = postalCode
107
109
  }
@@ -244,7 +246,7 @@ const CheckoutForm = ({
244
246
  {isLoading ? (
245
247
  <CircularProgress size={26} />
246
248
  ) : (
247
- `Pay ${getCurrencySymbolByCurrency(currency)}${total}`
249
+ `${paymentButtonText ? paymentButtonText : 'Pay'} ${getCurrencySymbolByCurrency(currency)}${total}`
248
250
  )}
249
251
  </button>
250
252
  </div>