tf-checkout-react 1.3.39-beta.2 → 1.3.40

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.
@@ -1 +1 @@
1
- export declare const createElementFromHTML: (htmlString: string) => ChildNode | "";
1
+ export declare const createElementFromHTML: (htmlString: string) => NodeListOf<ChildNode>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.39-beta.2",
2
+ "version": "1.3.40",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -17,7 +17,10 @@
17
17
  "lint": "tsdx lint",
18
18
  "prepare": "tsdx build",
19
19
  "size": "size-limit",
20
- "analyze": "size-limit --why"
20
+ "analyze": "size-limit --why",
21
+ "release:beta": "npm version $(semver $(npm info $(npm info . name) version) -i prerelease --preid beta)",
22
+ "release:patch": "npm version $(semver $(npm info $(npm info . name) version) -i patch)",
23
+ "release:minor": "npm version $(semver $(npm info $(npm info . name) version) -i minor)"
21
24
  },
22
25
  "peerDependencies": {
23
26
  "react": ">=16"
@@ -520,7 +520,7 @@ export const BillingInfoContainer = React.memo(
520
520
  const initialCountry =
521
521
  selectedCountry.id || _get(userData, 'country', '') || '1'
522
522
 
523
- usePixel('checkoutPixels', eventId)
523
+ usePixel(['checkoutPixels', 'brandCheckoutPixels'], eventId)
524
524
 
525
525
  return (
526
526
  <ThemeProvider theme={themeMui}>
@@ -111,7 +111,7 @@ export const ConfirmationContainer = ({
111
111
  confirmationHelper = 'Please bring them with you to the event',
112
112
  } = confirmationLabels
113
113
 
114
- usePixel('conversionPixels', data?.product_id)
114
+ usePixel(['conversionPixels', 'brandConversionPixels'], data?.product_id)
115
115
 
116
116
  return (
117
117
  <div className="confirmation-page">
@@ -172,7 +172,7 @@ export const TicketsContainer = ({
172
172
  const ticketsContainerRef = useRef<HTMLDivElement>(null)
173
173
 
174
174
  useCookieListener(X_TF_ECOMMERCE, value => setIsLogged(Boolean(value)))
175
- usePixel('pagePixels', eventId)
175
+ usePixel(['pagePixels', 'brandPagePixels'], eventId, event)
176
176
 
177
177
  useEffect(() => {
178
178
  if (typeof window !== 'undefined') {
@@ -1,20 +1,49 @@
1
+ import _forEach from 'lodash/forEach'
1
2
  import _get from 'lodash/get'
2
3
  import { useEffect } from 'react'
3
4
 
4
5
  import { getEvent } from '../api'
5
6
  import { createElementFromHTML } from '../utils/htmlNodeFromString'
6
7
 
7
- export const usePixel = async (key: string, eventId: string | number) => {
8
- const getEventData = async () => {
9
- const eventResponse = await getEvent(eventId)
10
- const event = _get(eventResponse, 'data.data.attributes')
11
- const pixel = event[key]
8
+ export const usePixel = async (
9
+ key: string | string[],
10
+ eventId: string | number,
11
+ alreadyLoadedEventData?: any
12
+ ) => {
13
+ const addPixel = (pixel: string) => {
12
14
  if (document?.head && pixel) {
13
- document.head.append(createElementFromHTML(pixel))
15
+ const nodes = createElementFromHTML(pixel)
16
+ for (const element of Array.from(nodes)) {
17
+ document.head.append(element)
18
+ }
19
+ }
20
+ }
21
+
22
+ const getEventData = async () => {
23
+ if (!eventId) return
24
+ // Check if event data object passed or not. If not then the value will be undefined.
25
+ // If event data passed, then it's initial value will be null.
26
+ const isEventDataUndefined = alreadyLoadedEventData === undefined
27
+
28
+ const eventResponse = isEventDataUndefined ? await getEvent(eventId) : null
29
+
30
+ const event = isEventDataUndefined
31
+ ? _get(eventResponse, 'data.data.attributes', {})
32
+ : alreadyLoadedEventData || {}
33
+
34
+ if (typeof key === 'string') {
35
+ const pixel = event[key]
36
+ addPixel(pixel)
37
+ } else {
38
+ _forEach(key, item => {
39
+ const pixel = event[item]
40
+ addPixel(pixel)
41
+ })
14
42
  }
15
43
  }
16
44
 
17
45
  useEffect(() => {
18
46
  getEventData()
19
- }, [])
47
+ // eslint-disable-next-line react-hooks/exhaustive-deps
48
+ }, [eventId, alreadyLoadedEventData])
20
49
  }
@@ -2,5 +2,5 @@ export const createElementFromHTML = (htmlString: string) => {
2
2
  const div = document.createElement('div')
3
3
  div.innerHTML = htmlString.trim()
4
4
  // Change this to div.childNodes to support multiple top-level nodes.
5
- return div.firstChild || ''
5
+ return div.childNodes || []
6
6
  }