Files
overleaf-cep/services/web/frontend/js/shared/components/start-free-trial-button.tsx
T
Alf Eaton 2fbb4615f9 Convert utility functions to TypeScript (#22658)
* Convert event-tracking to TypeScript

* Convert local-storage to TypeScript

* Convert mapSeries to TypeScript

* Convert SessionStorage to TypeScript

* Convert account-upgrade to TypeScript

* Convert isValidTeXFile to TypeScript

* Convert date functions to TypeScript

* Convert EventEmitter to TypeScript

* Convert isNetworkError to TypeScript

* Convert webpack-public-path to TypeScript

* Convert displayNameForUser to TypeScript

GitOrigin-RevId: 79c5a2d1101fcd520f3116f0f4af29d974189d94
2025-01-16 09:05:36 +00:00

55 lines
1.3 KiB
TypeScript

import { MouseEventHandler, useCallback, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { startFreeTrial } from '@/main/account-upgrade'
import * as eventTracking from '../../infrastructure/event-tracking'
import OLButton from '@/features/ui/components/ol/ol-button'
type StartFreeTrialButtonProps = {
source: string
variant?: string
buttonProps?: React.ComponentProps<typeof OLButton>
children?: React.ReactNode
handleClick?: MouseEventHandler<typeof OLButton>
}
export default function StartFreeTrialButton({
buttonProps = {
variant: 'secondary',
},
children,
handleClick,
source,
variant,
}: StartFreeTrialButtonProps) {
const { t } = useTranslation()
useEffect(() => {
const eventSegmentation: { [key: string]: unknown } = {
'paywall-type': source,
}
if (variant) {
eventSegmentation.variant = variant
}
eventTracking.sendMB('paywall-prompt', eventSegmentation)
}, [source, variant])
const onClick = useCallback(
event => {
event.preventDefault()
if (handleClick) {
handleClick(event)
}
startFreeTrial(source, variant)
},
[handleClick, source, variant]
)
return (
<OLButton {...buttonProps} onClick={onClick}>
{children || t('start_free_trial')}
</OLButton>
)
}