Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7301,24 +7301,11 @@ const CONTINUATION_DETECTION_SEARCH_FILTER_KEYS = [
CONST.SEARCH.SYNTAX_FILTER_KEYS.ATTENDEE,
] as SearchFilterKey[];

const FEATURE_IDS = {
CATEGORIES: 'categories',
ACCOUNTING: 'accounting',
COMPANY_CARDS: 'company-cards',
TAGS: 'tags',
WORKFLOWS: 'workflows',
INVOICES: 'invoices',
RULES: 'rules',
PER_DIEM: 'per-diem',
DISTANCE_RATES: 'distance-rates',
EXPENSIFY_CARD: 'expensify-card',
};

const TASK_TO_FEATURE: Record<string, string> = {
[CONST.ONBOARDING_TASK_TYPE.SETUP_CATEGORIES]: FEATURE_IDS.CATEGORIES,
[CONST.ONBOARDING_TASK_TYPE.ADD_ACCOUNTING_INTEGRATION]: FEATURE_IDS.ACCOUNTING,
[CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD]: FEATURE_IDS.COMPANY_CARDS,
[CONST.ONBOARDING_TASK_TYPE.SETUP_TAGS]: FEATURE_IDS.TAGS,
[CONST.ONBOARDING_TASK_TYPE.SETUP_CATEGORIES]: CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED,
[CONST.ONBOARDING_TASK_TYPE.ADD_ACCOUNTING_INTEGRATION]: CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED,
[CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD]: CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED,
[CONST.ONBOARDING_TASK_TYPE.SETUP_TAGS]: CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED,
};

const FRAUD_PROTECTION_EVENT = {
Expand Down Expand Up @@ -7354,6 +7341,6 @@ type CancellationType = ValueOf<typeof CONST.CANCELLATION_TYPE>;

export type {Country, IOUAction, IOUType, IOURequestType, SubscriptionType, FeedbackSurveyOptionID, CancellationType, OnboardingInvite, OnboardingAccounting, IOUActionParams};

export {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS, TASK_TO_FEATURE, FEATURE_IDS, FRAUD_PROTECTION_EVENT};
export {CONTINUATION_DETECTION_SEARCH_FILTER_KEYS, TASK_TO_FEATURE, FRAUD_PROTECTION_EVENT};

export default CONST;
2 changes: 1 addition & 1 deletion src/libs/API/parameters/CreateWorkspaceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type CreateWorkspaceParams = {
file?: File;
companySize?: string;
userReportedIntegration?: string;
areDistanceRatesEnabled?: boolean;
memberData?: string;
features?: string;
};

export default CreateWorkspaceParams;
79 changes: 9 additions & 70 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import type {
} from '@libs/API/parameters';
import type SetPolicyCashExpenseModeParams from '@libs/API/parameters/SetPolicyCashExpenseModeParams';
import type UpdatePolicyMembersCustomFieldsParams from '@libs/API/parameters/UpdatePolicyMembersCustomFieldsParams';
import type {ApiRequestCommandParameters} from '@libs/API/types';
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types';
import * as CurrencyUtils from '@libs/CurrencyUtils';
Expand Down Expand Up @@ -98,7 +97,6 @@ import type {PolicySelector} from '@pages/home/sidebar/FloatingActionButtonAndPo
import type {Feature} from '@pages/OnboardingInterestedFeatures/types';
import * as PaymentMethods from '@userActions/PaymentMethods';
import * as PersistedRequests from '@userActions/PersistedRequests';
import type {EnablePolicyFeatureCommand} from '@userActions/RequestConflictUtils';
import {buildTaskData} from '@userActions/Task';
import {getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';
import type {OnboardingCompanySize, OnboardingPurpose} from '@userActions/Welcome/OnboardingFlow';
Expand Down Expand Up @@ -177,9 +175,8 @@ type BuildPolicyDataOptions = {
shouldAddOnboardingTasks?: boolean;
companySize?: OnboardingCompanySize;
userReportedIntegration?: OnboardingAccounting;
featuresMap?: Feature[];
featuresMap?: Array<Pick<Feature, 'id' | 'enabled' | 'enabledByDefault' | 'requiresUpdate'>>;
lastUsedPaymentMethod?: LastPaymentMethodType;
areDistanceRatesEnabled?: boolean;
adminParticipant?: Participant;
};

Expand Down Expand Up @@ -2035,7 +2032,6 @@ function buildPolicyData(options: BuildPolicyDataOptions = {}) {
userReportedIntegration,
featuresMap,
lastUsedPaymentMethod,
areDistanceRatesEnabled,
adminParticipant,
} = options;
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail);
Expand Down Expand Up @@ -2070,6 +2066,8 @@ function buildPolicyData(options: BuildPolicyDataOptions = {}) {
const isCorporateIntegration = userReportedIntegration && (CONST.POLICY.CONNECTIONS.CORPORATE as readonly string[]).includes(userReportedIntegration);
const workspaceType = isCorporateFeature || isCorporateIntegration ? CONST.POLICY.TYPE.CORPORATE : CONST.POLICY.TYPE.TEAM;

const areDistanceRatesEnabled = !!featuresMap?.find((feature) => feature.id === CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED && feature.enabled);

// WARNING: The data below should be kept in sync with the API so we create the policy with the correct configuration.
const optimisticData: OnyxUpdate[] = [
{
Expand Down Expand Up @@ -2383,6 +2381,11 @@ function buildPolicyData(options: BuildPolicyDataOptions = {}) {
// We need to clone the file to prevent non-indexable errors.
const clonedFile = file ? (createFile(file) as File) : undefined;

const features = featuresMap?.reduce<Record<string, boolean>>((acc, feature) => {
acc[feature.id] = !!feature.enabled;
return acc;
}, {});

const params: CreateWorkspaceParams = {
policyID,
adminsChatReportID,
Expand All @@ -2400,7 +2403,7 @@ function buildPolicyData(options: BuildPolicyDataOptions = {}) {
file: clonedFile,
companySize,
userReportedIntegration: userReportedIntegration ?? undefined,
areDistanceRatesEnabled,
features: features ? JSON.stringify(features) : undefined,
};

if (
Expand Down Expand Up @@ -6317,69 +6320,6 @@ function setIsComingFromGlobalReimbursementsFlow(value: boolean) {
Onyx.set(ONYXKEYS.IS_COMING_FROM_GLOBAL_REIMBURSEMENTS_FLOW, value);
}

function updateFeature(
request: {
endpoint: EnablePolicyFeatureCommand | typeof WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM;
parameters: ApiRequestCommandParameters[EnablePolicyFeatureCommand | typeof WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM];
},
policyID: string,
) {
if (request.endpoint === WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM) {
API.write(WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM, {
policyID,
enabled: request.parameters.enabled,
customUnitID: generateCustomUnitID(),
});
return;
}
// eslint-disable-next-line rulesdir/no-multiple-api-calls
API.writeWithNoDuplicatesEnableFeatureConflicts(request.endpoint, request.parameters);
}

function updateInterestedFeatures(features: Feature[], policyID: string, type: string | undefined) {
let shouldUpgradeToCorporate = false;

const requests: Array<{
endpoint: EnablePolicyFeatureCommand | typeof WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM;
parameters: ApiRequestCommandParameters[EnablePolicyFeatureCommand | typeof WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM];
}> = [];

features.forEach((feature) => {
// If the feature is not enabled by default but it's enabled now, we need to enable it
if (!feature.enabledByDefault && feature.enabled) {
if (feature.requiresUpdate && !shouldUpgradeToCorporate) {
shouldUpgradeToCorporate = true;
}
requests.push({
endpoint: feature.apiEndpoint,
parameters: {
policyID,
enabled: true,
},
});
}
// If the feature is enabled by default but it's not enabled now, we need to disable it
if (feature.enabledByDefault && !feature.enabled) {
requests.push({
endpoint: feature.apiEndpoint,
parameters: {
policyID,
enabled: false,
},
});
}
});

const isCorporate = type === CONST.POLICY.TYPE.CORPORATE;
if (shouldUpgradeToCorporate && !isCorporate) {
API.write(WRITE_COMMANDS.UPGRADE_TO_CORPORATE, {policyID});
}

requests.forEach((request) => {
updateFeature(request, policyID);
});
}

function clearPolicyTitleFieldError(policyID: string) {
if (!policyID) {
return;
Expand Down Expand Up @@ -6520,7 +6460,6 @@ export {
setPolicyAttendeeTrackingEnabled,
setPolicyReimbursableMode,
getCashExpenseReimbursableMode,
updateInterestedFeatures,
clearPolicyTitleFieldError,
inviteWorkspaceEmployeesToUber,
setWorkspaceConfirmationCurrency,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import {openOldDotLink} from '@libs/actions/Link';
import {createWorkspace, generatePolicyID, updateInterestedFeatures} from '@libs/actions/Policy/Policy';
import {createWorkspace, generatePolicyID} from '@libs/actions/Policy/Policy';
import {completeOnboarding} from '@libs/actions/Report';
import {setOnboardingAdminsChatReportID, setOnboardingPolicyID} from '@libs/actions/Welcome';
import {WRITE_COMMANDS} from '@libs/API/types';
import {navigateAfterOnboardingWithMicrotaskQueue} from '@libs/navigateAfterOnboarding';
import Navigation from '@libs/Navigation/Navigation';
import {waitForIdle} from '@libs/Network/SequentialQueue';
import {shouldOnboardingRedirectToOldDot} from '@libs/OnboardingUtils';
import {isPaidGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils';
import {closeReactNativeApp} from '@userActions/HybridApp';
import CONFIG from '@src/CONFIG';
import CONST, {FEATURE_IDS} from '@src/CONST';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -70,69 +69,59 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin
const features: Feature[] = useMemo(() => {
return [
{
id: FEATURE_IDS.CATEGORIES,
id: CONST.POLICY.MORE_FEATURES.ARE_CATEGORIES_ENABLED,
title: translate('workspace.moreFeatures.categories.title'),
icon: illustrations.FolderOpen,
enabledByDefault: true,
apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_CATEGORIES,
},
{
id: FEATURE_IDS.ACCOUNTING,
id: CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED,
title: translate('workspace.moreFeatures.connections.title'),
icon: illustrations.Accounting,
enabledByDefault: !!userReportedIntegration,
apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_CONNECTIONS,
},
{
id: FEATURE_IDS.COMPANY_CARDS,
id: CONST.POLICY.MORE_FEATURES.ARE_COMPANY_CARDS_ENABLED,
title: translate('workspace.moreFeatures.companyCards.title'),
icon: illustrations.CompanyCard,
enabledByDefault: true,
apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_COMPANY_CARDS,
},
{
id: FEATURE_IDS.WORKFLOWS,
id: CONST.POLICY.MORE_FEATURES.ARE_WORKFLOWS_ENABLED,
title: translate('workspace.moreFeatures.workflows.title'),
icon: illustrations.Workflows,
enabledByDefault: true,
apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_WORKFLOWS,
},
{
id: FEATURE_IDS.INVOICES,
id: CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED,
title: translate('workspace.moreFeatures.invoices.title'),
icon: illustrations.InvoiceBlue,
apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_INVOICING,
},
{
id: FEATURE_IDS.RULES,
id: CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED,
title: translate('workspace.moreFeatures.rules.title'),
icon: illustrations.Rules,
apiEndpoint: WRITE_COMMANDS.SET_POLICY_RULES_ENABLED,
requiresUpdate: true,
},
{
id: FEATURE_IDS.DISTANCE_RATES,
id: CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED,
title: translate('workspace.moreFeatures.distanceRates.title'),
icon: illustrations.Car,
apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_DISTANCE_RATES,
},
{
id: FEATURE_IDS.EXPENSIFY_CARD,
id: CONST.POLICY.MORE_FEATURES.ARE_EXPENSIFY_CARDS_ENABLED,
title: translate('workspace.moreFeatures.expensifyCard.title'),
icon: illustrations.HandCard,
apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_EXPENSIFY_CARDS,
},
{
id: FEATURE_IDS.TAGS,
id: CONST.POLICY.MORE_FEATURES.ARE_TAGS_ENABLED,
title: translate('workspace.moreFeatures.tags.title'),
icon: illustrations.Tag,
apiEndpoint: WRITE_COMMANDS.ENABLE_POLICY_TAGS,
},
{
id: FEATURE_IDS.PER_DIEM,
id: CONST.POLICY.MORE_FEATURES.ARE_PER_DIEM_RATES_ENABLED,
title: translate('workspace.moreFeatures.perDiem.title'),
icon: illustrations.PerDiem,
apiEndpoint: WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM,
requiresUpdate: true,
},
];
Expand Down Expand Up @@ -179,7 +168,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin

// We need `adminsChatReportID` for `completeOnboarding`, but at the same time, we don't want to call `createWorkspace` more than once.
// If we have already created a workspace, we want to reuse the `onboardingAdminsChatReportID` and `onboardingPolicyID`.
const {adminsChatReportID, policyID, type} = shouldCreateWorkspace
const {adminsChatReportID, policyID} = shouldCreateWorkspace
? createWorkspace({
policyOwnerEmail: undefined,
makeMeAdmin: true,
Expand All @@ -193,11 +182,7 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin
userReportedIntegration: newUserReportedIntegration,
featuresMap,
})
: {adminsChatReportID: onboardingAdminsChatReportID, policyID: onboardingPolicyID, type: undefined};

if (policyID) {
updateInterestedFeatures(featuresMap, policyID, type);
}
: {adminsChatReportID: onboardingAdminsChatReportID, policyID: onboardingPolicyID};

if (shouldCreateWorkspace) {
setOnboardingAdminsChatReportID(adminsChatReportID);
Expand Down Expand Up @@ -259,14 +244,14 @@ function BaseOnboardingInterestedFeatures({shouldUseNativeStyles}: BaseOnboardin

// Create items for enabled features
const enabledFeatures: Feature[] = features
.filter((feature) => !!feature.enabledByDefault || feature.id === FEATURE_IDS.ACCOUNTING)
.filter((feature) => !!feature.enabledByDefault || feature.id === CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED)
.map((feature) => ({
...feature,
}));

// Create items for features they may be interested in
const mayBeInterestedFeatures: Feature[] = features
.filter((feature) => !feature.enabledByDefault && feature.id !== FEATURE_IDS.ACCOUNTING)
.filter((feature) => !feature.enabledByDefault && feature.id !== CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED)
.map((feature) => ({
...feature,
}));
Expand Down
3 changes: 0 additions & 3 deletions src/pages/OnboardingInterestedFeatures/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type {EnablePolicyFeatureCommand} from '@libs/actions/RequestConflictUtils';
import type {WRITE_COMMANDS} from '@libs/API/types';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import type {OnboardingModalNavigatorParamList} from '@libs/Navigation/types';
import type SCREENS from '@src/SCREENS';
Expand All @@ -17,7 +15,6 @@ type Feature = {
title: string;
icon: IconAsset;
enabledByDefault?: boolean;
apiEndpoint: EnablePolicyFeatureCommand | typeof WRITE_COMMANDS.TOGGLE_POLICY_PER_DIEM;
requiresUpdate?: boolean;
enabled?: boolean;
};
Expand Down
7 changes: 6 additions & 1 deletion src/pages/iou/request/step/IOURequestStepUpgrade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ function IOURequestStepUpgrade({
policyID: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE,
currency: currentUserPersonalDetails?.localCurrencyCode ?? '',
areDistanceRatesEnabled: isDistanceRateUpgrade,
featuresMap: [
{
id: CONST.POLICY.MORE_FEATURES.ARE_DISTANCE_RATES_ENABLED,
enabled: isDistanceRateUpgrade,
},
],
adminParticipant,
});
setIsUpgraded(true);
Expand Down