| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- import { useCallback, useState, ReactNode } from 'react'
- import { useTranslation } from 'react-i18next'
- import AccessibleModal from '../../../../shared/components/accessible-modal'
- import { Button, Modal } from 'react-bootstrap'
- import getMeta from '../../../../utils/meta'
- 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 (
- <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>
- <p className="small">
- {description}{' '}
- <a href={helpPath} target="_blank" rel="noreferrer">
- {t('learn_more')}
- </a>
- </p>
- {hasFeature && statusIndicator}
- </div>
- <div>
- <ActionButton
- hasFeature={hasFeature}
- upgradePath="/user/subscription/plans"
- linked={linked}
- handleUnlinkClick={handleUnlinkClick}
- linkPath={linkPath}
- disabled={disabled}
- />
- </div>
- <UnlinkConfirmationModal
- show={showModal}
- title={unlinkConfirmationTitle}
- content={unlinkConfirmationText}
- unlinkPath={unlinkPath}
- handleHide={handleModalHide}
- />
- </div>
- )
- }
- type ActionButtonProps = {
- hasFeature?: boolean
- upgradePath: string
- linked?: boolean
- handleUnlinkClick: () => void
- linkPath: string
- disabled?: boolean
- }
- function ActionButton({
- hasFeature,
- upgradePath,
- linked,
- handleUnlinkClick,
- linkPath,
- disabled,
- }: ActionButtonProps) {
- const { t } = useTranslation()
- if (!hasFeature) {
- return (
- <Button bsStyle="info" href={upgradePath}>
- <span className="text-capitalize">{t('upgrade')}</span>
- </Button>
- )
- } else if (linked) {
- return (
- <Button bsStyle="danger" onClick={handleUnlinkClick} disabled={disabled}>
- {t('unlink')}
- </Button>
- )
- } else {
- return (
- <Button bsStyle="info" href={linkPath} disabled={disabled}>
- <span className="text-capitalize">{t('link')}</span>
- </Button>
- )
- }
- }
- type UnlinkConfirmModalProps = {
- show: boolean
- title: string
- content: string
- unlinkPath: string
- handleHide: () => void
- }
- function UnlinkConfirmationModal({
- show,
- title,
- content,
- unlinkPath,
- handleHide,
- }: UnlinkConfirmModalProps) {
- const { t } = useTranslation()
- const handleCancel = event => {
- event.preventDefault()
- handleHide()
- }
- 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>
- <form action={unlinkPath} method="POST" className="form-inline">
- <input type="hidden" name="_csrf" value={getMeta('ol-csrfToken')} />
- <Button onClick={handleCancel}>{t('cancel')}</Button>
- <Button type="submit" bsStyle="danger">
- {t('unlink')}
- </Button>
- </form>
- </Modal.Footer>
- </AccessibleModal>
- )
- }
|