group-settings-button.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { RowLink } from '@/features/subscription/components/dashboard/row-link'
  2. import { useTranslation } from 'react-i18next'
  3. import { useLocation } from '@/shared/hooks/use-location'
  4. import MaterialIcon from '@/shared/components/material-icon'
  5. import OLTag from '@/shared/components/ol/ol-tag'
  6. import { ManagedGroupSubscription } from '../../../../../../types/subscription/dashboard/subscription'
  7. import { sendMB } from '../../../../infrastructure/event-tracking'
  8. import starIcon from '../../images/star-gradient.svg'
  9. function AvailableWithGroupProfessionalBadge() {
  10. const { t } = useTranslation()
  11. const location = useLocation()
  12. const handleUpgradeClick = () => {
  13. sendMB('flex-upgrade', {
  14. location: 'ad-badge',
  15. })
  16. location.assign('/user/subscription/group/upgrade-subscription')
  17. }
  18. return (
  19. <OLTag
  20. prepend={<img aria-hidden="true" src={starIcon} alt="" />}
  21. contentProps={{
  22. className: 'mw-100',
  23. onClick: handleUpgradeClick,
  24. }}
  25. >
  26. <strong>{t('available_for_pro_groups')}</strong>
  27. </OLTag>
  28. )
  29. }
  30. function useGroupSettingsButton(subscription: ManagedGroupSubscription) {
  31. const { t } = useTranslation()
  32. const subscriptionHasManagedUsers =
  33. subscription.features?.managedUsers === true
  34. const subscriptionHasGroupSSO = subscription.features?.groupSSO === true
  35. const heading = t('group_settings')
  36. let groupSettingRowSubText = ''
  37. if (subscriptionHasGroupSSO && subscriptionHasManagedUsers) {
  38. groupSettingRowSubText = t('manage_group_settings_subtext')
  39. } else if (subscriptionHasGroupSSO) {
  40. groupSettingRowSubText = t('manage_group_settings_subtext_group_sso')
  41. } else if (subscriptionHasManagedUsers) {
  42. groupSettingRowSubText = t('manage_group_settings_subtext_managed_users')
  43. }
  44. return {
  45. heading,
  46. groupSettingRowSubText,
  47. }
  48. }
  49. export function GroupSettingsButton({
  50. subscription,
  51. }: {
  52. subscription: ManagedGroupSubscription
  53. }) {
  54. const { heading, groupSettingRowSubText } =
  55. useGroupSettingsButton(subscription)
  56. return (
  57. <RowLink
  58. href={`/manage/groups/${subscription._id}/settings`}
  59. heading={heading}
  60. subtext={groupSettingRowSubText}
  61. icon="settings"
  62. />
  63. )
  64. }
  65. export function GroupSettingsButtonWithAdBadge({
  66. subscription,
  67. }: {
  68. subscription: ManagedGroupSubscription
  69. }) {
  70. const { heading, groupSettingRowSubText } =
  71. useGroupSettingsButton(subscription)
  72. return (
  73. <li className="list-group-item row-link">
  74. <div className="row-link-inner">
  75. <MaterialIcon type="settings" className="p-2 p-md-3 text-muted" />
  76. <div className="flex-grow-1 text-truncate text-muted">
  77. <strong>{heading}</strong>
  78. <div className="text-truncate">{groupSettingRowSubText}</div>
  79. </div>
  80. <span className="p-2 p-md-3">
  81. <AvailableWithGroupProfessionalBadge />
  82. </span>
  83. </div>
  84. </li>
  85. )
  86. }