diff --git a/jsapp/js/account/organizations/organizations.utils.tsx b/jsapp/js/account/organizations/organizations.utils.tsx new file mode 100644 index 0000000000..f30e9dcc78 --- /dev/null +++ b/jsapp/js/account/organizations/organizations.utils.tsx @@ -0,0 +1,47 @@ +import type {SubscriptionInfo} from 'jsapp/js/account/stripe.types'; +import type {EnvStoreData} from 'jsapp/js/envStore'; + +/** Only use this directly for complex cases/strings (for example, possessive case). + * Otherwise, use getSimpleMMOLabel. + * @param {EnvStoreData} envStoreData + * @param {SubscriptionInfo} subscription + * @returns boolean indicating whether an MMO should be referred to as a 'team' or as an 'organization + */ +export function shouldUseTeamLabel( + envStoreData: EnvStoreData, + subscription: SubscriptionInfo | null +) { + if (subscription) { + return ( + subscription.items[0].price.product.metadata?.plan_type !== 'enterprise' + ); + } + + return envStoreData.use_team_label; +} + +/** + * @param {EnvStoreData} envStoreData + * @param {SubscriptionInfo} subscription + * @param {boolean} plural + * @param {boolean} capitalize + * @returns Translated string for referring to MMO as 'team' or 'organization' + * */ +export function getSimpleMMOLabel( + envStoreData: EnvStoreData, + subscription: SubscriptionInfo | null, + plural: boolean = false, + capitalize: boolean = false +) { + if (shouldUseTeamLabel(envStoreData, subscription)) { + if (plural) { + return capitalize ? t('Teams') : t('teams'); + } + return capitalize ? t('Team') : t('team'); + } + + if (plural) { + return capitalize ? t('Organizations') : t('organizations'); + } + return capitalize ? t('Organization') : t('organization'); +} diff --git a/jsapp/js/envStore.ts b/jsapp/js/envStore.ts index 5d17d9940a..137085945c 100644 --- a/jsapp/js/envStore.ts +++ b/jsapp/js/envStore.ts @@ -5,7 +5,7 @@ import type {UserFieldName} from './account/account.constants'; const ENV_ENDPOINT = '/environment/'; -interface EnvironmentResponse { +export interface EnvironmentResponse { mfa_has_availability_list: boolean; terms_of_service_url: string; privacy_policy_url: string; @@ -22,6 +22,8 @@ interface EnvironmentResponse { transcription_languages: TransxLanguages; translation_languages: TransxLanguages; submission_placeholder: string; + // TODO: Remove optional marker when PR#5182 is merged + use_team_label?: boolean; frontend_min_retry_time: number; frontend_max_retry_time: number; asr_mt_features_enabled: boolean; @@ -110,6 +112,7 @@ export class EnvStoreData { public transcription_languages: TransxLanguages = {}; public translation_languages: TransxLanguages = {}; public submission_placeholder = ''; + public use_team_label = true; public asr_mt_features_enabled = false; public mfa_localized_help_text = ''; public mfa_enabled = false; @@ -212,6 +215,8 @@ class EnvStore { this.data.project_metadata_fields = response.project_metadata_fields; this.data.user_metadata_fields = response.user_metadata_fields; this.data.submission_placeholder = response.submission_placeholder; + // TODO: Assign response value when PR#5182 is merged + this.data.use_team_label = true; this.data.mfa_localized_help_text = response.mfa_localized_help_text; this.data.mfa_enabled = response.mfa_enabled; this.data.mfa_per_user_availability = response.mfa_per_user_availability;