2022-04-22 09:49:26 -04:00
|
|
|
import { useCallback, useState, ReactNode } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLBadge from '@/features/ui/components/ol/ol-badge'
|
2022-04-25 07:05:15 -04:00
|
|
|
import getMeta from '../../../../utils/meta'
|
2022-06-10 04:14:00 -04:00
|
|
|
import { sendMB } from '../../../../infrastructure/event-tracking'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
2024-05-14 11:53:25 -04:00
|
|
|
import OLModal, {
|
|
|
|
OLModalBody,
|
|
|
|
OLModalFooter,
|
|
|
|
OLModalHeader,
|
|
|
|
OLModalTitle,
|
2024-05-15 10:31:00 -04:00
|
|
|
} from '@/features/ui/components/ol/ol-modal'
|
2022-06-10 04:14:00 -04:00
|
|
|
|
2024-04-23 12:49:11 -04:00
|
|
|
function trackUpgradeClick(integration: string) {
|
|
|
|
sendMB('settings-upgrade-click', { integration })
|
|
|
|
}
|
|
|
|
|
|
|
|
function trackLinkingClick(integration: string) {
|
|
|
|
sendMB('link-integration-click', { integration, location: 'Settings' })
|
2022-06-10 04:14:00 -04:00
|
|
|
}
|
2022-04-22 09:49:26 -04:00
|
|
|
|
|
|
|
type IntegrationLinkingWidgetProps = {
|
|
|
|
logo: ReactNode
|
|
|
|
title: string
|
|
|
|
description: string
|
|
|
|
helpPath: string
|
|
|
|
hasFeature?: boolean
|
|
|
|
statusIndicator?: ReactNode
|
|
|
|
linked?: boolean
|
|
|
|
linkPath: string
|
|
|
|
unlinkPath: string
|
|
|
|
unlinkConfirmationTitle: string
|
|
|
|
unlinkConfirmationText: string
|
2022-05-16 04:02:17 -04:00
|
|
|
disabled?: boolean
|
2022-04-22 09:49:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function IntegrationLinkingWidget({
|
|
|
|
logo,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
helpPath,
|
|
|
|
hasFeature,
|
|
|
|
statusIndicator,
|
|
|
|
linked,
|
|
|
|
linkPath,
|
|
|
|
unlinkPath,
|
|
|
|
unlinkConfirmationTitle,
|
|
|
|
unlinkConfirmationText,
|
2022-05-16 04:02:17 -04:00
|
|
|
disabled,
|
2022-04-22 09:49:26 -04:00
|
|
|
}: IntegrationLinkingWidgetProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
const [showModal, setShowModal] = useState(false)
|
|
|
|
|
|
|
|
const handleUnlinkClick = useCallback(() => {
|
|
|
|
setShowModal(true)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const handleModalHide = useCallback(() => {
|
|
|
|
setShowModal(false)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="settings-widget-container">
|
|
|
|
<div>{logo}</div>
|
|
|
|
<div className="description-container">
|
|
|
|
<div className="title-row">
|
|
|
|
<h4>{title}</h4>
|
2024-05-15 10:31:00 -04:00
|
|
|
{!hasFeature && <OLBadge bg="info">{t('premium_feature')}</OLBadge>}
|
2022-04-22 09:49:26 -04:00
|
|
|
</div>
|
2022-04-26 11:20:09 -04:00
|
|
|
<p className="small">
|
2022-04-22 09:49:26 -04:00
|
|
|
{description}{' '}
|
|
|
|
<a href={helpPath} target="_blank" rel="noreferrer">
|
|
|
|
{t('learn_more')}
|
|
|
|
</a>
|
|
|
|
</p>
|
2022-05-16 04:02:17 -04:00
|
|
|
{hasFeature && statusIndicator}
|
2022-04-22 09:49:26 -04:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<ActionButton
|
2024-04-23 12:49:11 -04:00
|
|
|
integration={title}
|
2022-04-22 09:49:26 -04:00
|
|
|
hasFeature={hasFeature}
|
|
|
|
linked={linked}
|
|
|
|
handleUnlinkClick={handleUnlinkClick}
|
|
|
|
linkPath={linkPath}
|
2022-05-16 04:02:17 -04:00
|
|
|
disabled={disabled}
|
2022-04-22 09:49:26 -04:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<UnlinkConfirmationModal
|
2024-04-23 12:49:11 -04:00
|
|
|
integration={title}
|
2022-04-22 09:49:26 -04:00
|
|
|
show={showModal}
|
|
|
|
title={unlinkConfirmationTitle}
|
|
|
|
content={unlinkConfirmationText}
|
|
|
|
unlinkPath={unlinkPath}
|
|
|
|
handleHide={handleModalHide}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ActionButtonProps = {
|
2024-04-23 12:49:11 -04:00
|
|
|
integration: string
|
2022-04-22 09:49:26 -04:00
|
|
|
hasFeature?: boolean
|
|
|
|
linked?: boolean
|
|
|
|
handleUnlinkClick: () => void
|
|
|
|
linkPath: string
|
2022-05-16 04:02:17 -04:00
|
|
|
disabled?: boolean
|
2022-04-22 09:49:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function ActionButton({
|
|
|
|
hasFeature,
|
|
|
|
linked,
|
|
|
|
handleUnlinkClick,
|
|
|
|
linkPath,
|
2022-05-16 04:02:17 -04:00
|
|
|
disabled,
|
2024-04-23 12:49:11 -04:00
|
|
|
integration,
|
2022-04-22 09:49:26 -04:00
|
|
|
}: 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"
|
2022-06-10 04:14:00 -04:00
|
|
|
href="/user/subscription/plans"
|
2024-04-23 12:49:11 -04:00
|
|
|
onClick={() => trackUpgradeClick(integration)}
|
2022-06-10 04:14:00 -04:00
|
|
|
>
|
2022-05-25 03:59:24 -04:00
|
|
|
<span className="text-capitalize">{t('upgrade')}</span>
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2022-04-22 09:49:26 -04: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-04-17 09:48:09 -04:00
|
|
|
onClick={handleUnlinkClick}
|
|
|
|
disabled={disabled}
|
|
|
|
>
|
2022-04-22 09:49:26 -04:00
|
|
|
{t('unlink')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2022-04-22 09:49:26 -04:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
2022-12-07 05:51:53 -05:00
|
|
|
<>
|
|
|
|
{disabled ? (
|
2024-06-06 11:37:47 -04:00
|
|
|
<OLButton disabled variant="secondary" className="text-capitalize">
|
2022-12-07 05:51:53 -05:00
|
|
|
{t('link')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2022-12-07 05:51:53 -05:00
|
|
|
) : (
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLButton
|
2024-04-23 10:12:25 -04:00
|
|
|
variant="secondary"
|
2022-12-16 09:45:40 -05:00
|
|
|
href={linkPath}
|
2024-06-06 11:37:47 -04:00
|
|
|
className="text-capitalize"
|
2024-04-23 12:49:11 -04:00
|
|
|
onClick={() => trackLinkingClick(integration)}
|
2022-12-16 09:45:40 -05:00
|
|
|
>
|
2022-12-07 05:51:53 -05:00
|
|
|
{t('link')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2022-12-07 05:51:53 -05:00
|
|
|
)}
|
|
|
|
</>
|
2022-04-22 09:49:26 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type UnlinkConfirmModalProps = {
|
|
|
|
show: boolean
|
|
|
|
title: string
|
2024-04-23 12:49:11 -04:00
|
|
|
integration: string
|
2022-04-22 09:49:26 -04:00
|
|
|
content: string
|
|
|
|
unlinkPath: string
|
|
|
|
handleHide: () => void
|
|
|
|
}
|
|
|
|
|
|
|
|
function UnlinkConfirmationModal({
|
|
|
|
show,
|
|
|
|
title,
|
2024-04-23 12:49:11 -04:00
|
|
|
integration,
|
2022-04-22 09:49:26 -04:00
|
|
|
content,
|
|
|
|
unlinkPath,
|
|
|
|
handleHide,
|
|
|
|
}: UnlinkConfirmModalProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2024-04-23 10:12:25 -04:00
|
|
|
const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {
|
2022-04-25 07:05:15 -04:00
|
|
|
event.preventDefault()
|
|
|
|
handleHide()
|
|
|
|
}
|
2024-04-23 12:49:11 -04:00
|
|
|
|
|
|
|
const handleConfirm = () => {
|
|
|
|
sendMB('unlink-integration-click', {
|
|
|
|
integration,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-22 09:49:26 -04:00
|
|
|
return (
|
2024-05-14 11:53:25 -04:00
|
|
|
<OLModal show={show} onHide={handleHide}>
|
|
|
|
<OLModalHeader closeButton>
|
|
|
|
<OLModalTitle>{title}</OLModalTitle>
|
|
|
|
</OLModalHeader>
|
2022-04-22 09:49:26 -04:00
|
|
|
|
2024-05-14 11:53:25 -04:00
|
|
|
<OLModalBody>
|
2022-04-22 09:49:26 -04:00
|
|
|
<p>{content}</p>
|
2024-05-14 11:53:25 -04:00
|
|
|
</OLModalBody>
|
2022-04-22 09:49:26 -04:00
|
|
|
|
2024-05-14 11:53:25 -04:00
|
|
|
<OLModalFooter>
|
2022-04-25 07:05:15 -04:00
|
|
|
<form action={unlinkPath} method="POST" className="form-inline">
|
|
|
|
<input type="hidden" name="_csrf" value={getMeta('ol-csrfToken')} />
|
2024-06-06 11:37:47 -04:00
|
|
|
<OLButton variant="secondary" onClick={handleCancel}>
|
2022-11-14 10:07:21 -05:00
|
|
|
{t('cancel')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
|
|
|
<OLButton
|
2024-04-23 10:12:25 -04:00
|
|
|
type="submit"
|
|
|
|
variant="danger-ghost"
|
2024-04-23 12:49:11 -04:00
|
|
|
onClick={handleConfirm}
|
2024-04-23 10:12:25 -04:00
|
|
|
>
|
2022-04-25 07:05:15 -04:00
|
|
|
{t('unlink')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2022-04-25 07:05:15 -04:00
|
|
|
</form>
|
2024-05-14 11:53:25 -04:00
|
|
|
</OLModalFooter>
|
|
|
|
</OLModal>
|
2022-04-22 09:49:26 -04:00
|
|
|
)
|
|
|
|
}
|