overleaf/services/web/frontend/js/features/pdf-preview/components/compile-time-warning.tsx

117 lines
3.8 KiB
TypeScript
Raw Normal View History

import { memo, useCallback, useEffect } from 'react'
import { Button } from 'react-bootstrap'
import { Trans, useTranslation } from 'react-i18next'
import * as eventTracking from '../../../infrastructure/event-tracking'
import StartFreeTrialButton from '../../../shared/components/start-free-trial-button'
import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
import usePersistedState from '../../../shared/hooks/use-persisted-state'
[web] Paywall CTA split-test (#17555) * Fix `{splitTest.requiredCohortSize && (...)}` can display `0` * Get `paywall-cta` assignment in ProjectController.js * CTA change: "Get Dropbox Sync" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286026 * CTA change: "Get GitHub Sync" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286736 * CTA change: "Get Git integration" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286283 * CTA change: "Add more collaborators" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763884855 * CTA change: "Get track changes" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764030761 * Update wording and position: "Already subscribed? Try refreshing the page." https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764366969 * Casing update: "Upgrade to track changes" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764209961 * CTA changes: "Get Mendeley integration" + "Get Zotero integration" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764547424 https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764547269 * CTA change: "Get full project history" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762005 * Casing update: "full project history" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762280 * CTA change: "Get more compile time" in timeout-upgrade-prompt-new.tsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762563 * CTA change: "Get more compile time" in compile-timeout-warning.tsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762726 * CTA change: "Get advanced reference search" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764969087 * Update casing and wording: "advanced reference search" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764969412 * CTA change: "Get Symbol Palette" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578765128906 * Update title: "Subscribe to find the symbols you need faster" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578765289664 * Revert use of `satisfies`: it doesn't work with our version of prettier (https://github.com/prettier/prettier/issues/13516) * CTA change: "Get more compile time" in compile-timeout-changing-soon.tsx ⚠️ not in miro * Rename `paywallCtaAssignment`, remove useless export and comment Addressing Fahru's review * Add alternative texts in `/registration/try-premium` page * CTA change: "Get more compile time" in timeout-upgrade-prompt.jsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762563 * CTA change: "Get GitHub Sync" in import-project-from-github-modal-content.tsx Not in Miro, but related to: https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286736 * CTA change: "Get more compile time" in compile-time-warning.tsx Not in Miro, but related to others * Fix compile-time-warning style (spacings, overflows out of window) * `npm run format:fix` GitOrigin-RevId: 0d8d1808b5901c2761d35494c49713d26721bcfd
2024-04-02 10:06:16 -04:00
import { useSplitTestContext } from '@/shared/context/split-test-context'
const TWENTY_FOUR_DAYS = 24 * 60 * 60 * 24 * 1000
function CompileTimeWarning() {
const { t } = useTranslation()
const [displayStatus, setDisplayStatus] = usePersistedState(
'compile-time-warning-display-status',
{ lastDisplayTime: 0, dismissed: false },
true
)
const {
showCompileTimeWarning,
setShowCompileTimeWarning,
deliveryLatencies,
isProjectOwner,
} = useDetachCompileContext()
[web] Paywall CTA split-test (#17555) * Fix `{splitTest.requiredCohortSize && (...)}` can display `0` * Get `paywall-cta` assignment in ProjectController.js * CTA change: "Get Dropbox Sync" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286026 * CTA change: "Get GitHub Sync" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286736 * CTA change: "Get Git integration" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286283 * CTA change: "Add more collaborators" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763884855 * CTA change: "Get track changes" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764030761 * Update wording and position: "Already subscribed? Try refreshing the page." https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764366969 * Casing update: "Upgrade to track changes" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764209961 * CTA changes: "Get Mendeley integration" + "Get Zotero integration" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764547424 https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764547269 * CTA change: "Get full project history" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762005 * Casing update: "full project history" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762280 * CTA change: "Get more compile time" in timeout-upgrade-prompt-new.tsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762563 * CTA change: "Get more compile time" in compile-timeout-warning.tsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762726 * CTA change: "Get advanced reference search" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764969087 * Update casing and wording: "advanced reference search" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764969412 * CTA change: "Get Symbol Palette" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578765128906 * Update title: "Subscribe to find the symbols you need faster" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578765289664 * Revert use of `satisfies`: it doesn't work with our version of prettier (https://github.com/prettier/prettier/issues/13516) * CTA change: "Get more compile time" in compile-timeout-changing-soon.tsx ⚠️ not in miro * Rename `paywallCtaAssignment`, remove useless export and comment Addressing Fahru's review * Add alternative texts in `/registration/try-premium` page * CTA change: "Get more compile time" in timeout-upgrade-prompt.jsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762563 * CTA change: "Get GitHub Sync" in import-project-from-github-modal-content.tsx Not in Miro, but related to: https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286736 * CTA change: "Get more compile time" in compile-time-warning.tsx Not in Miro, but related to others * Fix compile-time-warning style (spacings, overflows out of window) * `npm run format:fix` GitOrigin-RevId: 0d8d1808b5901c2761d35494c49713d26721bcfd
2024-04-02 10:06:16 -04:00
const { splitTestVariants } = useSplitTestContext()
const hasNewPaywallCta = splitTestVariants['paywall-cta'] === 'enabled'
useEffect(() => {
if (deliveryLatencies && deliveryLatencies.compileTimeServerE2E) {
// compile-timeout-20s test
if (deliveryLatencies.compileTimeServerE2E > 10000) {
eventTracking.sendMB('compile-time-warning-would-display', {
time: 10,
newCompileTimeout: 'control',
isProjectOwner,
})
}
}
}, [deliveryLatencies, isProjectOwner])
useEffect(() => {
if (showCompileTimeWarning) {
if (
displayStatus &&
Date.now() - displayStatus.lastDisplayTime < TWENTY_FOUR_DAYS
) {
return
}
setDisplayStatus({ lastDisplayTime: Date.now(), dismissed: false })
eventTracking.sendMB('compile-time-warning-displayed', { time: 30 })
}
}, [showCompileTimeWarning, displayStatus, setDisplayStatus])
const getTimeSinceDisplayed = useCallback(() => {
return (Date.now() - displayStatus.lastDisplayTime) / 1000
}, [displayStatus])
const closeWarning = useCallback(() => {
eventTracking.sendMB('compile-time-warning-dismissed', {
'time-since-displayed': getTimeSinceDisplayed(),
time: 30,
})
setShowCompileTimeWarning(false)
setDisplayStatus(displayStatus => ({ ...displayStatus, dismissed: true }))
}, [getTimeSinceDisplayed, setShowCompileTimeWarning, setDisplayStatus])
const handleUpgradeClick = useCallback(() => {
eventTracking.sendMB('compile-time-warning-upgrade-click', {
'time-since-displayed': getTimeSinceDisplayed(),
time: 30,
})
setShowCompileTimeWarning(false)
setDisplayStatus(displayStatus => ({ ...displayStatus, dismissed: true }))
}, [getTimeSinceDisplayed, setShowCompileTimeWarning, setDisplayStatus])
if (!showCompileTimeWarning || displayStatus.dismissed) {
return null
}
return (
<div className="alert alert-success compile-time-warning" role="alert">
<Button
className="close"
data-dismiss="alert"
aria-label="Close"
onClick={closeWarning}
>
<span aria-hidden="true">&times;</span>
</Button>
<div className="warning-content">
<div className="warning-text">
<Trans
i18nKey="approaching_compile_timeout_limit_upgrade_for_more_compile_time"
components={{
strong: <strong style={{ display: 'inline-block' }} />,
}}
/>
</div>
<div className="upgrade-prompt">
<StartFreeTrialButton
buttonProps={{ bsStyle: 'primary', bsSize: 'sm' }}
handleClick={handleUpgradeClick}
source="compile-time-warning"
>
[web] Paywall CTA split-test (#17555) * Fix `{splitTest.requiredCohortSize && (...)}` can display `0` * Get `paywall-cta` assignment in ProjectController.js * CTA change: "Get Dropbox Sync" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286026 * CTA change: "Get GitHub Sync" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286736 * CTA change: "Get Git integration" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286283 * CTA change: "Add more collaborators" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763884855 * CTA change: "Get track changes" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764030761 * Update wording and position: "Already subscribed? Try refreshing the page." https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764366969 * Casing update: "Upgrade to track changes" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764209961 * CTA changes: "Get Mendeley integration" + "Get Zotero integration" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764547424 https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764547269 * CTA change: "Get full project history" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762005 * Casing update: "full project history" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762280 * CTA change: "Get more compile time" in timeout-upgrade-prompt-new.tsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762563 * CTA change: "Get more compile time" in compile-timeout-warning.tsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762726 * CTA change: "Get advanced reference search" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764969087 * Update casing and wording: "advanced reference search" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764969412 * CTA change: "Get Symbol Palette" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578765128906 * Update title: "Subscribe to find the symbols you need faster" https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578765289664 * Revert use of `satisfies`: it doesn't work with our version of prettier (https://github.com/prettier/prettier/issues/13516) * CTA change: "Get more compile time" in compile-timeout-changing-soon.tsx ⚠️ not in miro * Rename `paywallCtaAssignment`, remove useless export and comment Addressing Fahru's review * Add alternative texts in `/registration/try-premium` page * CTA change: "Get more compile time" in timeout-upgrade-prompt.jsx https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578764762563 * CTA change: "Get GitHub Sync" in import-project-from-github-modal-content.tsx Not in Miro, but related to: https://miro.com/app/board/uXjVMFLu5J8=/?openComment=3458764578763286736 * CTA change: "Get more compile time" in compile-time-warning.tsx Not in Miro, but related to others * Fix compile-time-warning style (spacings, overflows out of window) * `npm run format:fix` GitOrigin-RevId: 0d8d1808b5901c2761d35494c49713d26721bcfd
2024-04-02 10:06:16 -04:00
{hasNewPaywallCta ? t('get_more_compile_time') : t('upgrade')}
</StartFreeTrialButton>
</div>
</div>
</div>
)
}
export default memo(CompileTimeWarning)