tf-checkout-react 1.0.80 → 1.0.84

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.0.80",
2
+ "version": "1.0.84",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/src/api/index.ts CHANGED
@@ -224,8 +224,9 @@ export const getProfileData = (accessToken: any) =>
224
224
  },
225
225
  })
226
226
  .catch((e: any) => {
227
+ const errorType = e?.response?.data?.error
227
228
  if (isWindowDefined) {
228
- const event = new window.CustomEvent('auth_error', e)
229
+ const event = new window.CustomEvent('auth_error', { detail: errorType })
229
230
  window.document.dispatchEvent(event)
230
231
  }
231
232
  return e
@@ -13,6 +13,7 @@ import _identity from 'lodash/identity'
13
13
  import _map from 'lodash/map'
14
14
  import _get from 'lodash/get'
15
15
  import _includes from 'lodash/includes'
16
+ import _isEqual from 'lodash/isEqual'
16
17
 
17
18
  import './style.css'
18
19
  import { combineValidators, requiredValidator } from '../../validators'
@@ -26,6 +27,7 @@ import {
26
27
  register,
27
28
  setCustomHeader,
28
29
  getStates,
30
+ getPaymentData,
29
31
  } from '../../api'
30
32
  import { LoginModal } from '../loginModal'
31
33
  import { RegisterModal } from '../registerModal'
@@ -40,7 +42,7 @@ import {
40
42
  import { CustomField } from '../common/CustomField'
41
43
  import axios from 'axios'
42
44
  import { CheckboxField } from '../common/CheckboxField'
43
- import { CircularProgress, ThemeOptions } from '@mui/material'
45
+ import { Alert, CircularProgress, ThemeOptions } from '@mui/material'
44
46
  import { nanoid } from 'nanoid'
45
47
  import { getQueryVariable } from '../../utils/getQueryVariable'
46
48
  import { SelectField } from '../common/SelectField'
@@ -90,6 +92,7 @@ export interface IBillingInfoPage {
90
92
 
91
93
  onLogin?: () => void;
92
94
  onLoginSuccess?: () => void;
95
+ onErrorClose?: () => void;
93
96
 
94
97
  initialValues?: FormikValues;
95
98
  buttonName?: string;
@@ -115,7 +118,7 @@ const LogicRunner: FC<{
115
118
  setValues,
116
119
  setUserValues,
117
120
  onGetStatesSuccess,
118
- onGetStatesError,
121
+ onGetStatesError
119
122
  }) => {
120
123
  const prevCountry = useRef(values.country)
121
124
  useEffect(() => {
@@ -209,7 +212,8 @@ export const BillingInfoContainer = ({
209
212
  isLoggedIn: pIsLoggedIn = false,
210
213
  accountInfoTitle = '',
211
214
  hideLogo,
212
- themeOptions
215
+ themeOptions,
216
+ onErrorClose = () => {}
213
217
  }: IBillingInfoPage) => {
214
218
  const themeMui = createTheme(themeOptions)
215
219
  const isWindowDefined = typeof window !== 'undefined'
@@ -250,6 +254,7 @@ export const BillingInfoContainer = ({
250
254
  state: '',
251
255
  zip: '',
252
256
  })
257
+ const [error, setError] = useState(null)
253
258
  const emailLogged =
254
259
  _get(userData, 'email', '') || _get(userValues, 'email', '')
255
260
  const firstNameLogged =
@@ -260,12 +265,23 @@ export const BillingInfoContainer = ({
260
265
  const showDOB = getQueryVariable('age_required') === 'true'
261
266
  const eventId = getQueryVariable('event_id')
262
267
  const optedInFieldValue: boolean = _get(cartInfoData, 'optedIn', false)
268
+ const ttfOptIn: boolean = _get(cartInfoData, 'ttfOptIn', false)
263
269
  const hideTtfOptIn: boolean = _get(cartInfoData, 'hide_ttf_opt_in', true)
264
270
 
265
- if (!_get(dataWithUniqueIds, '[0].uniqueId')) {
266
- setDataWithUniqueIds(assingUniqueIds(data))
267
- }
268
-
271
+ // Get prevProps
272
+ const prevData = useRef(data)
273
+
274
+ useEffect(() => {
275
+ const hasUniqueId = _get(dataWithUniqueIds, '[0].uniqueId')
276
+ const isEqualData = _isEqual(prevData.current, data)
277
+ if (!hasUniqueId || !isEqualData) {
278
+ setDataWithUniqueIds(assingUniqueIds(data))
279
+ if (!isEqualData) {
280
+ prevData.current = data
281
+ }
282
+ }
283
+ }, [dataWithUniqueIds, data])
284
+
269
285
  const getQuantity = (cart: any = []) => {
270
286
  let qty: any = 0
271
287
  cart.forEach((item: any) => {
@@ -274,8 +290,11 @@ export const BillingInfoContainer = ({
274
290
  return qty
275
291
  }
276
292
 
277
- const handleAuthErrors = useCallback(() => {
293
+ const handleAuthErrors = useCallback((e) => {
278
294
  setIsLoggedIn(false)
295
+ if (isWindowDefined && e?.detail === 'invalid_token') {
296
+ window.location.href = '/'
297
+ }
279
298
  }, [])
280
299
 
281
300
  useEffect(() => {
@@ -371,6 +390,7 @@ export const BillingInfoContainer = ({
371
390
  country: _get(userData, 'country', '') || "1",
372
391
  state: _get(userData, 'state', '') || "1",
373
392
  brand_opt_in: optedInFieldValue,
393
+ ttf_opt_in: ttfOptIn,
374
394
  },
375
395
  userValues
376
396
  )}
@@ -396,6 +416,7 @@ export const BillingInfoContainer = ({
396
416
  showDOB
397
417
  )
398
418
  const res = await postOnCheckout(checkoutBody, access_token)
419
+ await getPaymentData(res.data.data.attributes.hash)
399
420
  handleSubmit(
400
421
  values,
401
422
  formikHelpers as FormikHelpers<any>,
@@ -480,6 +501,7 @@ export const BillingInfoContainer = ({
480
501
  checkoutBody,
481
502
  access_token_register
482
503
  )
504
+ await getPaymentData(res.data.data.attributes.hash)
483
505
  handleSubmit(
484
506
  values,
485
507
  formikHelpers as FormikHelpers<any>,
@@ -496,6 +518,12 @@ export const BillingInfoContainer = ({
496
518
  setShowModalLogin(true)
497
519
  }
498
520
  }
521
+ if (e.response?.data.message) {
522
+ if (typeof document !== undefined) {
523
+ document.body.scrollTop = document.documentElement.scrollTop = 0
524
+ }
525
+ setError(_get(e, 'response.data.message'))
526
+ }
499
527
  onSubmitError(e)
500
528
  }
501
529
  }
@@ -514,6 +542,11 @@ export const BillingInfoContainer = ({
514
542
  onGetStatesError={onGetStatesError}
515
543
  />
516
544
  <div className={`billing-info-container ${theme}`}>
545
+ {error && (
546
+ <Alert severity="error" onClose={onErrorClose} variant="filled">
547
+ {error}
548
+ </Alert>
549
+ )}
517
550
  {!isLoggedIn && (
518
551
  <div className="account-actions-block">
519
552
  <div>{accountInfoTitle}</div>
@@ -628,12 +661,12 @@ export const BillingInfoContainer = ({
628
661
  {_map(ticketHoldersFields.fields, group => {
629
662
  const { groupClassname, groupItems } = group
630
663
  return (
631
- <div key={group.uniqueId}>
664
+ <div key={group.id}>
632
665
  <div className={groupClassname}>
633
666
  {_map(groupItems, element => (
634
667
  <div
635
668
  className={element.className}
636
- key={element.uniqueId}
669
+ key={element.name}
637
670
  >
638
671
  <Field
639
672
  name={`${element.name}-${index}`}
@@ -695,7 +728,10 @@ export const BillingInfoContainer = ({
695
728
  userExpired={userExpired}
696
729
  onAuthorizeSuccess={onAuthorizeSuccess}
697
730
  onAuthorizeError={onAuthorizeError}
698
- onGetProfileDataSuccess={onGetProfileDataSuccess}
731
+ onGetProfileDataSuccess={(data: any) => {
732
+ fetchCart()
733
+ onGetProfileDataSuccess(data)
734
+ }}
699
735
  onGetProfileDataError={onGetProfileDataError}
700
736
  />
701
737
  )}
@@ -707,7 +743,10 @@ export const BillingInfoContainer = ({
707
743
  onRegister={() => {
708
744
  setShowModalRegister(false)
709
745
  }}
710
- onGetProfileDataSuccess={onGetProfileDataSuccess}
746
+ onGetProfileDataSuccess={(data: any) => {
747
+ fetchCart()
748
+ onGetProfileDataSuccess(data)
749
+ }}
711
750
  onGetProfileDataError={onGetProfileDataError}
712
751
  />
713
752
  )}
@@ -25,6 +25,7 @@ export const PromoCodeSection = ({
25
25
  setShowPromoInput,
26
26
  isAccessCodeEnabled,
27
27
  }: IPromoCodeSectionProps) => {
28
+ const isPromoCodeHasValue = !!promoCode.trim()
28
29
 
29
30
  const renderInputField = () => {
30
31
  return (
@@ -42,15 +43,19 @@ export const PromoCodeSection = ({
42
43
  setPromoCode(e.target.value)
43
44
  }}
44
45
  onKeyPress={event => {
45
- if (event.key === 'Enter') {
46
+ if (event.key === 'Enter' && isPromoCodeHasValue) {
46
47
  setPromoCodeUpdated(promoCode)
48
+ setShowPromoInput(false)
47
49
  }
48
50
  }}
49
51
  />
50
52
  <Button
51
53
  className="promo-submit-button"
52
54
  onClick={() => {
53
- setPromoCodeUpdated(promoCode)
55
+ if (isPromoCodeHasValue) {
56
+ setPromoCodeUpdated(promoCode)
57
+ setShowPromoInput(false)
58
+ }
54
59
  }}
55
60
  >
56
61
  {isAccessCodeEnabled ? 'ENTER' : 'APPLY'}
@@ -70,7 +75,7 @@ export const PromoCodeSection = ({
70
75
  <p className="promo-code-success">PROMO CODE APPLIED SUCCESSFULLY</p>
71
76
  </div>
72
77
  ) : null}
73
- {showPromoInput && !promoCodeIsApplied && (
78
+ {showPromoInput && (
74
79
  renderInputField()
75
80
  )}
76
81
  {isPromotionsEnabled && !showPromoInput && !isAccessCodeEnabled ? (
@@ -57,6 +57,7 @@ export interface IGetTickets {
57
57
  isPromotionsEnabled?: boolean;
58
58
  themeOptions?: ThemeOptions & { input?: CSSProperties; checkbox?: CSSProperties }
59
59
  isAccessCodeEnabled?: boolean;
60
+ hideSessionButtons?: boolean;
60
61
  }
61
62
 
62
63
  export interface ITicket {
@@ -82,6 +83,7 @@ export const TicketsContainer = ({
82
83
  isPromotionsEnabled = true,
83
84
  themeOptions,
84
85
  isAccessCodeEnabled = false,
86
+ hideSessionButtons = false
85
87
  }: IGetTickets) => {
86
88
  const [selectedTickets, setSelectedTickets] = useState(
87
89
  {} as ISelectedTickets
@@ -154,6 +156,7 @@ export const TicketsContainer = ({
154
156
  setTickets(_get(attributes, 'tickets'))
155
157
  setShowWaitingList(attributes.showWaitingList)
156
158
  onGetTicketsSuccess(response.data)
159
+ setPromoCode('')
157
160
  }
158
161
  if (eventResponse.data.success) {
159
162
  const event = _get(eventResponse, 'data.data.attributes')
@@ -363,7 +366,7 @@ export const TicketsContainer = ({
363
366
  {getTicketsLabel || 'GET TICKETS'}
364
367
  </Button>
365
368
  )}
366
- {isLogged ? (
369
+ {isLogged && !hideSessionButtons ? (
367
370
  <div className="session-wrapper">
368
371
  <span className="session-container">
369
372
  <Button
@@ -12,11 +12,19 @@ export const downloadPDF = (pdfUrl: string) => {
12
12
  })
13
13
  .then(async response => {
14
14
  const blobValue = await response.blob()
15
- return blobValue
15
+ const fileNameHeader = response.headers.get("content-disposition") || ''
16
+ const fileName = fileNameHeader.split('"')[1]
17
+ return { blobValue, fileName }
16
18
  })
17
- .then(blobValue => {
19
+ .then(({ blobValue, fileName }) => {
20
+ if (!fileName) return
18
21
  const file = new Blob([blobValue], { type: 'application/pdf' })
19
22
  const fileURL = URL.createObjectURL(file)
20
- window.open(fileURL)
23
+ const link = document.createElement('a')
24
+ link.href = fileURL
25
+ link.setAttribute('download', fileName)
26
+ document.body.appendChild(link)
27
+ link.click()
28
+ document.body.removeChild(link)
21
29
  })
22
30
  }