tf-checkout-react 1.0.106 → 1.1.0
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/README.md +278 -1
- package/dist/api/index.d.ts +40 -28
- package/dist/components/account-settings/index.d.ts +3 -0
- package/dist/components/billing-info-container/index.d.ts +8 -5
- package/dist/components/common/PhoneNumberField.d.ts +9 -0
- package/dist/components/common/index.d.ts +1 -0
- package/dist/components/confirmationContainer/index.d.ts +2 -1
- package/dist/components/countdown/index.d.ts +2 -1
- package/dist/components/forgotPasswordModal/index.d.ts +11 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/loginModal/index.d.ts +35 -2
- package/dist/components/myTicketsContainer/index.d.ts +2 -1
- package/dist/components/myTicketsContainer/tableConfig.d.ts +1 -1
- package/dist/components/orderDetailsContainer/index.d.ts +6 -1
- package/dist/components/orderDetailsContainer/ticketsTable.d.ts +2 -1
- package/dist/components/paymentContainer/index.d.ts +2 -1
- package/dist/components/resetPasswordContainer/index.d.ts +10 -0
- package/dist/components/signupModal/index.d.ts +14 -0
- package/dist/components/ticketsContainer/PromoCodeSection.d.ts +3 -2
- package/dist/components/ticketsContainer/TicketsSection.d.ts +1 -2
- package/dist/components/ticketsContainer/index.d.ts +4 -1
- package/dist/index.d.ts +2 -0
- package/dist/tf-checkout-react.cjs.development.js +1274 -629
- package/dist/tf-checkout-react.cjs.development.js.map +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js.map +1 -1
- package/dist/tf-checkout-react.esm.js +1272 -629
- package/dist/tf-checkout-react.esm.js.map +1 -1
- package/dist/tf-checkout-styles.css +1 -1
- package/dist/utils/cookies.d.ts +3 -0
- package/dist/utils/createCheckoutDataBodyWithDefaultHolder.d.ts +6 -1
- package/dist/utils/downloadPDF.d.ts +1 -1
- package/dist/utils/getDomain.d.ts +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/package.json +12 -1
- package/src/api/index.ts +61 -24
- package/src/components/account-settings/index.tsx +161 -0
- package/src/components/account-settings/style.css +200 -0
- package/src/components/billing-info-container/index.tsx +121 -77
- package/src/components/billing-info-container/style.css +1 -1
- package/src/components/billing-info-container/utils.ts +11 -3
- package/src/components/common/PhoneNumberField.tsx +68 -0
- package/src/components/common/SnackbarAlert.tsx +1 -1
- package/src/components/common/dist/PhoneNumberField.js +96 -0
- package/src/components/common/index.tsx +1 -0
- package/src/components/confirmationContainer/index.tsx +19 -9
- package/src/components/countdown/index.tsx +3 -1
- package/src/components/forgotPasswordModal/index.tsx +107 -0
- package/src/components/forgotPasswordModal/style.css +47 -0
- package/src/components/index.ts +1 -0
- package/src/components/loginModal/index.tsx +72 -71
- package/src/components/myTicketsContainer/index.tsx +99 -95
- package/src/components/myTicketsContainer/style.css +2 -2
- package/src/components/myTicketsContainer/tableConfig.tsx +3 -6
- package/src/components/orderDetailsContainer/index.tsx +75 -21
- package/src/components/orderDetailsContainer/style.css +3 -3
- package/src/components/orderDetailsContainer/ticketsTable.tsx +130 -83
- package/src/components/paymentContainer/index.tsx +114 -49
- package/src/components/registerModal/index.tsx +3 -10
- package/src/components/resetPasswordContainer/index.tsx +96 -0
- package/src/components/resetPasswordContainer/style.css +36 -0
- package/src/components/signupModal/index.tsx +195 -0
- package/src/components/signupModal/style.css +58 -0
- package/src/components/stripePayment/index.tsx +14 -12
- package/src/components/stripePayment/style.css +3 -3
- package/src/components/ticketResaleModal/index.tsx +12 -14
- package/src/components/ticketsContainer/PromoCodeSection.tsx +8 -7
- package/src/components/ticketsContainer/TicketRow.tsx +12 -6
- package/src/components/ticketsContainer/TicketsSection.tsx +0 -3
- package/src/components/ticketsContainer/index.tsx +92 -50
- package/src/env.ts +3 -3
- package/src/index.ts +3 -1
- package/src/utils/cookies.ts +42 -0
- package/src/utils/createCheckoutDataBodyWithDefaultHolder.ts +16 -4
- package/src/utils/downloadPDF.tsx +28 -6
- package/src/utils/getDomain.ts +15 -0
- package/src/utils/index.ts +2 -0
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getEvent,
|
|
9
9
|
addToCart,
|
|
10
10
|
postOnCheckout,
|
|
11
|
+
logout,
|
|
11
12
|
} from '../../api'
|
|
12
13
|
import _get from 'lodash/get'
|
|
13
14
|
import _some from 'lodash/some'
|
|
@@ -22,7 +23,12 @@ import { PromoCodeSection } from './PromoCodeSection'
|
|
|
22
23
|
import { AccessCodeSection } from './AccessCodeSection'
|
|
23
24
|
import { LoginModal } from '../loginModal'
|
|
24
25
|
import Countdown from '../countdown'
|
|
25
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
createCheckoutDataBodyWithDefaultHolder,
|
|
28
|
+
getQueryVariable,
|
|
29
|
+
deleteCookieByName,
|
|
30
|
+
getCookieByName,
|
|
31
|
+
} from '../../utils'
|
|
26
32
|
import { ThemeProvider } from '@mui/private-theming'
|
|
27
33
|
import { createTheme, ThemeOptions } from '@mui/material'
|
|
28
34
|
import { CSSProperties } from '@mui/styles'
|
|
@@ -46,15 +52,21 @@ export interface IGetTickets {
|
|
|
46
52
|
onAddToCartError: (e: AxiosError) => void;
|
|
47
53
|
onGetTicketsSuccess: (response: any) => void;
|
|
48
54
|
onGetTicketsError: (e: AxiosError) => void;
|
|
55
|
+
onLogoutSuccess: () => void;
|
|
56
|
+
onLogoutError: (e: AxiosError) => void;
|
|
49
57
|
onLoginSuccess: () => void;
|
|
50
58
|
|
|
51
59
|
theme?: 'light' | 'dark';
|
|
52
60
|
queryPromoCode?: string;
|
|
53
61
|
isPromotionsEnabled?: boolean;
|
|
54
|
-
themeOptions?: ThemeOptions & {
|
|
62
|
+
themeOptions?: ThemeOptions & {
|
|
63
|
+
input?: CSSProperties;
|
|
64
|
+
checkbox?: CSSProperties;
|
|
65
|
+
};
|
|
55
66
|
isAccessCodeEnabled?: boolean;
|
|
56
67
|
hideSessionButtons?: boolean;
|
|
57
68
|
hideWaitingList?: boolean;
|
|
69
|
+
enableBillingInfoAutoCreate?: boolean;
|
|
58
70
|
isButtonScrollable?: boolean;
|
|
59
71
|
sortBySoldOut?: boolean;
|
|
60
72
|
disableCountdownLeadingZero?: boolean;
|
|
@@ -65,12 +77,12 @@ export interface IGetTickets {
|
|
|
65
77
|
}
|
|
66
78
|
|
|
67
79
|
export interface ITicket {
|
|
68
|
-
id: string | number
|
|
69
|
-
[key: string]: string | number
|
|
80
|
+
id: string | number
|
|
81
|
+
[key: string]: string | number
|
|
70
82
|
}
|
|
71
83
|
|
|
72
84
|
export interface ISelectedTickets {
|
|
73
|
-
[key: string]: string | number
|
|
85
|
+
[key: string]: string | number
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
export const TicketsContainer = ({
|
|
@@ -82,6 +94,8 @@ export const TicketsContainer = ({
|
|
|
82
94
|
onAddToCartError = () => {},
|
|
83
95
|
onGetTicketsSuccess = () => {},
|
|
84
96
|
onGetTicketsError = () => {},
|
|
97
|
+
onLogoutSuccess = () => {},
|
|
98
|
+
onLogoutError = () => {},
|
|
85
99
|
theme = 'light',
|
|
86
100
|
queryPromoCode = '',
|
|
87
101
|
isPromotionsEnabled = true,
|
|
@@ -89,6 +103,7 @@ export const TicketsContainer = ({
|
|
|
89
103
|
isAccessCodeEnabled = false,
|
|
90
104
|
hideSessionButtons = false,
|
|
91
105
|
hideWaitingList = false,
|
|
106
|
+
enableBillingInfoAutoCreate = true,
|
|
92
107
|
isButtonScrollable = false,
|
|
93
108
|
sortBySoldOut = false,
|
|
94
109
|
disableCountdownLeadingZero = false,
|
|
@@ -97,12 +112,12 @@ export const TicketsContainer = ({
|
|
|
97
112
|
ticketsHeaderComponent,
|
|
98
113
|
hideTicketsHeader = false
|
|
99
114
|
}: IGetTickets) => {
|
|
100
|
-
const [selectedTickets, setSelectedTickets] = useState(
|
|
101
|
-
{} as ISelectedTickets
|
|
102
|
-
)
|
|
115
|
+
const [selectedTickets, setSelectedTickets] = useState({} as ISelectedTickets)
|
|
103
116
|
const isWindowDefined = typeof window !== 'undefined'
|
|
117
|
+
const xtfCookie = getCookieByName('X-TF-ECOMMERCE')
|
|
104
118
|
const [isLogged, setIsLogged] = useState(
|
|
105
|
-
isWindowDefined ? !!window.localStorage.getItem('access_token') : false
|
|
119
|
+
(isWindowDefined ? !!window.localStorage.getItem('access_token') : false) ||
|
|
120
|
+
!!xtfCookie
|
|
106
121
|
)
|
|
107
122
|
const [showLoginModal, setShowLoginModal] = useState(false)
|
|
108
123
|
const [tickets, setTickets] = useState([] as ITicket[])
|
|
@@ -136,13 +151,20 @@ export const TicketsContainer = ({
|
|
|
136
151
|
!!eventId && getTicketsApi()
|
|
137
152
|
}, [eventId])
|
|
138
153
|
|
|
139
|
-
const handleLogout = () => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
154
|
+
const handleLogout = async () => {
|
|
155
|
+
try {
|
|
156
|
+
await logout()
|
|
157
|
+
onLogoutSuccess()
|
|
158
|
+
if (isWindowDefined) {
|
|
159
|
+
window.localStorage.removeItem('access_token')
|
|
160
|
+
window.localStorage.removeItem('user_data')
|
|
161
|
+
setIsLogged(false)
|
|
162
|
+
const event = new window.CustomEvent('tf-logout')
|
|
163
|
+
deleteCookieByName('X-TF-ECOMMERCE')
|
|
164
|
+
window.document.dispatchEvent(event)
|
|
165
|
+
}
|
|
166
|
+
} catch (e) {
|
|
167
|
+
onLogoutError(e)
|
|
146
168
|
}
|
|
147
169
|
}
|
|
148
170
|
|
|
@@ -154,10 +176,12 @@ export const TicketsContainer = ({
|
|
|
154
176
|
: {}
|
|
155
177
|
if (userData.country === '') {
|
|
156
178
|
handleLogout()
|
|
157
|
-
window.open(
|
|
179
|
+
window.open(
|
|
180
|
+
'https://www.ticketfairy.com/account/change_information?need_country=true'
|
|
181
|
+
)
|
|
158
182
|
}
|
|
159
183
|
}
|
|
160
|
-
} catch(e) {}
|
|
184
|
+
} catch (e) {}
|
|
161
185
|
}, [])
|
|
162
186
|
|
|
163
187
|
const handleExternalLogin = () => {
|
|
@@ -174,14 +198,14 @@ export const TicketsContainer = ({
|
|
|
174
198
|
}
|
|
175
199
|
}
|
|
176
200
|
|
|
177
|
-
async function getTicketsApi(isUpdateingCode?: boolean) {
|
|
201
|
+
async function getTicketsApi(isUpdateingCode?: boolean, type?: string) {
|
|
178
202
|
try {
|
|
179
203
|
isUpdateingCode ? setCodeIsLoading(true) : setIsLoading(true)
|
|
180
204
|
const response = await getTickets(eventId, code)
|
|
181
205
|
const eventResponse = await getEvent(eventId)
|
|
182
206
|
if (response.data.success) {
|
|
183
207
|
const attributes = _get(response, 'data.data.attributes')
|
|
184
|
-
setCodeIsApplied(attributes.ValidPromoCode)
|
|
208
|
+
type === 'promo' && setCodeIsApplied(attributes.ValidPromoCode)
|
|
185
209
|
setTickets(_get(attributes, 'tickets'))
|
|
186
210
|
setShowWaitingList(attributes.showWaitingList)
|
|
187
211
|
onGetTicketsSuccess(response.data)
|
|
@@ -282,10 +306,9 @@ export const TicketsContainer = ({
|
|
|
282
306
|
userData
|
|
283
307
|
)
|
|
284
308
|
|
|
285
|
-
const checkoutResult =
|
|
286
|
-
checkoutBody,
|
|
287
|
-
|
|
288
|
-
)
|
|
309
|
+
const checkoutResult = enableBillingInfoAutoCreate
|
|
310
|
+
? await postOnCheckout(checkoutBody, access_token)
|
|
311
|
+
: null
|
|
289
312
|
|
|
290
313
|
hash = _get(checkoutResult, 'data.data.attributes.hash')
|
|
291
314
|
total = _get(checkoutResult, 'data.data.attributes.total')
|
|
@@ -310,17 +333,20 @@ export const TicketsContainer = ({
|
|
|
310
333
|
}
|
|
311
334
|
}
|
|
312
335
|
|
|
313
|
-
const updateTickets = (isUpdateingCode?: boolean) => {
|
|
314
|
-
getTicketsApi(isUpdateingCode)
|
|
336
|
+
const updateTickets = (isUpdateingCode?: boolean, type?: string) => {
|
|
337
|
+
getTicketsApi(isUpdateingCode, type)
|
|
315
338
|
}
|
|
316
339
|
|
|
317
340
|
const isTicketOnSale = _some(
|
|
318
341
|
tickets,
|
|
319
|
-
item =>
|
|
342
|
+
item => item.salesStarted && !item.salesEnded && !item.soldOut
|
|
320
343
|
)
|
|
321
344
|
|
|
345
|
+
const eventHasTickets = !_isEmpty(tickets)
|
|
346
|
+
const isSalesClosed = event?.salesEnded
|
|
347
|
+
|
|
322
348
|
const themeMui = createTheme(themeOptions)
|
|
323
|
-
|
|
349
|
+
|
|
324
350
|
useEffect(() => {
|
|
325
351
|
isWindowDefined &&
|
|
326
352
|
window.document.addEventListener('custom-logout', handleLogout)
|
|
@@ -335,24 +361,36 @@ export const TicketsContainer = ({
|
|
|
335
361
|
window.document.addEventListener('custom-login', handleExternalLogin)
|
|
336
362
|
return () => {
|
|
337
363
|
isWindowDefined &&
|
|
338
|
-
window.document.removeEventListener(
|
|
339
|
-
'custom-login',
|
|
340
|
-
handleExternalLogin
|
|
341
|
-
)
|
|
364
|
+
window.document.removeEventListener('custom-login', handleExternalLogin)
|
|
342
365
|
}
|
|
343
366
|
}, [])
|
|
344
367
|
|
|
345
368
|
const handleGetTicketClick = () => {
|
|
346
|
-
if (
|
|
369
|
+
if (
|
|
370
|
+
!handleBookIsLoading &&
|
|
371
|
+
!_isEmpty(selectedTickets) &&
|
|
372
|
+
Object.values(selectedTickets)[0] > 0
|
|
373
|
+
) {
|
|
347
374
|
handleBook()
|
|
348
375
|
} else {
|
|
349
|
-
if (
|
|
350
|
-
|
|
376
|
+
if (
|
|
377
|
+
isButtonScrollable &&
|
|
378
|
+
ticketsContainerRef &&
|
|
379
|
+
ticketsContainerRef.current
|
|
380
|
+
) {
|
|
381
|
+
ticketsContainerRef.current.scrollIntoView({
|
|
382
|
+
behavior: 'smooth',
|
|
383
|
+
block: 'center',
|
|
384
|
+
inline: 'nearest',
|
|
385
|
+
})
|
|
351
386
|
}
|
|
352
387
|
}
|
|
353
388
|
}
|
|
354
389
|
|
|
355
|
-
const bookButtonIsDisabled =
|
|
390
|
+
const bookButtonIsDisabled =
|
|
391
|
+
handleBookIsLoading ||
|
|
392
|
+
_isEmpty(selectedTickets) ||
|
|
393
|
+
Object.values(selectedTickets)[0] === 0
|
|
356
394
|
|
|
357
395
|
const wrappedActionsSectionComponent = React.isValidElement(ActionsSectionComponent) ? React.cloneElement(ActionsSectionComponent as React.ReactElement<any>, {
|
|
358
396
|
handleGetTicketClick,
|
|
@@ -370,23 +408,27 @@ export const TicketsContainer = ({
|
|
|
370
408
|
<Loader />
|
|
371
409
|
) : (
|
|
372
410
|
<div ref={ticketsContainerRef}>
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
411
|
+
{!isSalesClosed && (
|
|
412
|
+
<TicketsSection
|
|
413
|
+
ticketsList={tickets}
|
|
414
|
+
selectedTickets={selectedTickets}
|
|
415
|
+
handleTicketSelect={handleTicketSelect}
|
|
416
|
+
sortBySoldOut={sortBySoldOut}
|
|
417
|
+
ticketsHeaderComponent={ticketsHeaderComponent}
|
|
418
|
+
hideTicketsHeader={hideTicketsHeader || _isEmpty(tickets)}
|
|
419
|
+
/>
|
|
420
|
+
)}
|
|
421
|
+
{externalUrl ? null : isSalesClosed ? (
|
|
422
|
+
<p className={`event-closed-message ${!isLoggedIn ? 'event-closed-on-bottom' : ''}`}>
|
|
423
|
+
Sales for this event are closed.
|
|
424
|
+
</p>
|
|
384
425
|
) : eventSaleIsNotStarted ? (
|
|
385
426
|
<Countdown
|
|
386
427
|
startDate={event.salesStart}
|
|
387
428
|
timezone={event.timezone}
|
|
388
429
|
title="Sales start in:"
|
|
389
430
|
message="No tickets are currently available for this event."
|
|
431
|
+
showMessage={!eventHasTickets}
|
|
390
432
|
callback={updateTickets}
|
|
391
433
|
disableLeadingZero={disableCountdownLeadingZero}
|
|
392
434
|
isLoggedIn={isLoggedIn}
|
|
@@ -395,10 +437,9 @@ export const TicketsContainer = ({
|
|
|
395
437
|
{showWaitingList && event.salesStarted && !hideWaitingList && (
|
|
396
438
|
<WaitingList tickets={tickets} eventId={eventId} />
|
|
397
439
|
)}
|
|
398
|
-
{
|
|
399
|
-
codeIsLoading ? (
|
|
440
|
+
{codeIsLoading ? (
|
|
400
441
|
<Loader />
|
|
401
|
-
) : showAccessCodeSection ? (
|
|
442
|
+
) : isSalesClosed ? null : showAccessCodeSection ? (
|
|
402
443
|
<AccessCodeSection
|
|
403
444
|
code={code}
|
|
404
445
|
setCode={setCode}
|
|
@@ -408,6 +449,7 @@ export const TicketsContainer = ({
|
|
|
408
449
|
<PromoCodeSection
|
|
409
450
|
code={code}
|
|
410
451
|
codeIsApplied={codeIsApplied}
|
|
452
|
+
setCodeIsApplied={setCodeIsApplied}
|
|
411
453
|
showPromoInput={showPromoInput}
|
|
412
454
|
setShowPromoInput={setShowPromoInput}
|
|
413
455
|
setCode={setCode}
|
package/src/env.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// preview
|
|
2
2
|
export const ENV = {
|
|
3
|
-
EVENT_ID:
|
|
4
|
-
BASE_URL: 'https://
|
|
5
|
-
CLIENT_ID: '
|
|
3
|
+
EVENT_ID: 12906,
|
|
4
|
+
BASE_URL: 'https://test.ticketfairy.com',
|
|
5
|
+
CLIENT_ID: 'e9d8f8922797b4621e562255afe90dbf',
|
|
6
6
|
CLIENT_SECRET: 'b89c191eff22fdcf84ac9bfd88d005355a151ec2c83b26b9',
|
|
7
7
|
STRIPE_PUBLISHABLE_KEY:
|
|
8
8
|
'pk_test_51H4BkOGqveRD6EShliLrT9vd7mPOBPvQSuqmvc3wIinDqxWsCLeS2N7HonPPn6MhjU35ayYy5v4I6MLlD4jNWrd000NSgAF6UL',
|
package/src/index.ts
CHANGED
|
@@ -12,4 +12,6 @@ export { OrderDetailsContainer } from './components/orderDetailsContainer'
|
|
|
12
12
|
export { setConfigs } from './utils/setConfigs'
|
|
13
13
|
export { TicketResaleContainer } from './components'
|
|
14
14
|
export { RedirectModal } from './components/common/RedirectModal'
|
|
15
|
-
export { RsvpContainer } from './components/rsvpContainer'
|
|
15
|
+
export { RsvpContainer } from './components/rsvpContainer'
|
|
16
|
+
export { ResetPasswordContainer } from './components/resetPasswordContainer'
|
|
17
|
+
export { ForgotPasswordModal } from './components/forgotPasswordModal'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getDomain } from './getDomain'
|
|
2
|
+
|
|
3
|
+
export function setCustomCookie(name: string, value: string, days: number = 5) {
|
|
4
|
+
let expires = ''
|
|
5
|
+
if (days) {
|
|
6
|
+
let date = new Date()
|
|
7
|
+
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000)
|
|
8
|
+
expires = '; expires=' + date.toUTCString()
|
|
9
|
+
}
|
|
10
|
+
if (typeof window !== 'undefined') {
|
|
11
|
+
const domain = getDomain(window.location.hostname)
|
|
12
|
+
document.cookie =
|
|
13
|
+
name + '=' + (value || '') + expires + '; path=/' + `; domain=${domain}`
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getCookieByName(cname: string) {
|
|
18
|
+
if (typeof window === 'undefined') return ''
|
|
19
|
+
let name = cname + '='
|
|
20
|
+
let ca = document.cookie.split(';')
|
|
21
|
+
for (let i = 0; i < ca.length; i++) {
|
|
22
|
+
let c = ca[i]
|
|
23
|
+
while (c.charAt(0) == ' ') {
|
|
24
|
+
c = c.substring(1)
|
|
25
|
+
}
|
|
26
|
+
if (c.indexOf(name) == 0) {
|
|
27
|
+
return c.substring(name.length, c.length)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return ''
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function deleteCookieByName(name: string) {
|
|
34
|
+
if (typeof window !== 'undefined') {
|
|
35
|
+
const domain = getDomain(window.location.hostname)
|
|
36
|
+
document.cookie =
|
|
37
|
+
name +
|
|
38
|
+
'=; Path=/' +
|
|
39
|
+
`; domain=${domain}` +
|
|
40
|
+
'; Expires=Thu, 01 Jan 1970 00:00:01 GMT;'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -13,21 +13,33 @@ interface IticketHolder {
|
|
|
13
13
|
email?: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
interface IUserCredentialsValues {
|
|
17
|
+
emailLogged?: string;
|
|
18
|
+
firstNameLogged?: string;
|
|
19
|
+
lastNameLogged?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
export const createCheckoutDataBodyWithDefaultHolder = (
|
|
17
23
|
ticketsQuantity: number,
|
|
18
24
|
logedInValues: {},
|
|
19
|
-
includeDob: boolean = false
|
|
25
|
+
includeDob: boolean = false,
|
|
26
|
+
userCredentials: IUserCredentialsValues = {}
|
|
20
27
|
): ICheckoutBody => {
|
|
21
28
|
const ticket_holders: IticketHolder[] = []
|
|
22
29
|
|
|
23
30
|
const first_name =
|
|
24
|
-
_get(logedInValues, 'firstName') ||
|
|
31
|
+
_get(logedInValues, 'firstName') ||
|
|
32
|
+
_get(logedInValues, 'first_name') ||
|
|
33
|
+
_get(userCredentials, 'firstNameLogged') ||
|
|
34
|
+
''
|
|
35
|
+
|
|
25
36
|
const last_name =
|
|
26
|
-
_get(logedInValues, 'lastName'
|
|
37
|
+
_get(logedInValues, 'lastName') ||
|
|
27
38
|
_get(logedInValues, 'last_name') ||
|
|
39
|
+
_get(userCredentials, 'lastNameLogged') ||
|
|
28
40
|
''
|
|
29
41
|
const phone = _get(logedInValues, 'phone', '')
|
|
30
|
-
const email = _get(logedInValues, 'email', '')
|
|
42
|
+
const email = _get(logedInValues, 'email') || _get(userCredentials, 'emailLogged') || ''
|
|
31
43
|
|
|
32
44
|
for (let i = 0; i <= ticketsQuantity - 1; i++) {
|
|
33
45
|
const individualHolder = i
|
|
@@ -1,23 +1,42 @@
|
|
|
1
|
+
import { getCookieByName } from './cookies'
|
|
2
|
+
|
|
1
3
|
export const downloadPDF = (pdfUrl: string) => {
|
|
2
4
|
if (typeof window === 'undefined') return
|
|
3
5
|
|
|
6
|
+
const xtfCookie = getCookieByName('X-TF-ECOMMERCE')
|
|
4
7
|
const accessToken: string | null = localStorage.getItem('access_token')
|
|
5
8
|
|
|
6
|
-
if (!accessToken) return
|
|
9
|
+
if (!accessToken && !xtfCookie) return
|
|
10
|
+
|
|
11
|
+
let headers = {}
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
headers
|
|
13
|
+
if (accessToken) {
|
|
14
|
+
headers = {
|
|
10
15
|
Authorization: `Bearer ${accessToken}`,
|
|
11
|
-
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (xtfCookie) {
|
|
20
|
+
headers = {
|
|
21
|
+
'X-TF-ECOMMERCE': xtfCookie,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return fetch(pdfUrl, {
|
|
26
|
+
headers,
|
|
27
|
+
credentials: 'include',
|
|
12
28
|
})
|
|
13
29
|
.then(async response => {
|
|
14
30
|
const blobValue = await response.blob()
|
|
15
|
-
const fileNameHeader = response.headers.get(
|
|
31
|
+
const fileNameHeader = response.headers.get('content-disposition') || ''
|
|
16
32
|
const fileName = fileNameHeader.split('"')[1]
|
|
17
33
|
return { blobValue, fileName }
|
|
18
34
|
})
|
|
19
35
|
.then(({ blobValue, fileName }) => {
|
|
20
|
-
if (!fileName)
|
|
36
|
+
if (!fileName) {
|
|
37
|
+
throw Error('Something went wrong.')
|
|
38
|
+
return
|
|
39
|
+
}
|
|
21
40
|
const file = new Blob([blobValue], { type: 'application/pdf' })
|
|
22
41
|
const fileURL = URL.createObjectURL(file)
|
|
23
42
|
const link = document.createElement('a')
|
|
@@ -27,4 +46,7 @@ export const downloadPDF = (pdfUrl: string) => {
|
|
|
27
46
|
link.click()
|
|
28
47
|
document.body.removeChild(link)
|
|
29
48
|
})
|
|
49
|
+
.catch(error => {
|
|
50
|
+
return error
|
|
51
|
+
})
|
|
30
52
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function getDomain(url: string, subdomain?: string): string {
|
|
2
|
+
let updatedUrl: any = url.replace(/(https?:\/\/)?(www.)?/i, '')
|
|
3
|
+
|
|
4
|
+
if (!subdomain) {
|
|
5
|
+
updatedUrl = updatedUrl.split('.')
|
|
6
|
+
|
|
7
|
+
updatedUrl = updatedUrl.slice(updatedUrl.length - 2).join('.')
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (updatedUrl.indexOf('/') !== -1) {
|
|
11
|
+
return updatedUrl.split('/')[0]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return updatedUrl
|
|
15
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -3,3 +3,5 @@ export { getQueryVariable } from './getQueryVariable'
|
|
|
3
3
|
export { ErrorFocus } from './formikErrorFocus'
|
|
4
4
|
export { downloadPDF } from './downloadPDF'
|
|
5
5
|
export { createCheckoutDataBodyWithDefaultHolder } from './createCheckoutDataBodyWithDefaultHolder'
|
|
6
|
+
export { setCustomCookie, getCookieByName, deleteCookieByName } from './cookies'
|
|
7
|
+
export { getDomain } from './getDomain'
|