2022-07-25 08:33:25 -04:00
|
|
|
import { MouseEventHandler, useCallback, useEffect } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { startFreeTrial } from '../../main/account-upgrade'
|
|
|
|
import * as eventTracking from '../../infrastructure/event-tracking'
|
2024-06-13 08:44:38 -04:00
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
2022-07-25 08:33:25 -04:00
|
|
|
|
|
|
|
type StartFreeTrialButtonProps = {
|
|
|
|
source: string
|
2023-09-19 09:23:19 -04:00
|
|
|
variant?: string
|
2024-06-13 08:44:38 -04:00
|
|
|
buttonProps?: React.ComponentProps<typeof OLButton>
|
2022-07-25 08:33:25 -04:00
|
|
|
children?: React.ReactNode
|
2024-06-13 08:44:38 -04:00
|
|
|
handleClick?: MouseEventHandler<typeof OLButton>
|
2022-07-25 08:33:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function StartFreeTrialButton({
|
|
|
|
buttonProps = {
|
2024-06-13 08:44:38 -04:00
|
|
|
variant: 'secondary',
|
2022-07-25 08:33:25 -04:00
|
|
|
},
|
|
|
|
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 (
|
2024-06-13 08:44:38 -04:00
|
|
|
<OLButton {...buttonProps} onClick={onClick}>
|
2022-07-25 08:33:25 -04:00
|
|
|
{children || t('start_free_trial')}
|
2024-06-13 08:44:38 -04:00
|
|
|
</OLButton>
|
2022-07-25 08:33:25 -04:00
|
|
|
)
|
|
|
|
}
|