import { useCallback, useState, ReactNode } from 'react' import { useTranslation } from 'react-i18next' import OLBadge from '@/features/ui/components/ol/ol-badge' import getMeta from '../../../../utils/meta' import { sendMB } from '../../../../infrastructure/event-tracking' import OLButton from '@/features/ui/components/ol/ol-button' import OLModal, { OLModalBody, OLModalFooter, OLModalHeader, OLModalTitle, } from '@/features/ui/components/ol/ol-modal' function trackUpgradeClick(integration: string) { sendMB('settings-upgrade-click', { integration }) } function trackLinkingClick(integration: string) { sendMB('link-integration-click', { integration, location: 'Settings' }) } type IntegrationLinkingWidgetProps = { logo: ReactNode title: string description: string helpPath: string hasFeature?: boolean statusIndicator?: ReactNode linked?: boolean linkPath: string unlinkPath: string unlinkConfirmationTitle: string unlinkConfirmationText: string disabled?: boolean } export function IntegrationLinkingWidget({ logo, title, description, helpPath, hasFeature, statusIndicator, linked, linkPath, unlinkPath, unlinkConfirmationTitle, unlinkConfirmationText, disabled, }: IntegrationLinkingWidgetProps) { const { t } = useTranslation() const [showModal, setShowModal] = useState(false) const handleUnlinkClick = useCallback(() => { setShowModal(true) }, []) const handleModalHide = useCallback(() => { setShowModal(false) }, []) return (
{logo}

{title}

{!hasFeature && {t('premium_feature')}}

{description}{' '} {t('learn_more')}

{hasFeature && statusIndicator}
) } type ActionButtonProps = { integration: string hasFeature?: boolean linked?: boolean handleUnlinkClick: () => void linkPath: string disabled?: boolean } function ActionButton({ hasFeature, linked, handleUnlinkClick, linkPath, disabled, integration, }: ActionButtonProps) { const { t } = useTranslation() if (!hasFeature) { return ( trackUpgradeClick(integration)} > {t('upgrade')} ) } else if (linked) { return ( {t('unlink')} ) } else { return ( <> {disabled ? ( {t('link')} ) : ( trackLinkingClick(integration)} > {t('link')} )} ) } } type UnlinkConfirmModalProps = { show: boolean title: string integration: string content: string unlinkPath: string handleHide: () => void } function UnlinkConfirmationModal({ show, title, integration, content, unlinkPath, handleHide, }: UnlinkConfirmModalProps) { const { t } = useTranslation() const handleCancel = (event: React.MouseEvent) => { event.preventDefault() handleHide() } const handleConfirm = () => { sendMB('unlink-integration-click', { integration, }) } return ( {title}

{content}

{t('cancel')} {t('unlink')}
) }