2022-07-25 08:33:25 -04:00
|
|
|
import { MouseEventHandler, useCallback, useEffect } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { Button } from 'react-bootstrap'
|
|
|
|
import { startFreeTrial } from '../../main/account-upgrade'
|
|
|
|
import * as eventTracking from '../../infrastructure/event-tracking'
|
|
|
|
|
|
|
|
type StartFreeTrialButtonProps = {
|
|
|
|
source: string
|
2023-09-19 09:23:19 -04:00
|
|
|
variant?: string
|
2022-07-25 08:33:25 -04:00
|
|
|
buttonProps?: Button.ButtonProps
|
|
|
|
children?: React.ReactNode
|
|
|
|
handleClick?: MouseEventHandler<Button>
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function StartFreeTrialButton({
|
|
|
|
buttonProps = {
|
|
|
|
bsStyle: 'info',
|
|
|
|
},
|
|
|
|
children,
|
|
|
|
handleClick,
|
|
|
|
source,
|
2023-09-19 09:23:19 -04:00
|
|
|
variant,
|
2022-07-25 08:33:25 -04:00
|
|
|
}: StartFreeTrialButtonProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-09-19 09:23:19 -04:00
|
|
|
const eventSegmentation: { [key: string]: unknown } = {
|
2022-07-25 08:33:25 -04:00
|
|
|
'paywall-type': source,
|
2023-09-19 09:23:19 -04:00
|
|
|
}
|
|
|
|
if (variant) {
|
|
|
|
eventSegmentation.variant = variant
|
|
|
|
}
|
|
|
|
eventTracking.sendMB('paywall-prompt', eventSegmentation)
|
|
|
|
}, [source, variant])
|
2022-07-25 08:33:25 -04:00
|
|
|
|
|
|
|
const onClick = useCallback(
|
|
|
|
event => {
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
|
|
if (handleClick) {
|
|
|
|
handleClick(event)
|
|
|
|
}
|
|
|
|
|
2023-09-19 09:23:19 -04:00
|
|
|
startFreeTrial(source, null, null, variant)
|
2022-07-25 08:33:25 -04:00
|
|
|
},
|
2023-09-19 09:23:19 -04:00
|
|
|
[handleClick, source, variant]
|
2022-07-25 08:33:25 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button {...buttonProps} onClick={onClick}>
|
|
|
|
{children || t('start_free_trial')}
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|