Skip to content

Commit

Permalink
Merge pull request #5194 from kobotoolbox/task-1083-mmo-label-util
Browse files Browse the repository at this point in the history
[TASK-1083] Add utils for determining MMO labeling
  • Loading branch information
duvld authored Oct 28, 2024
2 parents 5eef785 + 6246521 commit ffde206
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
47 changes: 47 additions & 0 deletions jsapp/js/account/organizations/organizations.utils.tsx
Original file line number Diff line number Diff line change
@@ -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');
}
7 changes: 6 additions & 1 deletion jsapp/js/envStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ffde206

Please sign in to comment.