import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react' import getMeta from '@/utils/meta' import * as eventTracking from '@/infrastructure/event-tracking' import TimeoutMessageAfterPaywallDismissal from './timeout-message-after-paywall-dismissal' import { UpgradePrompt } from '@/shared/components/upgrade-prompt' const studentRoles = [ 'High-school student', 'Undergraduate student', "Master's student (e.g. MSc, MA)", 'Doctoral student (e.g. PhD, MD, EngD)', ] type Segmentation = Record< string, string | number | boolean | undefined | unknown | any > interface TimeoutUpgradePaywallPromptProps { setIsShowingPrimary: Dispatch> } function TimeoutUpgradePaywallPrompt({ setIsShowingPrimary, }: TimeoutUpgradePaywallPromptProps) { const odcRole = getMeta('ol-odcRole') const planPrices = getMeta('ol-paywallPlans') const isStudent = useMemo(() => studentRoles.includes(odcRole), [odcRole]) const [isPaywallDismissed, setIsPaywallDismissed] = useState(false) function sendPaywallEvent(event: string, segmentation?: Segmentation) { eventTracking.sendMB(event, { 'paywall-type': 'compile-timeout', 'paywall-version': 'primary', ...segmentation, }) } function onClose() { sendPaywallEvent('paywall-dismiss') setIsPaywallDismissed(true) setIsShowingPrimary(false) } function onClickInfoLink() { sendPaywallEvent('paywall-info-click', { content: 'plans' }) } function onClickPaywall() { sendPaywallEvent('paywall-click', { plan: isStudent ? 'student' : 'collaborator', }) } useEffect(() => { sendPaywallEvent('paywall-prompt', { plan: isStudent ? 'student' : 'collaborator', }) setIsShowingPrimary(true) }, [isStudent, setIsShowingPrimary]) return (
{!isPaywallDismissed ? ( ) : ( )}
) } export default TimeoutUpgradePaywallPrompt