tf-checkout-react 1.4.17 → 1.4.18

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.4.17",
2
+ "version": "1.4.18",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -68,7 +68,7 @@
68
68
  "eslint-plugin-unused-imports": "^2.0.0",
69
69
  "eslint-webpack-plugin": "^3.2.0",
70
70
  "husky": "^7.0.4",
71
- "parcel": "^2.8.2",
71
+ "parcel": "^2.8.3",
72
72
  "prettier": "^2.8.4",
73
73
  "process": "^0.11.10",
74
74
  "react": "^17.0.2",
package/src/api/index.ts CHANGED
@@ -400,7 +400,43 @@ export const selectAddons = (data: any) => {
400
400
  publicRequest.post(`v1/on-checkout`, data)
401
401
  }
402
402
 
403
- export const getCheckoutPageConfigs = async () => {
403
+ export interface AttributesConfig {
404
+ has_add_on: boolean;
405
+ names_required: boolean;
406
+ phone_required: boolean;
407
+ minimum_age?: any;
408
+ age_required: boolean;
409
+ hide_phone_field: boolean;
410
+ event_id: string;
411
+ free_ticket: boolean;
412
+ collect_mandatory_wallet_address: boolean;
413
+ collect_optional_wallet_address: boolean;
414
+ collect_mandatory_company: boolean;
415
+ collect_optional_company: boolean;
416
+ collect_mandatory_job_title: boolean;
417
+ collect_optional_job_title: boolean;
418
+ collect_mandatory_business_category: boolean;
419
+ collect_optional_business_category: boolean;
420
+ collect_mandatory_instagram: boolean;
421
+ collect_optional_instagram: boolean;
422
+ skip_billing_page: boolean;
423
+ }
424
+
425
+ export interface ConfigsData {
426
+ attributes: AttributesConfig;
427
+ relationships: any[];
428
+ type: string;
429
+ }
430
+
431
+ export interface ResponseConfigs {
432
+ data: ConfigsData;
433
+ success: boolean;
434
+ error: boolean;
435
+ message: string;
436
+ status: number;
437
+ }
438
+
439
+ export const getCheckoutPageConfigs = async (): Promise<ResponseConfigs> => {
404
440
  const response = await publicRequest.get(`v1/checkout-configs`)
405
441
  return response.data
406
442
  }
@@ -25,7 +25,9 @@ import { nanoid } from 'nanoid'
25
25
  import React, { FC, useEffect, useRef, useState } from 'react'
26
26
 
27
27
  import {
28
+ AttributesConfig,
28
29
  getCart,
30
+ getCheckoutPageConfigs,
29
31
  getCountries,
30
32
  getProfileData,
31
33
  getStates,
@@ -42,7 +44,6 @@ import {
42
44
  isBrowser,
43
45
  } from '../../utils'
44
46
  import { ErrorFocus } from '../../utils/formikErrorFocus'
45
- import { getQueryVariable } from '../../utils/getQueryVariable'
46
47
  import { combineValidators, requiredValidator } from '../../validators'
47
48
  import SnackbarAlert from '../common/SnackbarAlert'
48
49
  import { ForgotPasswordModal } from '../forgotPasswordModal'
@@ -195,7 +196,11 @@ const LogicRunner: FC<{
195
196
  parsedData?.last_name || parsedData?.lastName || '',
196
197
  'holderEmail-0': parsedData?.email || '',
197
198
  }
198
- setValues({ ...values, ...mappedValues })
199
+
200
+ const extraDataJSON = window.localStorage.getItem('extraData')
201
+ const extraData = extraDataJSON ? JSON.parse(extraDataJSON) : null
202
+
203
+ setValues({ ...values, ...mappedValues, ...(extraData ?? {}) })
199
204
  setUserValues(mappedValues)
200
205
  } catch (e) {}
201
206
  }
@@ -254,9 +259,28 @@ export const BillingInfoContainer = React.memo(
254
259
  isCountryCodeEditable = true,
255
260
  onPendingVerification = _identity,
256
261
  }: IBillingInfoPage) => {
262
+ const [extraData, setExtraData] = useState(null)
263
+ const [isConfigLoading, setIsConfigLoading] = useState(true)
264
+ const [configs, setConfigs] = useState<null | AttributesConfig>(null)
257
265
  const [isNewUser, setIsNewUser] = useState(false)
258
266
  const themeMui = createTheme(themeOptions)
259
267
  const isWindowDefined = typeof window !== 'undefined'
268
+ useEffect(() => {
269
+ if (isWindowDefined) {
270
+ const extraData = window.localStorage.getItem('extraData')
271
+ if (extraData) {
272
+ setExtraData(JSON.parse(extraData))
273
+ }
274
+ }
275
+ getCheckoutPageConfigs().then(data => {
276
+ if (data?.data?.attributes) {
277
+ setConfigs(data.data.attributes)
278
+ setIsConfigLoading(false)
279
+ }
280
+ }).catch(() => {
281
+ setIsConfigLoading(false)
282
+ })
283
+ }, [isWindowDefined])
260
284
  const defaultCountry = isWindowDefined
261
285
  ? window.localStorage.getItem('eventCountry')
262
286
  : ''
@@ -312,9 +336,9 @@ export const BillingInfoContainer = React.memo(
312
336
  _get(userData, 'first_name', '') || _get(userValues, 'first_name', '')
313
337
  const lastNameLogged =
314
338
  _get(userData, 'last_name', '') || _get(userValues, 'last_name', '')
315
- const showDOB = getQueryVariable('age_required') === 'true'
316
- const showTicketHolders = getQueryVariable('names_required') === 'true'
317
- const eventId = getQueryVariable('event_id') || ''
339
+ const showDOB = configs?.age_required
340
+ const showTicketHolders = configs?.names_required
341
+ const eventId = configs?.event_id
318
342
  const optedInFieldValue: boolean = brandOptIn
319
343
  ? brandOptIn
320
344
  : _get(cartInfoData, 'optedIn', false)
@@ -322,15 +346,29 @@ export const BillingInfoContainer = React.memo(
322
346
  const isTable = Boolean(_get(cartInfoData, 'is_table', false))
323
347
  const hideTtfOptIn: boolean = _get(cartInfoData, 'hide_ttf_opt_in', true)
324
348
  const expirationTime = _get(cartInfoData, 'expiresAt')
325
- const flagRequirePhone = getQueryVariable('phone_required') === 'true'
326
- const collectMandatoryWalletAddress =
327
- getQueryVariable('collect_mandatory_wallet_address') === 'true'
328
- const collectOptionalWalletAddress =
329
- getQueryVariable('collect_optional_wallet_address') === 'true'
330
- const flagFreeTicket = getQueryVariable('free_ticket') === 'true'
331
- const hidePhoneField = getQueryVariable('hide_phone_field') === 'true'
349
+ const flagRequirePhone = configs?.phone_required
350
+ const collectMandatoryWalletAddress = configs?.collect_mandatory_wallet_address
351
+ const collectOptionalWalletAddress = configs?.collect_optional_wallet_address
352
+ const flagFreeTicket = configs?.free_ticket
353
+ const hidePhoneField = configs?.hide_phone_field
332
354
  const hideWalletAddressField =
333
355
  !collectOptionalWalletAddress && !collectMandatoryWalletAddress
356
+ const collectMandatoryCompany = configs?.collect_mandatory_company
357
+ const collectOptionalCompany = configs?.collect_optional_company
358
+ const hideCompanyField =
359
+ !collectOptionalCompany && !collectMandatoryCompany
360
+ const collectMandatoryJobTitle = configs?.collect_mandatory_job_title
361
+ const collectOptionalJobTitle = configs?.collect_optional_job_title
362
+ const hideJobTitleField =
363
+ !collectMandatoryJobTitle && !collectOptionalJobTitle
364
+ const collectMandatoryInstagram = configs?.collect_mandatory_instagram
365
+ const collectOptionalInstagram = configs?.collect_optional_instagram
366
+ const hideInstagramField =
367
+ !collectMandatoryInstagram && !collectOptionalInstagram
368
+ const collectMandatoryBusinessCategory = configs?.collect_mandatory_business_category
369
+ const collectOptionalBusinessCategory = configs?.collect_optional_business_category
370
+ const hideBusinessCategoryField =
371
+ !collectMandatoryBusinessCategory && !collectOptionalBusinessCategory
334
372
 
335
373
  const [
336
374
  pendingVerificationMessage,
@@ -534,13 +572,13 @@ export const BillingInfoContainer = React.memo(
534
572
  selectedCountry.id || _get(userData, 'country', '') || '1'
535
573
 
536
574
  const pageUrl = isBrowser ? window.location.href.split('?')[0] : ''
537
- usePixel(eventId, { page: 'billing', pageUrl })
575
+ usePixel(eventId || '', { page: 'billing', pageUrl })
538
576
  if (isTable) {
539
577
  dataWithUniqueIds[0].label = 'Get Your Tables'
540
578
  }
541
579
  return (
542
580
  <ThemeProvider theme={themeMui}>
543
- {(loading || cardLoading || isCountriesLoading) && (
581
+ {(loading || cardLoading || isCountriesLoading || isConfigLoading) && (
544
582
  <Backdrop
545
583
  sx={{ color: '#fff', backgroundColor: '#000000bd', zIndex: 1205 }}
546
584
  open={true}
@@ -554,7 +592,7 @@ export const BillingInfoContainer = React.memo(
554
592
  onCountdownFinish={onCountdownFinish}
555
593
  />
556
594
  )}
557
- {!isCountriesLoading && (
595
+ {!isCountriesLoading && !isConfigLoading && (
558
596
  <Formik
559
597
  initialValues={getInitialValues(
560
598
  dataWithUniqueIds,
@@ -563,6 +601,12 @@ export const BillingInfoContainer = React.memo(
563
601
  state: _get(userData, 'state', '') || '1',
564
602
  brand_opt_in: optedInFieldValue,
565
603
  ttf_opt_in: ttfOptIn,
604
+ data_capture: {
605
+ 'instagram': _get(extraData, 'data_capture.instagram', ''),
606
+ 'company': _get(extraData, 'data_capture.company', ''),
607
+ 'businessCategory': _get(extraData, 'data_capture.businessCategory', ''),
608
+ 'jobTitle': _get(extraData, 'data_capture.jobTitle', ''),
609
+ },
566
610
  ...initialValues,
567
611
  },
568
612
  userValues
@@ -570,6 +614,16 @@ export const BillingInfoContainer = React.memo(
570
614
  enableReinitialize={false}
571
615
  onSubmit={async (values, formikHelpers) => {
572
616
  try {
617
+ if (isWindowDefined) {
618
+ window.localStorage.setItem('extraData', JSON.stringify({
619
+ data_capture: {
620
+ 'instagram': _get(values, 'data_capture.instagram', ''),
621
+ 'company': _get(values, 'data_capture.company', ''),
622
+ 'businessCategory': _get(values, 'data_capture.businessCategory', ''),
623
+ 'jobTitle': _get(values, 'data_capture.jobTitle', ''),
624
+ }
625
+ }))
626
+ }
573
627
  if (isLoggedIn) {
574
628
  const checkoutBody = collectCheckoutBody(values, userData)
575
629
 
@@ -833,13 +887,40 @@ export const BillingInfoContainer = React.memo(
833
887
  el.required = true
834
888
  }
835
889
  }
890
+ if (
891
+ el.name === 'data_capture[jobTitle]'
892
+ ) {
893
+ if (collectMandatoryJobTitle) {
894
+ el.required = true
895
+ }
896
+ }
897
+ if (
898
+ el.name === 'data_capture[businessCategory]'
899
+ ) {
900
+ if (collectMandatoryBusinessCategory) {
901
+ el.required = true
902
+ }
903
+ }
904
+ if (
905
+ el.name === 'data_capture[company]'
906
+ ) {
907
+ if (collectMandatoryCompany) {
908
+ el.required = true
909
+ }
910
+ }
911
+ if (
912
+ el.name === 'data_capture[instagram]'
913
+ ) {
914
+ if (collectMandatoryInstagram) {
915
+ el.required = true
916
+ }
917
+ }
836
918
  if (
837
919
  [
838
920
  'street_address',
839
921
  'country',
840
922
  'state',
841
923
  'city',
842
- 'zip',
843
924
  ].includes(el.name)
844
925
  ) {
845
926
  if (flagFreeTicket) {
@@ -849,7 +930,28 @@ export const BillingInfoContainer = React.memo(
849
930
  }
850
931
  if (
851
932
  hideWalletAddressField &&
852
- el.name === 'wallet-address-info'
933
+ (el.name === 'wallet-address-info' || el.name === 'data_capture[wallet_address]')
934
+ ) {
935
+ return false
936
+ }
937
+ if (
938
+ hideJobTitleField && el.name === 'data_capture[jobTitle]'
939
+ ) {
940
+ return false
941
+ }
942
+ if (
943
+ hideBusinessCategoryField && el.name === 'data_capture[businessCategory]'
944
+ ) {
945
+ return false
946
+ }
947
+ if (
948
+ hideCompanyField && el.name === 'data_capture[company]'
949
+ ) {
950
+ return false
951
+ }
952
+ if (
953
+ hideInstagramField &&
954
+ (el.name === 'data_capture[instagram]' || el.name === 'instagram-info')
853
955
  ) {
854
956
  return false
855
957
  }
@@ -861,10 +963,7 @@ export const BillingInfoContainer = React.memo(
861
963
  'confirmPassword',
862
964
  'password-info',
863
965
  ].includes(element.name) &&
864
- isLoggedIn ? null : [
865
- 'data_capture[wallet_address]',
866
- ].includes(element.name) &&
867
- hideWalletAddressField ? null : (
966
+ isLoggedIn ? null : (
868
967
  <React.Fragment key={element.uniqueId}>
869
968
  <div
870
969
  className={`${
@@ -210,6 +210,7 @@ export const TicketsContainer = ({
210
210
  window.localStorage.removeItem('user_data')
211
211
  }
212
212
  }
213
+ window.localStorage.removeItem('extraData')
213
214
  }
214
215
  }, [])
215
216