import '../../../../stylesheets/components/compile-time-paywall-modal.scss' import { OLModal, OLModalBody, OLModalHeader, OLModalTitle, } from '@/shared/components/ol/ol-modal' import OLButton from '@/shared/components/ol/ol-button' import MaterialIcon from '@/shared/components/material-icon' import BillingPeriodToggle, { type BillingPeriod, } from '@/shared/components/billing-period-toggle' import getMeta from '@/utils/meta' import { sendMB } from '@/infrastructure/event-tracking' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' const PLAN_CODE = { monthly: 'collaborator', annual: 'collaborator-annual', } as const export type CompileTimeoutPaywallModalProps = { show: boolean onHide: () => void } export function CompileTimeoutPaywallModal({ show, onHide, }: CompileTimeoutPaywallModalProps) { const { t } = useTranslation() const standardPlanPricing = getMeta('ol-standardPlanPricing') const currency = getMeta('ol-recommendedCurrency') const supportsAnnualPricing = Boolean(standardPlanPricing?.annual) const [annual, setAnnual] = useState(false) useEffect(() => { if (!show) { setAnnual(false) } }, [show]) const billingPeriod: BillingPeriod = annual ? 'annual' : 'monthly' const planCode = PLAN_CODE[billingPeriod] const hasShownRef = useRef(false) useEffect(() => { if (show && !hasShownRef.current) { const countryCode = getMeta('ol-countryCode') sendMB('paywall-plans-page-view', { 'paywall-type': 'compile-timeout', currency, countryCode, version: 'compile-timeout', }) hasShownRef.current = true } else if (!show) { hasShownRef.current = false } }, [show, currency]) const handleToggleBilling = useCallback(() => { const nextAnnual = !annual setAnnual(nextAnnual) sendMB('paywall-plans-page-toggle', { 'billing-period': nextAnnual ? 'annual' : 'monthly', checked: nextAnnual ? 'checked' : 'unchecked', version: 'compile-timeout', }) }, [annual]) const openCheckout = useCallback(() => { const params = new URLSearchParams({ itm_campaign: 'compile-timeout', }) window.open( `/user/subscription/new?planCode=${planCode}&${params.toString()}`, '_blank', 'noopener,noreferrer' ) }, [planCode]) const handleUpgrade = useCallback(() => { sendMB('paywall-plans-page-click', { 'paywall-type': 'compile-timeout', plan: 'collaborator', 'billing-period': billingPeriod, currency, version: 'compile-timeout', button: 'buy', }) openCheckout() }, [billingPeriod, currency, openCheckout]) const viewAllPlansHref = useMemo(() => { const params = new URLSearchParams({ 'paywall-type': 'compile-timeout', itm_campaign: 'compile-timeout', }) return `/user/subscription/choose-your-plan?${params.toString()}` }, []) const handleViewAllPlans = useCallback(() => { sendMB('paywall-plans-page-click', { 'paywall-type': 'compile-timeout', button: 'plans', 'billing-period': billingPeriod, currency, version: 'compile-timeout', }) }, [billingPeriod, currency]) const price = annual ? standardPlanPricing?.annual : standardPlanPricing?.monthly const priceSubtext = annual ? t('per_year') : t('per_month') const strikethroughPrice = annual ? standardPlanPricing?.monthlyTimesTwelve : undefined return (
{t('get_more_compile_time')}

{t('standard')} {t('plan')}

{strikethroughPrice ? ( {strikethroughPrice} ) : ( )} {price} {priceSubtext && ( {priceSubtext} )}
{supportsAnnualPricing && (
{ if ((period === 'annual') !== annual) { handleToggleBilling() } }} variant="premium" />
)}

{t('compile_timeout_modal_intro')}

{t('collabs_per_proj', { count: 10 })} {t('track_changes')} {t('github_integration')} {t('and_much_more')}
{t('buy_now_no_exclamation_mark')} {t('view_all_plans')}
) } function ListItem({ children }: { children: React.ReactNode }) { return (
{children}
) } export default CompileTimeoutPaywallModal