tf-checkout-react 1.0.52 → 1.0.56

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.52",
2
+ "version": "1.0.56",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -88,10 +88,12 @@ export interface IBillingInfoPage {
88
88
  onAuthorizeError?: (e: AxiosError) => void;
89
89
 
90
90
  onLogin?: () => void;
91
+ onLoginSuccess?: () => void;
91
92
 
92
93
  initialValues?: FormikValues;
93
94
  buttonName?: string;
94
95
  theme?: 'light' | 'dark';
96
+ isLoggedIn?: boolean;
95
97
  }
96
98
 
97
99
  const LogicRunner: FC<{
@@ -155,6 +157,9 @@ const LogicRunner: FC<{
155
157
  city: parsedData?.city || '',
156
158
  confirmPassword: '',
157
159
  password: '',
160
+ 'holderFirstName-0': parsedData?.first_name || '',
161
+ 'holderLastName-0': parsedData?.last_name || '',
162
+ 'holderEmail-0': parsedData?.email || '',
158
163
  }
159
164
  setValues(mappedValues)
160
165
  setUserValues(mappedValues)
@@ -192,13 +197,16 @@ export const BillingInfoContainer = ({
192
197
  onAuthorizeSuccess = () => {},
193
198
  onAuthorizeError = () => {},
194
199
  onLogin = () => {},
200
+ onLoginSuccess = () => {},
201
+ isLoggedIn: pIsLoggedIn = false,
195
202
  }: IBillingInfoPage) => {
203
+ const isWindowDefined = typeof window !== 'undefined'
196
204
  const userData =
197
- typeof window !== 'undefined' && window.localStorage.getItem('user_data')
205
+ isWindowDefined && window.localStorage.getItem('user_data')
198
206
  ? JSON.parse(window.localStorage.getItem('user_data') || '')
199
207
  : {}
200
208
  const access_token =
201
- typeof window !== 'undefined' && window.localStorage.getItem('access_token')
209
+ isWindowDefined && window.localStorage.getItem('access_token')
202
210
  ? window.localStorage.getItem('access_token') || ''
203
211
  : ''
204
212
 
@@ -206,6 +214,7 @@ export const BillingInfoContainer = ({
206
214
  IBillingInfoData[]
207
215
  >(data)
208
216
 
217
+ const [isLoggedIn, setIsLoggedIn] = useState(!!access_token)
209
218
  const [cartInfoData, setCartInfo] = useState<any>({})
210
219
  const [countries, setCountries] = useState<any>([])
211
220
  const [states, setStates] = useState<any>([])
@@ -229,7 +238,6 @@ export const BillingInfoContainer = ({
229
238
  state: '',
230
239
  zip: '',
231
240
  })
232
- const isLoggedIn = !!access_token
233
241
  const emailLogged =
234
242
  _get(userData, 'email', '') || _get(userValues, 'email', '')
235
243
  const firstNameLogged =
@@ -238,7 +246,6 @@ export const BillingInfoContainer = ({
238
246
  _get(userData, 'last_name', '') || _get(userValues, 'last_name', '')
239
247
 
240
248
  const showDOB = getQueryVariable('age_required') === 'true'
241
- const showTicketHolderName = getQueryVariable('names_required') === 'true'
242
249
  const eventId = getQueryVariable('event_id')
243
250
  const optedInFieldValue: boolean = _get(cartInfoData, 'optedIn', false)
244
251
  const hideTtfOptIn: boolean = _get(cartInfoData, 'hide_ttf_opt_in', true)
@@ -255,6 +262,12 @@ export const BillingInfoContainer = ({
255
262
  return qty
256
263
  }
257
264
 
265
+ useEffect(() => {
266
+ if ((pIsLoggedIn || access_token) && !isLoggedIn) {
267
+ setIsLoggedIn(true)
268
+ }
269
+ }, [pIsLoggedIn, isLoggedIn, access_token])
270
+
258
271
  //just once
259
272
  useEffect(() => {
260
273
  // fetch countries data
@@ -301,7 +314,7 @@ export const BillingInfoContainer = ({
301
314
  // fetch user data
302
315
  const fetchUserData = async (token: string) => {
303
316
  try {
304
- if (typeof window !== 'undefined' && token) {
317
+ if (isWindowDefined && token) {
305
318
  const userDataResponse = await getProfileData(token)
306
319
  const profileSpecifiedData = _get(userDataResponse, 'data.data')
307
320
  const profileDataObj = setLoggedUserData(profileSpecifiedData)
@@ -346,7 +359,7 @@ export const BillingInfoContainer = ({
346
359
  const updatedUserData = await getProfileData(access_token)
347
360
  const profileSpecifiedData = _get(updatedUserData, 'data.data')
348
361
  const profileDataObj = setLoggedUserData(profileSpecifiedData)
349
- if (typeof window !== 'undefined') {
362
+ if (isWindowDefined) {
350
363
  window.localStorage.setItem(
351
364
  'user_data',
352
365
  JSON.stringify(profileDataObj)
@@ -375,7 +388,10 @@ export const BillingInfoContainer = ({
375
388
  { emailLogged, firstNameLogged, lastNameLogged },
376
389
  showDOB
377
390
  )
378
- const bodyFormData = createRegisterFormData(values, checkoutBodyForRegistration)
391
+ const bodyFormData = createRegisterFormData(
392
+ values,
393
+ checkoutBodyForRegistration
394
+ )
379
395
 
380
396
  let access_token_register = null
381
397
  try {
@@ -423,7 +439,7 @@ export const BillingInfoContainer = ({
423
439
  const profileData = await getProfileData(access_token_register)
424
440
  const profileSpecifiedData = _get(profileData, 'data.data')
425
441
  const profileDataObj = setLoggedUserData(profileSpecifiedData)
426
- if (typeof window !== 'undefined') {
442
+ if (isWindowDefined) {
427
443
  window.localStorage.setItem(
428
444
  'user_data',
429
445
  JSON.stringify(profileDataObj)
@@ -449,7 +465,7 @@ export const BillingInfoContainer = ({
449
465
  } catch (e) {
450
466
  if (axios.isAxiosError(e)) {
451
467
  if (e.response?.data.error === 'invalid_token') {
452
- if (typeof window !== 'undefined') {
468
+ if (isWindowDefined) {
453
469
  window.localStorage.removeItem('user_data')
454
470
  window.localStorage.removeItem('access_token')
455
471
  setUserExpired(true)
@@ -499,45 +515,16 @@ export const BillingInfoContainer = ({
499
515
  )}
500
516
  {_map(dataWithUniqueIds, item => {
501
517
  const { label, labelClassName, fields } = item
502
- if (
503
- label === 'Ticket Holders' &&
504
- !showTicketHolderName &&
505
- !showDOB
506
- ) {
507
- return null
508
- }
509
518
  return (
510
519
  <React.Fragment key={item.uniqueId}>
511
520
  <p className={labelClassName}>{label}</p>
512
521
  {_map(fields, group => {
513
- const {
514
- groupClassname,
515
- groupItems,
516
- groupLabel,
517
- groupLabelClassName,
518
- } = group
522
+ const { groupClassname, groupItems } = group
519
523
  return (
520
524
  <React.Fragment key={group.uniqueId}>
521
- {!isLoggedIn && (
522
- <div className={groupLabelClassName}>
523
- {groupLabel}
524
- </div>
525
- )}
526
525
  <div className={groupClassname}>
527
526
  {_map(
528
527
  groupItems.filter(el => {
529
- if (
530
- el.name === 'holderFirstName' &&
531
- !showTicketHolderName
532
- ) {
533
- return false
534
- }
535
- if (
536
- el.name === 'holderLastName' &&
537
- !showTicketHolderName
538
- ) {
539
- return false
540
- }
541
528
  if (el.name === 'holderAge' && !showDOB) {
542
529
  return false
543
530
  }
@@ -547,9 +534,12 @@ export const BillingInfoContainer = ({
547
534
  return true
548
535
  }),
549
536
  element =>
550
- ['password', 'confirmPassword'].includes(
551
- element.name
552
- ) && isLoggedIn ? null : (
537
+ [
538
+ 'password',
539
+ 'confirmPassword',
540
+ 'password-info',
541
+ ].includes(element.name) &&
542
+ isLoggedIn ? null : (
553
543
  <React.Fragment key={element.uniqueId}>
554
544
  {element.name === 'email' ? (
555
545
  <div className="email-checking">
@@ -598,53 +588,49 @@ export const BillingInfoContainer = ({
598
588
  </React.Fragment>
599
589
  )
600
590
  })}
601
- {showTicketHolderName && (
602
- <React.Fragment>
603
- <div className="ticket-holders-fields">
604
- <p>{ticketHoldersFields.label}</p>
605
- {_map(ticketsQuantity, (_item, index) => (
606
- <div key={_item}>
607
- <h5>Ticket {index + 1}</h5>
608
- {_map(ticketHoldersFields.fields, group => {
609
- const { groupClassname, groupItems } = group
610
- return (
611
- <div key={group.uniqueId}>
612
- <div className={groupClassname}>
613
- {_map(groupItems, element => (
614
- <div
615
- className={element.className}
616
- key={element.uniqueId}
617
- >
618
- <Field
619
- name={`${element.name}-${index}`}
620
- label={element.label}
621
- type={element.type}
622
- required={true}
623
- component={
624
- element.type === 'checkbox'
625
- ? CheckboxField
626
- : CustomField
627
- }
628
- validate={combineValidators(
629
- element.required
630
- ? requiredValidator
631
- : () => {},
632
- element.onValidate
633
- ? element.onValidate
634
- : () => {}
635
- )}
636
- />
637
- </div>
638
- ))}
591
+ <div className="ticket-holders-fields">
592
+ <p>{ticketHoldersFields.label}</p>
593
+ {_map(ticketsQuantity, (_item, index) => (
594
+ <div key={_item}>
595
+ <h5>Ticket {index + 1}</h5>
596
+ {_map(ticketHoldersFields.fields, group => {
597
+ const { groupClassname, groupItems } = group
598
+ return (
599
+ <div key={group.uniqueId}>
600
+ <div className={groupClassname}>
601
+ {_map(groupItems, element => (
602
+ <div
603
+ className={element.className}
604
+ key={element.uniqueId}
605
+ >
606
+ <Field
607
+ name={`${element.name}-${index}`}
608
+ label={element.label}
609
+ type={element.type}
610
+ required={true}
611
+ component={
612
+ element.type === 'checkbox'
613
+ ? CheckboxField
614
+ : CustomField
615
+ }
616
+ validate={combineValidators(
617
+ element.required
618
+ ? requiredValidator
619
+ : () => {},
620
+ element.onValidate
621
+ ? element.onValidate
622
+ : () => {}
623
+ )}
624
+ />
639
625
  </div>
640
- </div>
641
- )
642
- })}
643
- </div>
644
- ))}
626
+ ))}
627
+ </div>
628
+ </div>
629
+ )
630
+ })}
645
631
  </div>
646
- </React.Fragment>
647
- )}
632
+ ))}
633
+ </div>
648
634
  <div className="button-container">
649
635
  <LoadingButton
650
636
  type="submit"
@@ -671,6 +657,7 @@ export const BillingInfoContainer = ({
671
657
  onLogin={() => {
672
658
  setShowModalLogin(false)
673
659
  setUserExpired(false)
660
+ onLoginSuccess()
674
661
  }}
675
662
  alreadyHasUser={alreadyHasUser}
676
663
  userExpired={userExpired}
@@ -33,6 +33,14 @@ export const getInitialValues = (
33
33
  initialValues[item] = propsInitialValues[item] || userValues[item] || ''
34
34
  })
35
35
 
36
+ // set logged in user as first ticket holder
37
+ initialValues['holderFirstName-0'] =
38
+ propsInitialValues.firstName || userValues.firstName || ''
39
+ initialValues['holderLastName-0'] =
40
+ propsInitialValues.lastName || userValues.lastName || ''
41
+ initialValues['holderEmail-0'] =
42
+ propsInitialValues.email || userValues.email || ''
43
+
36
44
  return initialValues
37
45
  }
38
46
 
@@ -67,7 +67,7 @@ export const ConfirmationContainer = ({
67
67
  }
68
68
  }
69
69
  })()
70
- }, [onGetConfirmationDataSuccess, onGetConfirmationDataError])
70
+ }, [])
71
71
 
72
72
  return (
73
73
  <div className="confirmation-page">
@@ -16,6 +16,7 @@ import StripePayment from '../stripePayment'
16
16
  import { IOrderData, IPaymentField } from '../../types'
17
17
 
18
18
  import { getPaymentData, handlePaymentSuccess, getConditions } from '../../api'
19
+ import { StripeCardNumberElementOptions } from '@stripe/stripe-js'
19
20
 
20
21
  const testId = ENV.STRIPE_PUBLISHABLE_KEY || 'pk_test_3Ov1P1oP33A1cxaSjxWE0VjT'
21
22
  const stripePromise = loadStripe(
@@ -32,6 +33,7 @@ export interface IPaymentPage {
32
33
  onGetPaymentDataSuccess: (value: any) => void;
33
34
  onGetPaymentDataError: (value: AxiosError) => void;
34
35
  onPaymentError: (value: AxiosError) => void;
36
+ stripeCardOptions?: StripeCardNumberElementOptions;
35
37
  }
36
38
 
37
39
  const initialOrderValues: IOrderData = {
@@ -62,6 +64,7 @@ export const PaymentContainer = ({
62
64
  onGetPaymentDataSuccess = () => {},
63
65
  onGetPaymentDataError = () => {},
64
66
  onPaymentError = () => {},
67
+ stripeCardOptions = {},
65
68
  }: IPaymentPage) => {
66
69
  const [reviewData, setReviewData] = useState(initialReviewValues)
67
70
  const [orderData, setOrderData] = useState(initialOrderValues)
@@ -118,6 +121,7 @@ export const PaymentContainer = ({
118
121
  ? conditionsInfo.map((item: string) => ({
119
122
  id: nanoid(),
120
123
  text: item,
124
+ checked: false,
121
125
  }))
122
126
  : []
123
127
  )
@@ -191,6 +195,7 @@ export const PaymentContainer = ({
191
195
  isLoading={paymentIsLoading}
192
196
  handleSetLoading={value => setPaymentIsLoading(value)}
193
197
  conditions={conditions}
198
+ stripeCardOptions={stripeCardOptions}
194
199
  />
195
200
  </Elements>
196
201
  </div>
@@ -18,11 +18,13 @@ import CircularProgress from '@mui/material/CircularProgress'
18
18
  const options: StripeCardNumberElementOptions = {
19
19
  style: {
20
20
  base: {
21
- backgroundColor:'#232323',
21
+ backgroundColor: '#232323',
22
22
  fontSize: '18px',
23
23
  color: '#ffffff',
24
24
  letterSpacing: '1px',
25
-
25
+ ':-webkit-autofill': {
26
+ color: '#ffffff',
27
+ },
26
28
  '::placeholder': {
27
29
  color: 'rgba(201, 201, 201, 0.5)',
28
30
  },
@@ -37,7 +39,6 @@ export interface ICheckoutForm {
37
39
  total: string;
38
40
  currency: string;
39
41
  onSubmit: (error: any) => Promise<any>;
40
-
41
42
  error?: string | null;
42
43
  stripeCardOptions?: StripeCardNumberElementOptions;
43
44
  stripe_client_secret: string;
@@ -57,7 +58,7 @@ interface AddressTypes {
57
58
  const CheckoutForm = ({
58
59
  total,
59
60
  onSubmit = _identity,
60
- stripeCardOptions = options,
61
+ stripeCardOptions = {},
61
62
  error = null,
62
63
  stripe_client_secret,
63
64
  currency,
@@ -70,6 +71,8 @@ const CheckoutForm = ({
70
71
  const elements = useElements()
71
72
  const [postalCode, setPostalCode] = useState<any>('')
72
73
  const [stripeError, setStripeError] = useState<any>(null)
74
+ const [checkboxes, setCheckboxes] = useState<any>([])
75
+ const [allowSubmit, setAllowSubmit] = useState(false)
73
76
 
74
77
  const handleSubmit = async (event: React.SyntheticEvent) => {
75
78
  handleSetLoading(true)
@@ -127,6 +130,18 @@ const CheckoutForm = ({
127
130
  }
128
131
  }
129
132
 
133
+ const handleCheckboxes = (e: any) => {
134
+ const checkbox = e.target
135
+ const updatedCheckedState = checkboxes.map((item: any) => {
136
+ const value = item.id === checkbox.name ? !item.checked : item.checked
137
+ return {
138
+ ...item,
139
+ checked: value,
140
+ }
141
+ })
142
+ setCheckboxes(updatedCheckedState)
143
+ }
144
+
130
145
  const onChangePostalCode = (e: any) => {
131
146
  setPostalCode(e.target.value)
132
147
  }
@@ -141,6 +156,21 @@ const CheckoutForm = ({
141
156
  }
142
157
  }, [])
143
158
 
159
+ useEffect(() => {
160
+ if (conditions.length) {
161
+ setCheckboxes(conditions)
162
+ }
163
+ }, [conditions])
164
+
165
+ useEffect(() => {
166
+ if (checkboxes.length) {
167
+ const allChecked = checkboxes.every(
168
+ (item: any) => item?.checked === true
169
+ )
170
+ setAllowSubmit(allChecked)
171
+ }
172
+ }, [checkboxes])
173
+
144
174
  const buttonIsDiabled = !stripe || !!error || isLoading
145
175
 
146
176
  return (
@@ -153,7 +183,7 @@ const CheckoutForm = ({
153
183
  <label className="card_number_element">
154
184
  <span className="card_label_text">Card number</span>
155
185
  <CardNumberElement
156
- options={stripeCardOptions}
186
+ options={{ ...options, ...stripeCardOptions }}
157
187
  onReady={_identity}
158
188
  onChange={_identity}
159
189
  onBlur={_identity}
@@ -162,11 +192,11 @@ const CheckoutForm = ({
162
192
  </label>
163
193
  <label className="expiration_element">
164
194
  <span className="card_label_text">Expiration date</span>
165
- <CardExpiryElement options={stripeCardOptions} />
195
+ <CardExpiryElement options={{ ...options, ...stripeCardOptions }} />
166
196
  </label>
167
197
  <label className="cvc_element">
168
198
  <span className="card_label_text">CVC</span>
169
- <CardCvcElement options={stripeCardOptions} />
199
+ <CardCvcElement options={{ ...options, ...stripeCardOptions }} />
170
200
  </label>
171
201
  <label className="zip_element">
172
202
  <p className="card_label_text">ZIP</p>
@@ -178,7 +208,7 @@ const CheckoutForm = ({
178
208
  />
179
209
  </label>
180
210
  </div>
181
- {conditions?.map((checkbox: any) => (
211
+ {checkboxes?.map((checkbox: any) => (
182
212
  <div
183
213
  className={'billing-info-container__singleField'}
184
214
  key={checkbox.id}
@@ -188,13 +218,15 @@ const CheckoutForm = ({
188
218
  name={checkbox.id}
189
219
  label={checkbox.text}
190
220
  required={true}
221
+ onChange={handleCheckboxes}
222
+ checked={checkbox.checked}
191
223
  />
192
224
  </div>
193
225
  </div>
194
226
  ))}
195
227
  <div
196
228
  className={`payment_button ${
197
- buttonIsDiabled ? 'disabled-payment-button' : ''
229
+ buttonIsDiabled || !allowSubmit ? 'disabled-payment-button' : ''
198
230
  }`}
199
231
  >
200
232
  <button disabled={buttonIsDiabled} type="submit">
@@ -66,9 +66,10 @@ const WaitingList = ({ tickets = {} }: WaitingListProps) => {
66
66
 
67
67
  return (
68
68
  <div className="waiting-list">
69
+ <p className="no-tickets-text">No tickets are currently available for this event.</p>
69
70
  {showSuccessMessage ? (
70
71
  <div className="success-message">
71
- <h3>{`You've been added to the waiting list!`}</h3>
72
+ <p className="added-success-message">{`You've been added to the waiting list!`}</p>
72
73
  <p>{`You'll be notified if tickets become available.`}</p>
73
74
  </div>
74
75
  ) : (
@@ -15,4 +15,10 @@
15
15
  }
16
16
  .waiting-list .success-message p {
17
17
  margin: 0;
18
+ }
19
+ .waiting-list .no-tickets-text {
20
+ text-align: center;
21
+ }
22
+ .waiting-list .added-success-message {
23
+ font-size: 22px;
18
24
  }
package/src/.DS_Store DELETED
Binary file
Binary file