managed-group-subscriptions.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {
  2. GroupSettingsButton,
  3. GroupSettingsButtonWithAdBadge,
  4. } from '@/features/subscription/components/dashboard/group-settings-button'
  5. import getMeta from '@/utils/meta'
  6. import { Trans, useTranslation } from 'react-i18next'
  7. import { useSubscriptionDashboardContext } from '../../context/subscription-dashboard-context'
  8. import { RowLink } from './row-link'
  9. import { ManagedGroupSubscription } from '../../../../../../types/subscription/dashboard/subscription'
  10. function ManagedGroupAdministrator({
  11. subscription,
  12. }: {
  13. subscription: ManagedGroupSubscription
  14. }) {
  15. const usersEmail = getMeta('ol-usersEmail')
  16. const values = {
  17. planName: subscription.planLevelName,
  18. groupName: subscription.teamName || '',
  19. adminEmail: subscription.admin_id.email,
  20. }
  21. const isAdmin = usersEmail === subscription.admin_id.email
  22. if (subscription.userIsGroupMember && !isAdmin) {
  23. return (
  24. <Trans
  25. i18nKey="you_are_a_manager_and_member_of_x_plan_as_member_of_group_subscription_y_administered_by_z"
  26. components={[
  27. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  28. <a href="/user/subscription/plans" />,
  29. // eslint-disable-next-line react/jsx-key
  30. <strong />,
  31. ]}
  32. values={values}
  33. shouldUnescape
  34. tOptions={{ interpolation: { escapeValue: true } }}
  35. />
  36. )
  37. } else if (subscription.userIsGroupMember && isAdmin) {
  38. return (
  39. <Trans
  40. i18nKey="you_are_a_manager_and_member_of_x_plan_as_member_of_group_subscription_y_administered_by_z_you"
  41. components={[
  42. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  43. <a href="/user/subscription/plans" />,
  44. // eslint-disable-next-line react/jsx-key
  45. <strong />,
  46. ]}
  47. values={values}
  48. shouldUnescape
  49. tOptions={{ interpolation: { escapeValue: true } }}
  50. />
  51. )
  52. } else if (isAdmin) {
  53. return (
  54. <Trans
  55. i18nKey="you_are_a_manager_of_x_plan_as_member_of_group_subscription_y_administered_by_z_you"
  56. components={[
  57. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  58. <a href="/user/subscription/plans" />,
  59. // eslint-disable-next-line react/jsx-key
  60. <strong />,
  61. ]}
  62. values={values}
  63. shouldUnescape
  64. tOptions={{ interpolation: { escapeValue: true } }}
  65. />
  66. )
  67. }
  68. return (
  69. <Trans
  70. i18nKey="you_are_a_manager_of_x_plan_as_member_of_group_subscription_y_administered_by_z"
  71. components={[
  72. // eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
  73. <a href="/user/subscription/plans" />,
  74. // eslint-disable-next-line react/jsx-key
  75. <strong />,
  76. ]}
  77. values={values}
  78. shouldUnescape
  79. tOptions={{ interpolation: { escapeValue: true } }}
  80. />
  81. )
  82. }
  83. export default function ManagedGroupSubscriptions() {
  84. const { t } = useTranslation()
  85. const { managedGroupSubscriptions } = useSubscriptionDashboardContext()
  86. if (!managedGroupSubscriptions) {
  87. return null
  88. }
  89. const groupSettingsAdvertisedFor =
  90. getMeta('ol-groupSettingsAdvertisedFor') || []
  91. const groupSettingsEnabledFor = getMeta('ol-groupSettingsEnabledFor') || []
  92. const splitTestVariants = getMeta('ol-splitTestVariants')
  93. const displayAuditLogsLink =
  94. splitTestVariants?.['group-audit-logs'] === 'active'
  95. return (
  96. <>
  97. {managedGroupSubscriptions.map(subscription => {
  98. return (
  99. <div key={`managed-group-${subscription._id}`}>
  100. <h2 className="h3 fw-bold">{t('group_management')}</h2>
  101. <p>
  102. <ManagedGroupAdministrator subscription={subscription} />
  103. </p>
  104. <ul className="list-group p-0">
  105. <RowLink
  106. href={`/manage/groups/${subscription._id}/members`}
  107. heading={t('group_members')}
  108. subtext={t('manage_group_members_subtext')}
  109. icon="groups"
  110. />
  111. <RowLink
  112. href={`/manage/groups/${subscription._id}/managers`}
  113. heading={t('group_managers')}
  114. subtext={t('manage_managers_subtext')}
  115. icon="manage_accounts"
  116. />
  117. {groupSettingsEnabledFor?.includes(subscription._id) && (
  118. <GroupSettingsButton subscription={subscription} />
  119. )}
  120. {groupSettingsAdvertisedFor?.includes(subscription._id) && (
  121. <GroupSettingsButtonWithAdBadge subscription={subscription} />
  122. )}
  123. {displayAuditLogsLink && (
  124. <RowLink
  125. href={`/manage/groups/${subscription._id}/audit-logs`}
  126. heading={t('audit_logs')}
  127. subtext={t('view_audit_logs_group_subtext')}
  128. icon="list"
  129. />
  130. )}
  131. <RowLink
  132. href={`/metrics/groups/${subscription._id}`}
  133. heading={t('usage_metrics')}
  134. subtext={t('view_metrics_group_subtext')}
  135. icon="insights"
  136. />
  137. </ul>
  138. <hr />
  139. </div>
  140. )
  141. })}
  142. </>
  143. )
  144. }