2023-12-07 09:29:45 -05:00
|
|
|
import { ReactNode } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { sendMB } from '@/infrastructure/event-tracking'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLBadge from '@/features/ui/components/ol/ol-badge'
|
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
2023-12-07 09:29:45 -05:00
|
|
|
|
|
|
|
function trackUpgradeClick() {
|
|
|
|
sendMB('settings-upgrade-click')
|
|
|
|
}
|
|
|
|
|
|
|
|
type EnableWidgetProps = {
|
|
|
|
logo: ReactNode
|
|
|
|
title: string
|
|
|
|
description: string
|
|
|
|
helpPath: string
|
2023-12-13 07:31:57 -05:00
|
|
|
helpTextOverride?: string
|
2023-12-07 09:29:45 -05:00
|
|
|
hasFeature?: boolean
|
|
|
|
isPremiumFeature?: boolean
|
|
|
|
statusIndicator?: ReactNode
|
|
|
|
children?: ReactNode
|
|
|
|
linked?: boolean
|
|
|
|
handleLinkClick: () => void
|
|
|
|
handleUnlinkClick: () => void
|
|
|
|
disabled?: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
export function EnableWidget({
|
|
|
|
logo,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
helpPath,
|
2023-12-13 07:31:57 -05:00
|
|
|
helpTextOverride,
|
2023-12-07 09:29:45 -05:00
|
|
|
hasFeature,
|
|
|
|
isPremiumFeature,
|
|
|
|
statusIndicator,
|
|
|
|
linked,
|
|
|
|
handleLinkClick,
|
|
|
|
handleUnlinkClick,
|
|
|
|
children,
|
|
|
|
disabled,
|
|
|
|
}: EnableWidgetProps) {
|
|
|
|
const { t } = useTranslation()
|
2023-12-13 07:31:57 -05:00
|
|
|
const helpText = helpTextOverride || t('learn_more')
|
2023-12-07 09:29:45 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-widget-container">
|
|
|
|
<div>{logo}</div>
|
|
|
|
<div className="description-container">
|
|
|
|
<div className="title-row">
|
|
|
|
<h4>{title}</h4>
|
|
|
|
{!hasFeature && isPremiumFeature && (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLBadge bg="info">{t('premium_feature')}</OLBadge>
|
2023-12-07 09:29:45 -05:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<p className="small">
|
|
|
|
{description}{' '}
|
|
|
|
<a href={helpPath} target="_blank" rel="noreferrer">
|
2023-12-13 07:31:57 -05:00
|
|
|
{helpText}
|
2023-12-07 09:29:45 -05:00
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
{children}
|
|
|
|
{hasFeature && statusIndicator}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<ActionButton
|
|
|
|
hasFeature={hasFeature}
|
|
|
|
linked={linked}
|
|
|
|
handleUnlinkClick={handleUnlinkClick}
|
|
|
|
handleLinkClick={handleLinkClick}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ActionButtonProps = {
|
|
|
|
hasFeature?: boolean
|
|
|
|
linked?: boolean
|
|
|
|
handleUnlinkClick: () => void
|
|
|
|
handleLinkClick: () => void
|
|
|
|
disabled?: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
function ActionButton({
|
|
|
|
linked,
|
|
|
|
handleUnlinkClick,
|
|
|
|
handleLinkClick,
|
|
|
|
hasFeature,
|
|
|
|
disabled,
|
|
|
|
}: ActionButtonProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
if (!hasFeature) {
|
|
|
|
return (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLButton
|
2024-04-23 10:12:25 -04:00
|
|
|
variant="primary"
|
2023-12-07 09:29:45 -05:00
|
|
|
href="/user/subscription/plans"
|
|
|
|
onClick={trackUpgradeClick}
|
|
|
|
>
|
|
|
|
<span className="text-capitalize">{t('upgrade')}</span>
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2023-12-07 09:29:45 -05:00
|
|
|
)
|
|
|
|
} else if (linked) {
|
|
|
|
return (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLButton
|
2024-04-23 10:12:25 -04:00
|
|
|
variant="danger-ghost"
|
2023-12-07 09:29:45 -05:00
|
|
|
onClick={handleUnlinkClick}
|
|
|
|
disabled={disabled}
|
|
|
|
>
|
|
|
|
{t('turn_off')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2023-12-07 09:29:45 -05:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLButton
|
2024-04-23 10:12:25 -04:00
|
|
|
variant="secondary"
|
2023-12-07 09:29:45 -05:00
|
|
|
disabled={disabled}
|
|
|
|
onClick={handleLinkClick}
|
|
|
|
>
|
|
|
|
{t('turn_on')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2023-12-07 09:29:45 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default EnableWidget
|