tf-checkout-react 1.4.20 → 1.4.21

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.
Files changed (59) hide show
  1. package/README.md +462 -229
  2. package/dist/api/guestTicketDelegation.d.ts +47 -0
  3. package/dist/api/index.d.ts +2 -2
  4. package/dist/components/common/CustomField.d.ts +1 -1
  5. package/dist/components/common/FieldSection/index.d.ts +19 -0
  6. package/dist/components/common/FieldSection/utils/index.d.ts +8 -0
  7. package/dist/components/common/index.d.ts +2 -2
  8. package/dist/components/confirmModal/index.d.ts +2 -2
  9. package/dist/components/delegationsContainer/IssueComponent.d.ts +10 -0
  10. package/dist/components/delegationsContainer/IssueTicketForm.d.ts +9 -0
  11. package/dist/components/delegationsContainer/TicketsAssignedTable.d.ts +11 -0
  12. package/dist/components/delegationsContainer/TicketsAvailableTable.d.ts +11 -0
  13. package/dist/components/delegationsContainer/index.d.ts +10 -0
  14. package/dist/components/idVerificationContainer/constants.d.ts +1 -0
  15. package/dist/components/index.d.ts +1 -0
  16. package/dist/components/loginForm/index.d.ts +45 -0
  17. package/dist/components/registerForm/adapters/index.d.ts +4 -0
  18. package/dist/components/registerForm/constants.d.ts +1 -0
  19. package/dist/components/registerForm/index.d.ts +16 -0
  20. package/dist/index.d.ts +3 -1
  21. package/dist/tf-checkout-react.cjs.development.js +1413 -283
  22. package/dist/tf-checkout-react.cjs.development.js.map +1 -1
  23. package/dist/tf-checkout-react.cjs.production.min.js +1 -1
  24. package/dist/tf-checkout-react.cjs.production.min.js.map +1 -1
  25. package/dist/tf-checkout-react.esm.js +1416 -288
  26. package/dist/tf-checkout-react.esm.js.map +1 -1
  27. package/dist/utils/form.d.ts +3 -0
  28. package/dist/utils/index.d.ts +3 -1
  29. package/dist/utils/replaceVarInString.d.ts +1 -0
  30. package/package.json +1 -1
  31. package/src/api/guestTicketDelegation.ts +79 -0
  32. package/src/api/index.ts +3 -2
  33. package/src/components/billing-info-container/utils.ts +1 -1
  34. package/src/components/common/CustomField.tsx +2 -0
  35. package/src/components/common/FieldSection/index.tsx +141 -0
  36. package/src/components/common/FieldSection/utils/index.tsx +92 -0
  37. package/src/components/common/SelectField/index.tsx +1 -1
  38. package/src/components/common/index.tsx +2 -2
  39. package/src/components/confirmModal/index.tsx +2 -2
  40. package/src/components/delegationsContainer/IssueComponent.tsx +155 -0
  41. package/src/components/delegationsContainer/IssueTicketForm.tsx +109 -0
  42. package/src/components/delegationsContainer/TicketsAssignedTable.tsx +55 -0
  43. package/src/components/delegationsContainer/TicketsAvailableTable.tsx +54 -0
  44. package/src/components/delegationsContainer/index.tsx +83 -0
  45. package/src/components/forgotPasswordModal/index.tsx +3 -9
  46. package/src/components/idVerificationContainer/constants.ts +5 -2
  47. package/src/components/index.ts +1 -0
  48. package/src/components/loginForm/index.tsx +195 -0
  49. package/src/components/registerForm/adapters/index.tsx +10 -0
  50. package/src/components/registerForm/constants.tsx +96 -0
  51. package/src/components/registerForm/index.tsx +192 -0
  52. package/src/index.ts +3 -4
  53. package/src/types/api/auth.d.ts +55 -0
  54. package/src/types/api/guestTicketDelegation.d.ts +18 -0
  55. package/src/types/formFields.d.ts +29 -0
  56. package/src/utils/form.ts +34 -0
  57. package/src/utils/index.ts +3 -1
  58. package/src/utils/replaceVarInString.ts +9 -0
  59. package/src/validators/index.ts +2 -2
@@ -0,0 +1,192 @@
1
+ import { Button, CircularProgress } from '@mui/material'
2
+ import axios, { AxiosError } from 'axios'
3
+ import { Form, Formik, FormikValues } from 'formik'
4
+ import _get from 'lodash/get'
5
+ import _identity from 'lodash/identity'
6
+ import _map from 'lodash/map'
7
+ import React, { FC, useEffect, useState } from 'react'
8
+
9
+ import { getCountries, getProfileData, getStates, register } from '../../api'
10
+ import { CONFIGS, getFormInitialValues, getQueryVariable } from '../../utils'
11
+ import { FieldsSection } from '../common/FieldSection'
12
+ import { updateFormFieldsAttributes } from '../common/FieldSection/utils'
13
+ import ConfirmModal from '../confirmModal'
14
+ import { collectStates } from './adapters'
15
+ import { formDefaultFields } from './constants'
16
+
17
+ interface IRegistrationProps {
18
+ formFields?: Array<IFormFieldsSection>;
19
+ additionalFieldAttribute?: IFieldAttribute;
20
+ registrationType: string;
21
+ onGetCountriesSuccess?: (res: any) => void;
22
+ onGetCountriesError?: (e: AxiosError) => void;
23
+ onRegisterAccountSuccess?: (res: any) => void;
24
+ onRegisterAccountError?: (e: AxiosError) => void;
25
+ onGetStatesSuccess?: (res: any) => void;
26
+ onGetStatesError?: (e: AxiosError) => void;
27
+ customerEmail: string;
28
+ }
29
+
30
+ export const RegistrationForm: FC<IRegistrationProps> = ({
31
+ formFields,
32
+ additionalFieldAttribute,
33
+ registrationType,
34
+ customerEmail,
35
+ onGetCountriesSuccess = _identity,
36
+ onGetCountriesError = _identity,
37
+ onRegisterAccountSuccess = _identity,
38
+ onRegisterAccountError = _identity,
39
+ onGetStatesSuccess = _identity,
40
+ onGetStatesError = _identity,
41
+ }) => {
42
+ const [errorMessage, setErrorMessage] = useState('')
43
+ const [countries, setCountries] = useState<{ [key: string]: string | number }[]>([])
44
+ const [states, setStates] = useState<{ [key: string]: string | number }[]>([])
45
+ const [phoneValidationIsLoading, setPhoneValidationIsLoading] = useState(false)
46
+ const [showErrorModal, setshowErrorModal] = useState(false)
47
+
48
+ const updatedFormFields = updateFormFieldsAttributes(
49
+ formFields || formDefaultFields,
50
+ additionalFieldAttribute
51
+ )
52
+
53
+ // Fetch countries data
54
+ const fetchCountries = async () => {
55
+ try {
56
+ const res = await getCountries()
57
+ setCountries(
58
+ _map(_get(res, 'data.data'), item => ({
59
+ label: item.name,
60
+ value: item.id,
61
+ }))
62
+ )
63
+ onGetCountriesSuccess(res.data)
64
+ } catch (e) {
65
+ if (axios.isAxiosError(e)) {
66
+ const errorMessage = e?.response?.data?.message || 'Error'
67
+ setErrorMessage(errorMessage)
68
+ onGetCountriesError(e)
69
+ }
70
+ }
71
+ }
72
+
73
+ // Fetch states data
74
+ const fetchStates = async (countryId?: string | number) => {
75
+ try {
76
+ const fetchCountryId = countryId ? countryId : '1'
77
+ const res = await getStates(fetchCountryId)
78
+ const states = _get(res, 'data.data', [])
79
+ const mappedStates = collectStates(states)
80
+ setStates(mappedStates)
81
+ onGetStatesSuccess(res.data)
82
+ } catch (e) {
83
+ if (axios.isAxiosError(e)) {
84
+ const errorMessage = e?.response?.data?.message || 'Error'
85
+ onGetStatesError(errorMessage)
86
+ }
87
+ }
88
+ }
89
+
90
+ const handleRegisterAccount = async (values: FormikValues) => {
91
+ const accessHash = getQueryVariable('hash') || ''
92
+
93
+ try {
94
+ const bodyFormData = new FormData()
95
+
96
+ bodyFormData.append('first_name', values.firstName)
97
+ bodyFormData.append('last_name', values.lastName)
98
+ bodyFormData.append('email', values.email)
99
+ bodyFormData.append('zip', values.zip)
100
+ bodyFormData.append('city', values.city)
101
+ bodyFormData.append('country', values.country)
102
+ bodyFormData.append('password', values.password)
103
+ bodyFormData.append('phone', values.phone || '')
104
+ bodyFormData.append('password_confirmation', values.confirmPassword)
105
+ bodyFormData.append('client_id', CONFIGS.CLIENT_ID)
106
+ bodyFormData.append('client_secret', CONFIGS.CLIENT_SECRET)
107
+ bodyFormData.append('register_for', registrationType)
108
+ bodyFormData.append('delegation_access_hash', accessHash)
109
+
110
+ await register(bodyFormData)
111
+ const profileRes = await getProfileData()
112
+
113
+ window.localStorage.setItem(
114
+ 'user_data',
115
+ JSON.stringify(_get(profileRes, 'data.data'))
116
+ )
117
+ onRegisterAccountSuccess(profileRes)
118
+ } catch (e) {
119
+ if (axios.isAxiosError(e)) {
120
+ console.log(e)
121
+ const errorMessage = e?.response?.data?.message || 'Error'
122
+ onRegisterAccountError(e)
123
+ setshowErrorModal(true)
124
+ setErrorMessage(errorMessage)
125
+ } else if (e instanceof Error) {
126
+ setErrorMessage(e?.message || 'Error')
127
+ }
128
+ }
129
+ }
130
+
131
+ useEffect(() => {
132
+ fetchCountries()
133
+ fetchStates()
134
+ }, [])
135
+
136
+ return (
137
+ <div className="register-form-container">
138
+ <h2>Create an account</h2>
139
+ <div className="register-sub-title">
140
+ To manage your tickets, please create an account:
141
+ </div>
142
+ {showErrorModal && (
143
+ <ConfirmModal
144
+ hideCancelBtn={true}
145
+ message={errorMessage}
146
+ onClose={() => (window.location.href = '/')}
147
+ onConfirm={() => (window.location.href = '/')}
148
+ />
149
+ )}
150
+ {errorMessage && <div className="register-error">{errorMessage}</div>}
151
+ <Formik
152
+ initialValues={{
153
+ ...getFormInitialValues(updatedFormFields),
154
+ email: customerEmail,
155
+ }}
156
+ enableReinitialize={true}
157
+ onSubmit={handleRegisterAccount}
158
+ >
159
+ {props => (
160
+ <Form>
161
+ <div className="register-body">
162
+ <FieldsSection
163
+ disableField={'email'}
164
+ containerClass="register"
165
+ formFields={updatedFormFields}
166
+ values={props.values}
167
+ setFieldValue={props.setFieldValue}
168
+ setPhoneValidationIsLoading={setPhoneValidationIsLoading}
169
+ countries={countries}
170
+ states={states}
171
+ onFieldChange={(name, value) => {
172
+ if (name === 'country') {
173
+ fetchStates(value)
174
+ }
175
+ }}
176
+ />
177
+ </div>
178
+ <div className="button-container">
179
+ <Button
180
+ className="register-button"
181
+ type="submit"
182
+ disabled={props.isSubmitting || phoneValidationIsLoading}
183
+ >
184
+ {props.isSubmitting ? <CircularProgress size={26} /> : 'Create Account'}
185
+ </Button>
186
+ </div>
187
+ </Form>
188
+ )}
189
+ </Formik>
190
+ </div>
191
+ )
192
+ }
package/src/index.ts CHANGED
@@ -2,10 +2,7 @@ export { BillingInfoContainer } from './components/billing-info-container/index'
2
2
  export { PaymentContainer } from './components/paymentContainer/index'
3
3
  export { ConfirmationContainer } from './components/confirmationContainer/index'
4
4
  export { TicketsContainer } from './components/ticketsContainer/index'
5
- export {
6
- currencyNormalizerCreator,
7
- createFixedFloatNormalizer,
8
- } from './normalizers'
5
+ export { currencyNormalizerCreator, createFixedFloatNormalizer } from './normalizers'
9
6
  export { LoginModal } from './components/loginModal'
10
7
  export { MyTicketsContainer } from './components/myTicketsContainer'
11
8
  export { OrderDetailsContainer } from './components/orderDetailsContainer'
@@ -16,7 +13,9 @@ export { RsvpContainer } from './components/rsvpContainer'
16
13
  export { ResetPasswordContainer } from './components/resetPasswordContainer'
17
14
  export { ForgotPasswordModal } from './components/forgotPasswordModal'
18
15
  export { AddonsContainter } from './components/addonsContainer'
16
+ export { DelegationsContainer } from './components/delegationsContainer'
19
17
  export { PoweredBy } from './components/common/PoweredBy'
20
18
  export { SeatMapContainer } from './components/seatMapContainer'
21
19
  export { IDVerification } from './components/idVerificationContainer'
22
20
  export { VERIFICATION_STATUSES } from './components/idVerificationContainer/constants'
21
+ export { useCookieListener } from './hooks/useCookieListener'
@@ -0,0 +1,55 @@
1
+ // autorize request body
2
+ interface IAuthorizeRequestData {
3
+ email: string;
4
+ password: string;
5
+ }
6
+
7
+ // authorize, get user data
8
+ interface IProfileData {
9
+ id: number | string;
10
+ firstName: string;
11
+ lastName: string;
12
+ email: string;
13
+ phone: string;
14
+ streetAddress: string;
15
+ zipCode: number;
16
+ countryId: number;
17
+ company: string;
18
+ state: string | number;
19
+ stateId: number;
20
+ city: string;
21
+ username: string;
22
+ screenName: string | null;
23
+ bio: string;
24
+ shortBio: string | null;
25
+ region: string | null;
26
+ image: string;
27
+ recommendedEvents: Array<any>;
28
+ rnRoles: Array<string>;
29
+ hasDashboardAccess: boolean;
30
+ ticketHolders: Array<any>;
31
+ }
32
+
33
+ interface IProfileResponse extends IAxiosResponseData {
34
+ data: IProfileData;
35
+ }
36
+
37
+ // signup request body
38
+ interface ISignupRequestData {
39
+ firstName: string;
40
+ lastName: string;
41
+ email: string;
42
+ password: string;
43
+ passwordConfirmation: string;
44
+ checkCartExpiration: boolean;
45
+ confirmEmail?: string;
46
+ }
47
+
48
+ interface ISignupRequestDataExtended extends ISignupRequestData {
49
+ phone: string | number;
50
+ countryId: string | number;
51
+ city: string;
52
+ stateId: string | number;
53
+ streetAddress: string;
54
+ zip: string | number;
55
+ }
@@ -0,0 +1,18 @@
1
+ interface ICheckCustomerExistsData {
2
+ action: string;
3
+ alreadyApplied: boolean;
4
+ gropName: string | null;
5
+ id: string;
6
+ oneTimeAction: boolean;
7
+ phase: string;
8
+ point: string;
9
+ socialUrl: string | null;
10
+ }
11
+
12
+ interface ITicketIssueData {
13
+ ticketTypeId: string;
14
+ firstName: string;
15
+ lastName: string;
16
+ email: string;
17
+ confirmEmail: string;
18
+ }
@@ -0,0 +1,29 @@
1
+ interface IFormField {
2
+ name: string;
3
+ label: string;
4
+ uniqueId?: string;
5
+ component?: HTMLElement | JSX.Element;
6
+ type?: string;
7
+ required?: boolean;
8
+ className?: string;
9
+ options?: { [key: string]: string | number }[];
10
+ onValidate?: (() => void) | null;
11
+ disableDropdown?: boolean;
12
+ }
13
+
14
+ interface IFormFieldsSection {
15
+ name: string;
16
+ fields: IFormField[];
17
+ groupLabel?: string | HTMLElement | JSX.Element;
18
+ groupLabelVars?: string[];
19
+ groupLabelClassName?: string;
20
+ groupClassName?: string;
21
+ id?: string | number;
22
+ uniqueId?: string;
23
+ }
24
+
25
+ interface IFieldAttribute {
26
+ [key: string]: {
27
+ [key: string]: string | number | boolean | Array<string | number>;
28
+ };
29
+ }
@@ -0,0 +1,34 @@
1
+ import _forEach from 'lodash/forEach'
2
+ import _get from 'lodash/get'
3
+
4
+ export const getFormInitialValues = (fieldsSections: IFormFieldsSection[]) => {
5
+ const initialValues: { [key: string]: string | number | boolean } = {}
6
+ const isWindowDefined = typeof window !== 'undefined'
7
+ const userData = JSON.parse(
8
+ isWindowDefined ? window.localStorage.getItem('user_data') || '{}' : '{}'
9
+ ) as IProfileData
10
+
11
+ _forEach(fieldsSections, item => {
12
+ _forEach(item.fields, fieldItem => {
13
+ switch (fieldItem.name) {
14
+ case 'country':
15
+ case 'numTickets':
16
+ case 'state':
17
+ initialValues[fieldItem.name] = ''
18
+ break
19
+ case 'brandOptIn':
20
+ initialValues[fieldItem.name] = true
21
+ break
22
+ case 'confirmEmail':
23
+ initialValues[fieldItem.name] =
24
+ _get(userData, fieldItem.name) || _get(userData, 'email') || ''
25
+ break
26
+ default:
27
+ initialValues[fieldItem.name] = _get(userData, fieldItem.name) || ''
28
+ break
29
+ }
30
+ })
31
+ })
32
+
33
+ return initialValues
34
+ }
@@ -6,7 +6,9 @@ export { createCheckoutDataBodyWithDefaultHolder } from './createCheckoutDataBod
6
6
  export { setCustomCookie, getCookieByName, deleteCookieByName } from './cookies'
7
7
  export { getDomain } from './getDomain'
8
8
  export { createMarkup } from './createMarkup'
9
+ export { replaceVarInString } from './replaceVarInString'
10
+ export { isBrowser } from './isBrowser'
11
+ export { getFormInitialValues } from './form'
9
12
  export { setLoggedUserData } from './auth'
10
13
  export { createElementFromHTML } from './htmlNodeFromString'
11
- export { isBrowser } from './isBrowser'
12
14
  export { isJson } from './jsonUtils'
@@ -0,0 +1,9 @@
1
+ export const replaceVarInString = (message = '', varArray: Array<string>) => {
2
+ const re = new RegExp(/\{.*?\}/g)
3
+ let index = 0
4
+ return message.replace(re, _ => {
5
+ const value = varArray[index] || ''
6
+ index++
7
+ return value
8
+ })
9
+ }
@@ -11,9 +11,9 @@ export function isFalsy(item: any) {
11
11
  try {
12
12
  if (
13
13
  !item || // handles most, like false, 0, null, etc
14
- (typeof item == 'object' &&
14
+ (typeof item === 'object' &&
15
15
  Object.keys(item).length === 0 && // for empty objects, like {}, []
16
- !(typeof item.addEventListener == 'function')) // omit webpage elements
16
+ !(typeof item.addEventListener === 'function')) // omit webpage elements
17
17
  ) {
18
18
  return true
19
19
  }