Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow all even accountIDs to use "Create Expense" #50066

Merged
merged 9 commits into from
Nov 11, 2024
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
5 changes: 1 addition & 4 deletions src/libs/AccountUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import type {Account} from '@src/types/onyx';
const isValidateCodeFormSubmitting = (account: OnyxEntry<Account>) =>
!!account?.isLoading && account.loadingForm === (account.requiresTwoFactorAuth ? CONST.FORMS.VALIDATE_TFA_CODE_FORM : CONST.FORMS.VALIDATE_CODE_FORM);

/** Whether the accound ID is an odd number, useful for A/B testing. */
const isAccountIDOddNumber = (accountID: number) => accountID % 2 === 1;

function isDelegateOnlySubmitter(account: OnyxEntry<Account>): boolean {
const delegateEmail = account?.delegatedAccess?.delegate;
const delegateRole = account?.delegatedAccess?.delegates?.find((delegate) => delegate.email === delegateEmail)?.role;

return delegateRole === CONST.DELEGATE_ROLE.SUBMITTER;
}

export default {isValidateCodeFormSubmitting, isAccountIDOddNumber, isDelegateOnlySubmitter};
export default {isValidateCodeFormSubmitting, isDelegateOnlySubmitter};
8 changes: 6 additions & 2 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type {OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import type Beta from '@src/types/onyx/Beta';
import * as SessionUtils from './SessionUtils';

const isAccountIDEven = (accountID: number) => accountID % 2 === 0;

function canUseAllBetas(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.ALL);
Expand All @@ -26,9 +29,10 @@ function canUseCategoryAndTagApprovers(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.CATEGORY_AND_TAG_APPROVERS) || canUseAllBetas(betas);
}

function canUseCombinedTrackSubmit(betas: OnyxEntry<Beta[]>): boolean {
function canUseCombinedTrackSubmit(): boolean {
// We don't need to show this to all betas since this will be used for developing a feature for A/B testing.
return !!betas?.includes(CONST.BETAS.COMBINED_TRACK_SUBMIT);
const session = SessionUtils.getSession();
return isAccountIDEven(session?.accountID ?? -1);
}

function canUsePerDiem(betas: OnyxEntry<Beta[]>): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7321,7 +7321,7 @@ function canCreateRequest(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>,
}

const requestOptions = getMoneyRequestOptions(report, policy, participantAccountIDs);
if (Permissions.canUseCombinedTrackSubmit(allBetas ?? [])) {
if (Permissions.canUseCombinedTrackSubmit()) {
requestOptions.push(CONST.IOU.TYPE.CREATE);
}

Expand Down
9 changes: 1 addition & 8 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import INPUT_IDS from '@src/types/form/NewRoomForm';
import type {
Beta,
InvitedEmailsToAccountIDs,
NewGroupChatDraft,
PersonalDetailsList,
Expand Down Expand Up @@ -280,12 +279,6 @@ Onyx.connect({
callback: (value) => (allReportDraftComments = value),
});

let allBetas: OnyxEntry<Beta[]>;
Onyx.connect({
key: ONYXKEYS.BETAS,
callback: (value) => (allBetas = value),
});

let environmentURL: string;
Environment.getEnvironmentURL().then((url: string) => (environmentURL = url));

Expand Down Expand Up @@ -3431,7 +3424,7 @@ function completeOnboarding(
userReportedIntegration?: OnboardingAccountingType,
) {
// If the user has the "combinedTrackSubmit" beta enabled we'll show different tasks for track and submit expense.
if (Permissions.canUseCombinedTrackSubmit(allBetas)) {
if (Permissions.canUseCombinedTrackSubmit()) {
if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND) {
// eslint-disable-next-line no-param-reassign
data = CONST.COMBINED_TRACK_SUBMIT_ONBOARDING_MESSAGES[CONST.ONBOARDING_CHOICES.PERSONAL_SPEND];
Expand Down
Loading