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
6 changes: 6 additions & 0 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ type CreateWorkspaceWithPolicyDraftParams = {
type?: PolicyType;
betas: OnyxEntry<OnyxTypes.Beta[]>;
hasActiveAdminPolicies: boolean;
isAnnualSubscription?: boolean;
};

/**
Expand All @@ -598,6 +599,7 @@ function createWorkspaceWithPolicyDraftAndNavigateToIt(params: CreateWorkspaceWi
isSelfTourViewed,
betas,
hasActiveAdminPolicies,
isAnnualSubscription = false,
} = params;

const policyIDWithDefault = policyID || generatePolicyID();
Expand Down Expand Up @@ -626,6 +628,7 @@ function createWorkspaceWithPolicyDraftAndNavigateToIt(params: CreateWorkspaceWi
isSelfTourViewed,
betas,
hasActiveAdminPolicies,
isAnnualSubscription,
});
Navigation.navigate(routeToNavigate, {forceReplace: !transitionFromOldDot});
});
Expand Down Expand Up @@ -689,6 +692,7 @@ type SavePolicyDraftByNewWorkspaceParams = {
type?: PolicyType;
betas: OnyxEntry<OnyxTypes.Beta[]>;
hasActiveAdminPolicies: boolean;
isAnnualSubscription?: boolean;
};

/**
Expand All @@ -712,6 +716,7 @@ function savePolicyDraftByNewWorkspace({
isSelfTourViewed,
betas,
hasActiveAdminPolicies,
isAnnualSubscription = false,
}: SavePolicyDraftByNewWorkspaceParams) {
createWorkspace({
policyOwnerEmail,
Expand All @@ -732,6 +737,7 @@ function savePolicyDraftByNewWorkspace({
isSelfTourViewed,
betas,
hasActiveAdminPolicies,
isAnnualSubscription,
});
}

Expand Down
7 changes: 5 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
shouldAddOnboardingTasks?: boolean;
companySize?: OnboardingCompanySize;
userReportedIntegration?: OnboardingAccounting;
isAnnualSubscription?: boolean;
featuresMap?: Array<Pick<Feature, 'id' | 'enabled' | 'enabledByDefault' | 'requiresUpdate'>>;
lastUsedPaymentMethod?: LastPaymentMethodType;
adminParticipant?: Participant;
Expand Down Expand Up @@ -252,7 +253,7 @@
};

const deprecatedAllPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 256 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (val, key) => {
if (!key) {
Expand All @@ -268,7 +269,7 @@
});

let deprecatedAllReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 272 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -278,7 +279,7 @@

let deprecatedSessionEmail = '';
let deprecatedSessionAccountID = 0;
Onyx.connect({

Check warning on line 282 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
deprecatedSessionEmail = val?.email ?? '';
Expand All @@ -287,7 +288,7 @@
});

let deprecatedAllPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 291 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => (deprecatedAllPersonalDetails = val),
});
Expand Down Expand Up @@ -2321,6 +2322,7 @@
currency = '',
file?: File,
type: typeof CONST.POLICY.TYPE.TEAM | typeof CONST.POLICY.TYPE.CORPORATE = CONST.POLICY.TYPE.TEAM,
isAnnualSubscription = false,
) {
const {customUnits, outputCurrency} = buildOptimisticDistanceRateCustomUnits(currency);
const shouldEnableWorkflowsByDefault =
Expand All @@ -2332,7 +2334,7 @@
key: `${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`,
value: {
id: policyID,
type: type || CONST.POLICY.TYPE.TEAM,
type: type || (isAnnualSubscription ? CONST.POLICY.TYPE.CORPORATE : CONST.POLICY.TYPE.TEAM),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor annual default when draft workspace type is unset

createDraftInitialWorkspace() now tries to default annual users to a Control workspace, but this line still uses type || ... while type is always initialized to CONST.POLICY.TYPE.TEAM in the function signature. In the common case where callers omit type, the fallback for isAnnualSubscription is never reached, so the draft remains Team. This breaks the new annual-default behavior for any flow that relies on the draft value before/without a successful createWorkspace round-trip.

Useful? React with 👍 / 👎.

Comment thread
daledah marked this conversation as resolved.
name: workspaceName,
role: CONST.POLICY.ROLE.ADMIN,
owner: currentUserEmail,
Expand Down Expand Up @@ -2421,6 +2423,7 @@
shouldAddOnboardingTasks = true,
companySize,
userReportedIntegration,
isAnnualSubscription = false,
featuresMap,
lastUsedPaymentMethod,
adminParticipant,
Expand Down Expand Up @@ -2468,7 +2471,7 @@
const isCorporateFeature = featuresMap?.some((feature) => !feature.enabledByDefault && feature.enabled && feature.requiresUpdate) ?? false;
const isCorporateIntegration = userReportedIntegration && (CONST.POLICY.CONNECTIONS.CORPORATE as readonly string[]).includes(userReportedIntegration);

const workspaceType = type ?? (isCorporateFeature || isCorporateIntegration || shouldCreateControlPolicy ? CONST.POLICY.TYPE.CORPORATE : CONST.POLICY.TYPE.TEAM);
const workspaceType = type ?? (isCorporateFeature || isCorporateIntegration || shouldCreateControlPolicy || isAnnualSubscription ? 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);

Expand Down
3 changes: 3 additions & 0 deletions src/pages/workspace/WorkspaceConfirmationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {createWorkspaceWithPolicyDraftAndNavigateToIt} from '@libs/actions/App';
import {generatePolicyID} from '@libs/actions/Policy/Policy';
import getCurrentUrl from '@libs/Navigation/currentUrl';
import {isSubscriptionTypeOfInvoicing} from '@libs/SubscriptionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {LastPaymentMethodType} from '@src/types/onyx';
Expand All @@ -29,6 +30,7 @@ function WorkspaceConfirmationPage() {

const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const privateSubscription = usePrivateSubscription();
const isAnnualSubscription = privateSubscription?.type === CONST.SUBSCRIPTION.TYPE.ANNUAL;
const hasActiveAdminPolicies = useHasActiveAdminPolicies();

const onSubmit = (params: WorkspaceConfirmationSubmitFunctionParams) => {
Expand All @@ -54,6 +56,7 @@ function WorkspaceConfirmationPage() {
isSelfTourViewed,
betas,
hasActiveAdminPolicies,
isAnnualSubscription,
});
};
const currentUrl = getCurrentUrl();
Expand Down
Loading