2023-11-07 04:09:12 -05:00
|
|
|
import GroupSettingsButton from '@/features/subscription/components/dashboard/group-settings-button'
|
|
|
|
import getMeta from '@/utils/meta'
|
2023-01-31 10:42:52 -05:00
|
|
|
import { Trans, useTranslation } from 'react-i18next'
|
2023-02-07 10:38:04 -05:00
|
|
|
import { useSubscriptionDashboardContext } from '../../context/subscription-dashboard-context'
|
2023-06-08 09:19:32 -04:00
|
|
|
import { RowLink } from './row-link'
|
2024-05-30 08:35:56 -04:00
|
|
|
import { ManagedGroupSubscription } from '../../../../../../types/subscription/dashboard/subscription'
|
|
|
|
|
|
|
|
function ManagedGroupAdministrator({
|
|
|
|
subscription,
|
|
|
|
}: {
|
|
|
|
subscription: ManagedGroupSubscription
|
|
|
|
}) {
|
2024-06-18 06:01:37 -04:00
|
|
|
const usersEmail = getMeta('ol-usersEmail')
|
2024-05-30 08:35:56 -04:00
|
|
|
const values = {
|
|
|
|
planName: subscription.planLevelName,
|
|
|
|
groupName: subscription.teamName || '',
|
|
|
|
adminEmail: subscription.admin_id.email,
|
|
|
|
}
|
|
|
|
|
|
|
|
const isAdmin = usersEmail === subscription.admin_id.email
|
|
|
|
|
|
|
|
if (subscription.userIsGroupMember && !isAdmin) {
|
|
|
|
return (
|
|
|
|
<Trans
|
|
|
|
i18nKey="you_are_a_manager_and_member_of_x_plan_as_member_of_group_subscription_y_administered_by_z"
|
|
|
|
components={[
|
|
|
|
// eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
|
|
|
|
<a href="/user/subscription/plans" />,
|
|
|
|
// eslint-disable-next-line react/jsx-key
|
|
|
|
<strong />,
|
|
|
|
]}
|
|
|
|
values={values}
|
|
|
|
shouldUnescape
|
|
|
|
tOptions={{ interpolation: { escapeValue: true } }}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
} else if (subscription.userIsGroupMember && isAdmin) {
|
|
|
|
return (
|
|
|
|
<Trans
|
|
|
|
i18nKey="you_are_a_manager_and_member_of_x_plan_as_member_of_group_subscription_y_administered_by_z_you"
|
|
|
|
components={[
|
|
|
|
// eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
|
|
|
|
<a href="/user/subscription/plans" />,
|
|
|
|
// eslint-disable-next-line react/jsx-key
|
|
|
|
<strong />,
|
|
|
|
]}
|
|
|
|
values={values}
|
|
|
|
shouldUnescape
|
|
|
|
tOptions={{ interpolation: { escapeValue: true } }}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
} else if (isAdmin) {
|
|
|
|
return (
|
|
|
|
<Trans
|
|
|
|
i18nKey="you_are_a_manager_of_x_plan_as_member_of_group_subscription_y_administered_by_z_you"
|
|
|
|
components={[
|
|
|
|
// eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
|
|
|
|
<a href="/user/subscription/plans" />,
|
|
|
|
// eslint-disable-next-line react/jsx-key
|
|
|
|
<strong />,
|
|
|
|
]}
|
|
|
|
values={values}
|
|
|
|
shouldUnescape
|
|
|
|
tOptions={{ interpolation: { escapeValue: true } }}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Trans
|
|
|
|
i18nKey="you_are_a_manager_of_x_plan_as_member_of_group_subscription_y_administered_by_z"
|
|
|
|
components={[
|
|
|
|
// eslint-disable-next-line react/jsx-key, jsx-a11y/anchor-has-content
|
|
|
|
<a href="/user/subscription/plans" />,
|
|
|
|
// eslint-disable-next-line react/jsx-key
|
|
|
|
<strong />,
|
|
|
|
]}
|
|
|
|
values={values}
|
|
|
|
shouldUnescape
|
|
|
|
tOptions={{ interpolation: { escapeValue: true } }}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2023-01-31 10:42:52 -05:00
|
|
|
|
2023-02-07 10:38:04 -05:00
|
|
|
export default function ManagedGroupSubscriptions() {
|
2023-01-31 10:42:52 -05:00
|
|
|
const { t } = useTranslation()
|
2023-02-07 10:38:04 -05:00
|
|
|
const { managedGroupSubscriptions } = useSubscriptionDashboardContext()
|
2023-01-31 10:42:52 -05:00
|
|
|
|
2023-02-07 10:38:04 -05:00
|
|
|
if (!managedGroupSubscriptions) {
|
2023-01-31 10:42:52 -05:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2024-06-18 06:01:37 -04:00
|
|
|
const groupSettingsEnabledFor = getMeta('ol-groupSettingsEnabledFor') || []
|
2023-11-07 04:09:12 -05:00
|
|
|
|
2023-01-31 10:42:52 -05:00
|
|
|
return (
|
|
|
|
<>
|
2023-11-06 06:01:43 -05:00
|
|
|
{managedGroupSubscriptions.map(subscription => {
|
|
|
|
return (
|
|
|
|
<div key={`managed-group-${subscription._id}`}>
|
|
|
|
<p>
|
2024-05-30 08:35:56 -04:00
|
|
|
<ManagedGroupAdministrator subscription={subscription} />
|
2023-11-06 06:01:43 -05:00
|
|
|
</p>
|
2024-09-30 05:49:18 -04:00
|
|
|
<ul className="list-group p-0">
|
|
|
|
<RowLink
|
|
|
|
href={`/manage/groups/${subscription._id}/members`}
|
|
|
|
heading={t('manage_members')}
|
|
|
|
subtext={t('manage_group_members_subtext')}
|
|
|
|
icon="groups"
|
|
|
|
/>
|
|
|
|
<RowLink
|
|
|
|
href={`/manage/groups/${subscription._id}/managers`}
|
|
|
|
heading={t('manage_group_managers')}
|
|
|
|
subtext={t('manage_managers_subtext')}
|
|
|
|
icon="manage_accounts"
|
|
|
|
/>
|
|
|
|
{groupSettingsEnabledFor?.includes(subscription._id) && (
|
|
|
|
<GroupSettingsButton subscription={subscription} />
|
|
|
|
)}
|
|
|
|
<RowLink
|
|
|
|
href={`/metrics/groups/${subscription._id}`}
|
|
|
|
heading={t('view_metrics')}
|
|
|
|
subtext={t('view_metrics_group_subtext')}
|
|
|
|
icon="insights"
|
|
|
|
/>
|
|
|
|
</ul>
|
2023-11-06 06:01:43 -05:00
|
|
|
<hr />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})}
|
2023-01-31 10:42:52 -05:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|