enable-widget.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { ReactNode } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { sendMB } from '@/infrastructure/event-tracking'
  4. import OLBadge from '@/features/ui/components/ol/ol-badge'
  5. import OLButton from '@/features/ui/components/ol/ol-button'
  6. function trackUpgradeClick() {
  7. sendMB('settings-upgrade-click')
  8. }
  9. type EnableWidgetProps = {
  10. logo: ReactNode
  11. title: string
  12. description: string
  13. helpPath: string
  14. helpTextOverride?: string
  15. hasFeature?: boolean
  16. isPremiumFeature?: boolean
  17. statusIndicator?: ReactNode
  18. children?: ReactNode
  19. linked?: boolean
  20. handleLinkClick: () => void
  21. handleUnlinkClick: () => void
  22. disabled?: boolean
  23. }
  24. export function EnableWidget({
  25. logo,
  26. title,
  27. description,
  28. helpPath,
  29. helpTextOverride,
  30. hasFeature,
  31. isPremiumFeature,
  32. statusIndicator,
  33. linked,
  34. handleLinkClick,
  35. handleUnlinkClick,
  36. children,
  37. disabled,
  38. }: EnableWidgetProps) {
  39. const { t } = useTranslation()
  40. const helpText = helpTextOverride || t('learn_more')
  41. return (
  42. <div className="settings-widget-container">
  43. <div>{logo}</div>
  44. <div className="description-container">
  45. <div className="title-row">
  46. <h4>{title}</h4>
  47. {!hasFeature && isPremiumFeature && (
  48. <OLBadge bg="info">{t('premium_feature')}</OLBadge>
  49. )}
  50. </div>
  51. <p className="small">
  52. {description}{' '}
  53. <a href={helpPath} target="_blank" rel="noreferrer">
  54. {helpText}
  55. </a>
  56. </p>
  57. {children}
  58. {hasFeature && statusIndicator}
  59. </div>
  60. <div>
  61. <ActionButton
  62. hasFeature={hasFeature}
  63. linked={linked}
  64. handleUnlinkClick={handleUnlinkClick}
  65. handleLinkClick={handleLinkClick}
  66. disabled={disabled}
  67. />
  68. </div>
  69. </div>
  70. )
  71. }
  72. type ActionButtonProps = {
  73. hasFeature?: boolean
  74. linked?: boolean
  75. handleUnlinkClick: () => void
  76. handleLinkClick: () => void
  77. disabled?: boolean
  78. }
  79. function ActionButton({
  80. linked,
  81. handleUnlinkClick,
  82. handleLinkClick,
  83. hasFeature,
  84. disabled,
  85. }: ActionButtonProps) {
  86. const { t } = useTranslation()
  87. if (!hasFeature) {
  88. return (
  89. <OLButton
  90. variant="primary"
  91. href="/user/subscription/plans"
  92. onClick={trackUpgradeClick}
  93. bs3Props={{ bsStyle: null, className: 'btn-primary' }}
  94. >
  95. <span className="text-capitalize">{t('upgrade')}</span>
  96. </OLButton>
  97. )
  98. } else if (linked) {
  99. return (
  100. <OLButton
  101. variant="danger-ghost"
  102. onClick={handleUnlinkClick}
  103. disabled={disabled}
  104. bs3Props={{ bsStyle: null, className: 'btn-danger-ghost' }}
  105. >
  106. {t('turn_off')}
  107. </OLButton>
  108. )
  109. } else {
  110. return (
  111. <OLButton
  112. variant="secondary"
  113. disabled={disabled}
  114. onClick={handleLinkClick}
  115. bs3Props={{
  116. bsStyle: null,
  117. className: 'btn btn-secondary-info btn-secondary',
  118. }}
  119. >
  120. {t('turn_on')}
  121. </OLButton>
  122. )
  123. }
  124. }
  125. export default EnableWidget