2022-04-22 09:49:26 -04:00
|
|
|
import { useCallback, useState, ReactNode } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import AccessibleModal from '../../../../shared/components/accessible-modal'
|
2022-04-25 07:05:15 -04:00
|
|
|
import { Button, Modal } from 'react-bootstrap'
|
|
|
|
import getMeta from '../../../../utils/meta'
|
2022-06-10 04:14:00 -04:00
|
|
|
import { sendMB } from '../../../../infrastructure/event-tracking'
|
|
|
|
|
|
|
|
function trackUpgradeClick() {
|
|
|
|
sendMB('settings-upgrade-click')
|
|
|
|
}
|
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>
|
|
|
|
{!hasFeature && (
|
|
|
|
<span className="label label-info">{t('premium_feature')}</span>
|
|
|
|
)}
|
|
|
|
</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
|
|
|
|
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
|
|
|
|
show={showModal}
|
|
|
|
title={unlinkConfirmationTitle}
|
|
|
|
content={unlinkConfirmationText}
|
|
|
|
unlinkPath={unlinkPath}
|
|
|
|
handleHide={handleModalHide}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ActionButtonProps = {
|
|
|
|
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,
|
2022-04-22 09:49:26 -04:00
|
|
|
}: ActionButtonProps) {
|
|
|
|
const { t } = useTranslation()
|
2022-12-07 05:51:53 -05:00
|
|
|
const classNames = require('classnames')
|
|
|
|
const classes = classNames(
|
|
|
|
'btn',
|
|
|
|
'btn-secondary-info',
|
|
|
|
'btn-secondary',
|
|
|
|
'text-capitalize'
|
|
|
|
)
|
2022-04-22 09:49:26 -04:00
|
|
|
if (!hasFeature) {
|
|
|
|
return (
|
2022-06-10 04:14:00 -04:00
|
|
|
<Button
|
2022-11-14 10:07:21 -05:00
|
|
|
bsStyle={null}
|
2022-12-05 10:32:54 -05:00
|
|
|
className="btn-primary"
|
2022-06-10 04:14:00 -04:00
|
|
|
href="/user/subscription/plans"
|
|
|
|
onClick={trackUpgradeClick}
|
|
|
|
>
|
2022-05-25 03:59:24 -04:00
|
|
|
<span className="text-capitalize">{t('upgrade')}</span>
|
|
|
|
</Button>
|
2022-04-22 09:49:26 -04:00
|
|
|
)
|
|
|
|
} else if (linked) {
|
|
|
|
return (
|
2022-05-25 03:59:24 -04:00
|
|
|
<Button bsStyle="danger" onClick={handleUnlinkClick} disabled={disabled}>
|
2022-04-22 09:49:26 -04:00
|
|
|
{t('unlink')}
|
2022-05-25 03:59:24 -04:00
|
|
|
</Button>
|
2022-04-22 09:49:26 -04:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return (
|
2022-12-07 05:51:53 -05:00
|
|
|
<>
|
|
|
|
{disabled ? (
|
|
|
|
<button disabled className={classes}>
|
|
|
|
{t('link')}
|
|
|
|
</button>
|
|
|
|
) : (
|
|
|
|
<a className={classes} href={linkPath}>
|
|
|
|
{t('link')}
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</>
|
2022-04-22 09:49:26 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type UnlinkConfirmModalProps = {
|
|
|
|
show: boolean
|
|
|
|
title: string
|
|
|
|
content: string
|
|
|
|
unlinkPath: string
|
|
|
|
handleHide: () => void
|
|
|
|
}
|
|
|
|
|
|
|
|
function UnlinkConfirmationModal({
|
|
|
|
show,
|
|
|
|
title,
|
|
|
|
content,
|
|
|
|
unlinkPath,
|
|
|
|
handleHide,
|
|
|
|
}: UnlinkConfirmModalProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2022-05-26 05:39:07 -04:00
|
|
|
const handleCancel = (
|
|
|
|
event: React.MouseEvent<HTMLButtonElement & Button>
|
|
|
|
) => {
|
2022-04-25 07:05:15 -04:00
|
|
|
event.preventDefault()
|
|
|
|
handleHide()
|
|
|
|
}
|
2022-04-22 09:49:26 -04:00
|
|
|
return (
|
|
|
|
<AccessibleModal show={show} onHide={handleHide}>
|
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>{title}</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
|
|
|
|
<Modal.Body className="modal-body-share">
|
|
|
|
<p>{content}</p>
|
|
|
|
</Modal.Body>
|
|
|
|
|
|
|
|
<Modal.Footer>
|
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')} />
|
2022-11-14 10:07:21 -05:00
|
|
|
<Button
|
|
|
|
className="btn-secondary-info btn-secondary"
|
|
|
|
onClick={handleCancel}
|
|
|
|
>
|
|
|
|
{t('cancel')}
|
|
|
|
</Button>
|
2022-04-25 07:05:15 -04:00
|
|
|
<Button type="submit" bsStyle="danger">
|
|
|
|
{t('unlink')}
|
|
|
|
</Button>
|
|
|
|
</form>
|
2022-04-22 09:49:26 -04:00
|
|
|
</Modal.Footer>
|
|
|
|
</AccessibleModal>
|
|
|
|
)
|
|
|
|
}
|