2022-07-13 04:33:47 -04:00
|
|
|
import { memo, useCallback, useEffect } from 'react'
|
|
|
|
import { Button } from 'react-bootstrap'
|
|
|
|
import { Trans, useTranslation } from 'react-i18next'
|
|
|
|
import * as eventTracking from '../../../infrastructure/event-tracking'
|
2022-07-25 08:33:25 -04:00
|
|
|
import StartFreeTrialButton from '../../../shared/components/start-free-trial-button'
|
2022-07-13 04:33:47 -04:00
|
|
|
import { useDetachCompileContext } from '../../../shared/context/detach-compile-context'
|
2022-07-13 08:53:54 -04:00
|
|
|
import usePersistedState from '../../../shared/hooks/use-persisted-state'
|
|
|
|
|
2023-09-19 09:09:33 -04:00
|
|
|
const TWENTY_FOUR_DAYS = 24 * 60 * 60 * 24 * 1000
|
2022-07-13 04:33:47 -04:00
|
|
|
|
|
|
|
function CompileTimeWarning() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2022-07-13 11:19:20 -04:00
|
|
|
const [displayStatus, setDisplayStatus] = usePersistedState(
|
|
|
|
'compile-time-warning-display-status',
|
|
|
|
{ lastDisplayTime: 0, dismissed: false },
|
2022-07-13 08:53:54 -04:00
|
|
|
true
|
|
|
|
)
|
|
|
|
|
2023-09-19 09:09:33 -04:00
|
|
|
const {
|
|
|
|
showCompileTimeWarning,
|
|
|
|
setShowCompileTimeWarning,
|
|
|
|
deliveryLatencies,
|
|
|
|
isProjectOwner,
|
|
|
|
} = useDetachCompileContext()
|
|
|
|
|
|
|
|
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])
|
2022-07-13 04:33:47 -04:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (showCompileTimeWarning) {
|
2022-07-13 11:19:20 -04:00
|
|
|
if (
|
|
|
|
displayStatus &&
|
2023-09-19 09:09:33 -04:00
|
|
|
Date.now() - displayStatus.lastDisplayTime < TWENTY_FOUR_DAYS
|
2022-07-13 11:19:20 -04:00
|
|
|
) {
|
2022-07-13 08:53:54 -04:00
|
|
|
return
|
|
|
|
}
|
2022-07-13 11:19:20 -04:00
|
|
|
setDisplayStatus({ lastDisplayTime: Date.now(), dismissed: false })
|
2023-09-18 07:35:43 -04:00
|
|
|
eventTracking.sendMB('compile-time-warning-displayed', { time: 30 })
|
2022-07-13 04:33:47 -04:00
|
|
|
}
|
2022-07-13 11:19:20 -04:00
|
|
|
}, [showCompileTimeWarning, displayStatus, setDisplayStatus])
|
2022-07-13 04:33:47 -04:00
|
|
|
|
2022-07-13 08:53:54 -04:00
|
|
|
const getTimeSinceDisplayed = useCallback(() => {
|
2022-07-13 11:19:20 -04:00
|
|
|
return (Date.now() - displayStatus.lastDisplayTime) / 1000
|
|
|
|
}, [displayStatus])
|
2022-07-13 08:53:54 -04:00
|
|
|
|
|
|
|
const closeWarning = useCallback(() => {
|
|
|
|
eventTracking.sendMB('compile-time-warning-dismissed', {
|
|
|
|
'time-since-displayed': getTimeSinceDisplayed(),
|
2023-09-18 07:35:43 -04:00
|
|
|
time: 30,
|
2022-07-13 08:53:54 -04:00
|
|
|
})
|
2022-07-13 04:33:47 -04:00
|
|
|
setShowCompileTimeWarning(false)
|
2022-07-13 11:19:20 -04:00
|
|
|
setDisplayStatus(displayStatus => ({ ...displayStatus, dismissed: true }))
|
|
|
|
}, [getTimeSinceDisplayed, setShowCompileTimeWarning, setDisplayStatus])
|
2022-07-13 04:33:47 -04:00
|
|
|
|
2022-07-25 08:33:25 -04:00
|
|
|
const handleUpgradeClick = useCallback(() => {
|
|
|
|
eventTracking.sendMB('compile-time-warning-upgrade-click', {
|
|
|
|
'time-since-displayed': getTimeSinceDisplayed(),
|
2023-09-18 07:35:43 -04:00
|
|
|
time: 30,
|
2022-07-25 08:33:25 -04:00
|
|
|
})
|
|
|
|
setShowCompileTimeWarning(false)
|
|
|
|
setDisplayStatus(displayStatus => ({ ...displayStatus, dismissed: true }))
|
|
|
|
}, [getTimeSinceDisplayed, setShowCompileTimeWarning, setDisplayStatus])
|
2022-07-13 04:33:47 -04:00
|
|
|
|
2022-07-13 11:19:20 -04:00
|
|
|
if (!showCompileTimeWarning || displayStatus.dismissed) {
|
2022-07-13 04:33:47 -04:00
|
|
|
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">×</span>
|
|
|
|
</Button>
|
2022-09-01 04:44:47 -04:00
|
|
|
<div className="warning-content">
|
2022-07-13 04:33:47 -04:00
|
|
|
<div className="warning-text">
|
|
|
|
<Trans
|
|
|
|
i18nKey="approaching_compile_timeout_limit_upgrade_for_more_compile_time"
|
2023-10-30 06:29:56 -04:00
|
|
|
components={{
|
|
|
|
strong: <strong style={{ display: 'inline-block' }} />,
|
|
|
|
}}
|
2022-07-13 04:33:47 -04:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="upgrade-prompt">
|
2022-07-25 08:33:25 -04:00
|
|
|
<StartFreeTrialButton
|
|
|
|
buttonProps={{ bsStyle: 'primary', bsSize: 'sm' }}
|
|
|
|
handleClick={handleUpgradeClick}
|
|
|
|
source="compile-time-warning"
|
|
|
|
>
|
2022-07-13 04:33:47 -04:00
|
|
|
{t('upgrade')}
|
2022-07-25 08:33:25 -04:00
|
|
|
</StartFreeTrialButton>
|
2022-07-13 04:33:47 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(CompileTimeWarning)
|