/* eslint-disable max-len */ import './style.css' import { Button } from '@mui/material' import axios, { AxiosError } from 'axios' import _get from 'lodash/get' import _identity from 'lodash/identity' import _map from 'lodash/map' import React, { SyntheticEvent, useEffect, useRef, useState } from 'react' import { getConfirmationData } from '../../api' import { usePixel } from '../../hooks/usePixel' import { IReferralPromotion } from '../../types' import { createMarkup, getCookieByName, isBrowser } from '../../utils' import { CopyMessageModal } from '../common' import SocialButtons from './social-buttons' export interface IShareButton { mainLabel: string; subLabel: string; platform: string; shareData: any; points?: number | string; onAfterShare?: (event: SyntheticEvent) => void; eventActionId?: string; oneTimeAction?: boolean; alreadyApplied?: boolean; btnClassName?: string; } export interface IConfirmationLabels { confirmationTitle?: string; confirmationMain?: string; confirmationHelper?: string; paymentPlanConfirmationTitle?: string; paymentPlanConfirmationMain?: string; paymentPlanConfirmationHelper?: string; } export interface IConfirmationPage { hasCopyIcon?: boolean; isReferralEnabled: boolean; showDefaultShareButtons: boolean; messengerAppId: string; shareButtons: IShareButton[]; onGetConfirmationDataSuccess: (res: ICheckoutCompleteData) => void; onGetConfirmationDataError: (e: AxiosError) => void; onLinkCopied: () => void; orderHash?: string; confirmationLabels: IConfirmationLabels; clientLabel?: string; showReferralsInfoText?: boolean; showCopyInfoModal?: boolean; showPricingNoteSection?: boolean; showOrderDetailsBtn?: boolean; onOrderDetailsClick?: (data: ICheckoutCompleteData) => void; showProductImage?: boolean; eventTitle?: string; eventDate?: string; eventLocation?: string; } export const ConfirmationContainer = ({ confirmationLabels, hasCopyIcon = true, isReferralEnabled, showDefaultShareButtons, messengerAppId = '', shareButtons = [], onGetConfirmationDataSuccess = _identity, onGetConfirmationDataError = _identity, orderHash, onLinkCopied = _identity, clientLabel, showReferralsInfoText = false, showCopyInfoModal = false, showPricingNoteSection = false, showOrderDetailsBtn = false, onOrderDetailsClick = _identity, showProductImage = true, eventTitle, eventDate, eventLocation, }: IConfirmationPage) => { const inputRef = useRef(null) const [data, setData] = useState(null) const dataEncoded = (isBrowser && window.localStorage.getItem('checkoutData')) || '' const dataDecoded = dataEncoded ? JSON.parse(dataEncoded) : { hash: orderHash } const { hash } = dataDecoded const eventId = data?.product_id || '' useEffect(() => { (async () => { if (hash) { try { const confirmationDataResponse = await getConfirmationData(hash) const data = confirmationDataResponse.data.attributes data.personal_share_sales = data.personal_share_sales.map(salesItem => { const salesData: IReferralPromotion = { label: `If your friends buy ${salesItem.sales} tickets`, price: '', } if (salesItem.price === 0) { salesData.subLabel = 'Your ticket becomes' salesData.price = 'FREE!' } else { salesData.subLabel = 'Your ticket goes down to' salesData.price = data.currency.symbol + Number(salesItem.price).toFixed(2) } return salesData }) data.personal_share_sales.unshift({ label: 'Your ticket is currently', price: data.currency.symbol + data.product_price?.toFixed(2), }) // Ensure order_hash is included in the data if (!data.order_hash) { data.order_hash = hash } setData(data) onGetConfirmationDataSuccess(confirmationDataResponse.data.attributes) // Clear user_data for non-logged-in users after successful purchase if (isBrowser) { const isLoggedIn = Boolean(getCookieByName('X-TF-ECOMMERCE')) if (!isLoggedIn) { window.localStorage.removeItem('user_data') } } } catch (error) { if (axios.isAxiosError(error)) onGetConfirmationDataError(error) } } })() }, [hash]) const [showCopyModal, setShowCopyModal] = useState(false) const onClose = () => { setShowCopyModal(false) } const onChangeShareLink = (e: React.ChangeEvent) => { const newData = { ...data, personal_share_link: e.target.value, } as ICheckoutCompleteData setData(newData) } const { confirmationTitle = 'Your Tickets are Confirmed!', confirmationMain = 'Your tickets are available in My Tickets section', confirmationHelper = 'Please bring them with you to the event', paymentPlanConfirmationTitle = 'Your Tickets are Confirmed!', paymentPlanConfirmationMain = 'Your payment plan is pending and we are trying to take your initial payment. If your initial payment does not complete, your payment plan will be cancelled.', paymentPlanConfirmationHelper = 'You will receive a confirmation with your tickets once your final payment has been made.', } = confirmationLabels const pageUrl = isBrowser ? window.location.href.split('?')[0] : '' usePixel(eventId, { page: 'complete', pageUrl, orderHash: hash }) return (
{showCopyInfoModal && ( )} {data && ( <>
{showProductImage && (
)}

{data.is_payment_plan ? paymentPlanConfirmationTitle : confirmationTitle}

{(eventTitle || eventDate || eventLocation) && (
{eventTitle &&
{eventTitle}
} {eventDate &&
{eventDate}
} {eventLocation &&
{eventLocation}
}
)}
{data.custom_confirmation_page_text && data.custom_confirmation_page_text_full_replacement ? undefined : ( <> {Boolean(data.is_payment_plan) && ( <> {paymentPlanConfirmationMain} {paymentPlanConfirmationHelper} )} {!data.is_payment_plan && ( <> {data.attach_tickets ? ( Your tickets have been emailed to you ) : ( {confirmationMain} )} {data.attach_tickets ? 'Please bring them with you to the event' : confirmationHelper} )} )}
{data.custom_confirmation_page_text && !data.custom_confirmation_page_text_full_replacement ? (
) : null} {showOrderDetailsBtn && (
)} {data.disable_referral === false && isReferralEnabled && ( <>
Your ticket can become cheaper or even FREE!
Invite friends and we'll refund up to 100% of your ticket money, if they buy tickets as well!
No Data
How do you invite your friends?
Send them this link:
{ navigator.clipboard.writeText( _get(inputRef, 'current.value') || '' ) setShowCopyModal(true) onLinkCopied() }} > {hasCopyIcon ? ( copy ) : ( Copy )}
{(showDefaultShareButtons || !!shareButtons.length) && ( )}
How much cheaper?
{_map(data.personal_share_sales, (pricing, index) => (
{pricing.label} {pricing.subLabel && (
{pricing.subLabel}
)}
{pricing.price}
))} {showPricingNoteSection && (
^ This is based on the most expensive ticket in your order.
)}
)} )}
) }