import React, { useEffect } from 'react'; import { LearnMoreColumn, TravelMiniCTAProps } from './types'; import { Container, ContentWrapper, LeftSection, TextContainer, Description, RightSection, ButtonsContainer, PrimaryButton, StyledTHLogo, LearnMoreButton, LearnMoreLabel, ExpandableSection, ExpandableIntro, ColumnsGrid, ColumnItem, ColumnTitle, ColumnDescription, ColumnPhoneLink, ColumnPhoneNumber } from './styles'; import { getAppContentLocation } from '../../utils'; import { TravelEnquiryForm } from '../travel-enquiry-form'; import { ChevronDown } from '../travel-enquiry-form/ChevronDown'; // Extend Window interface for LivePerson declare global { interface Window { lpTag?: { [key: string]: any; }; utag?: { link: (params: Record) => void; }; } } const DEFAULT_LEARN_MORE_INTRO = 'For years, The Times and The Sunday Times have been a trusted source of travel inspiration thanks to our award-winning journalists. Now with Times Holidays, our in-house agency, you can book your next getaway directly with us.'; const DEFAULT_LEARN_MORE_COLUMNS: LearnMoreColumn[] = [ { title: "Book the trips you've read about ", description: 'If you loved a particular feature, you can book the exact itinerary the writer experienced with us.' }, { title: 'Expert recommendations', description: 'Our dedicated advisors only work with partners approved by the editorial team for a trip you can trust.' }, { title: 'A holiday made just for you', description: 'Our network of premier travel partners will help us curate a bespoke itinerary based on your preferences.' }, { title: 'Call us on', phone: { number: '0808 1342945' }, description: 'Opening hours:\nMon-Fri: 9am-6pm\nSat & Sun: 10am-5pm' } ]; export const TravelMiniCTA: React.FC = ({ isApp, isOnChannelPage, learnMoreIntro = DEFAULT_LEARN_MORE_INTRO, learnMoreColumns = DEFAULT_LEARN_MORE_COLUMNS, learnMoreColumnCount = 4 }) => { const [showEnquiryForm, setShowEnquiryForm] = React.useState(false); const [isExpanded, setIsExpanded] = React.useState(false); const travelMiniCTARef = React.useRef(null); const hasLearnMoreColumns = Boolean( learnMoreColumns && learnMoreColumns.length > 0 ); const hasLearnMoreContent = Boolean(learnMoreIntro) || hasLearnMoreColumns; const handleOnClickTracking = (userInteraction: string) => window.utag && window.utag.link({ event_navigation_action: 'navigation', event_navigation_name: `mini slice: ${userInteraction.toLowerCase()}`, event_navigation_browsing_method: 'click', app_content_location: getAppContentLocation('nuk_preferred_edition') }); const setupImpressionTracking = () => { const element = travelMiniCTARef.current; if (!element) { return; } const intersectionObserver = new IntersectionObserver( entries => { entries.forEach(entry => { if (entry.isIntersecting && window.utag) { window.utag.link({ event_navigation_action: 'navigation', event_navigation_name: 'mini slice: impression', event_navigation_browsing_method: 'scroll', app_content_location: getAppContentLocation( 'nuk_preferred_edition' ) }); intersectionObserver.unobserve(entry.target); } }); }, { threshold: 0.5 } ); intersectionObserver.observe(element); return () => { intersectionObserver.unobserve(element); }; }; useEffect(() => { if (typeof window === 'undefined') { return; } const cleanupTracking = setupImpressionTracking(); return () => { if (cleanupTracking) { cleanupTracking(); } }; }, []); return ( You can now book your holiday with The Times via our own travel agency. {hasLearnMoreContent && ( { handleOnClickTracking(isExpanded ? 'Close' : 'Learn more'); setIsExpanded(prev => !prev); }} > {isExpanded ? 'Close' : 'Learn more'} )} {isApp ? ( handleOnClickTracking('Enquire now')} isApp={isApp} data-testid="travel-enquire-button" > Enquire now ) : ( { handleOnClickTracking('Enquire now'); setShowEnquiryForm(true); }} isApp={isApp} data-testid="travel-enquire-button" > Enquire now )} {hasLearnMoreContent && ( { handleOnClickTracking(isExpanded ? 'Close' : 'Learn more'); setIsExpanded(prev => !prev); }} > {isExpanded ? 'Close' : 'Learn more'} )} {isExpanded && hasLearnMoreContent && ( {learnMoreIntro && ( {learnMoreIntro} )} {hasLearnMoreColumns && ( {(learnMoreColumns || []).map((column, index) => { const phoneLink = column.phone && ( handleOnClickTracking('phone number click') } isApp={isApp} > {column.phone.number} ); return ( {column.title} {phoneLink && <> {phoneLink}} {column.description && ( {column.description} )} ); })} )} )} {showEnquiryForm && ( setShowEnquiryForm(false)} /> )} ); };