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
2 changes: 2 additions & 0 deletions src/components/AddUnreportedExpenseFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function AddUnreportedExpenseFooter({selectedIds, report, reportToConfirm, repor
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES, {canBeMissing: true});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});

const handleConfirm = () => {
if (selectedIds.size === 0) {
Expand All @@ -66,6 +67,7 @@ function AddUnreportedExpenseFooter({selectedIds, report, reportToConfirm, repor
policyRecentlyUsedCurrencies ?? [],
quickAction,
personalDetails,
betas,
);
} else {
changeTransactionsReport({
Expand Down
10 changes: 8 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ function MoneyReportHeader({
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES, {canBeMissing: true});
const shouldShowLoadingBar = useLoadingBarVisibility();
const kycWallRef = useContext(KYCWallContext);

const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const isReportInRHP = route.name !== SCREENS.REPORT;
const shouldDisplaySearchRouter = !isReportInRHP || isSmallScreenWidth;
const isReportInSearch = route.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT || route.name === SCREENS.RIGHT_MODAL.SEARCH_MONEY_REQUEST_REPORT;
Expand Down Expand Up @@ -583,6 +583,7 @@ function MoneyReportHeader({
methodID,
paymentMethod,
activePolicy,
betas,
});
} else {
startAnimation();
Expand All @@ -595,6 +596,7 @@ function MoneyReportHeader({
currentUserAccountID: accountID,
activePolicy,
policy,
betas,
});
if (currentSearchQueryJSON && !isOffline) {
search({
Expand Down Expand Up @@ -628,6 +630,7 @@ function MoneyReportHeader({
currentSearchKey,
shouldCalculateTotals,
currentSearchResults?.search?.isLoading,
betas,
],
);

Expand Down Expand Up @@ -656,7 +659,7 @@ function MoneyReportHeader({
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, true);
approveMoneyRequest(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, betas, true);
}
};

Expand Down Expand Up @@ -697,6 +700,7 @@ function MoneyReportHeader({
targetPolicy: defaultExpensePolicy ?? undefined,
targetPolicyCategories: activePolicyCategories,
targetReport: activePolicyExpenseChat,
betas,
personalDetails,
});
}
Expand All @@ -712,6 +716,7 @@ function MoneyReportHeader({
policyRecentlyUsedCurrencies,
policy?.id,
isSelfTourViewed,
betas,
personalDetails,
],
);
Expand Down Expand Up @@ -1738,6 +1743,7 @@ function MoneyReportHeader({
confirmApproval,
iouReport: moneyRequestReport,
iouReportNextStep: nextStep,
betas,
});

const showNextStepBar = shouldShowNextStep && !!optimisticNextStep?.message?.length;
Expand Down
4 changes: 3 additions & 1 deletion src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
const [network] = useOnyx(ONYXKEYS.NETWORK, {canBeMissing: true});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {canBeMissing: true, selector: hasSeenTourSelector});

const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const markAsCash = useCallback(() => {
markAsCashAction(transaction?.transactionID, reportID, transactionViolations);
}, [reportID, transaction?.transactionID, transactionViolations]);
Expand Down Expand Up @@ -208,6 +208,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
targetPolicy: defaultExpensePolicy ?? undefined,
targetPolicyCategories: activePolicyCategories,
targetReport: activePolicyExpenseChat,
betas,
personalDetails,
});
}
Expand All @@ -223,6 +224,7 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
policyRecentlyUsedCurrencies,
policy?.id,
isSelfTourViewed,
betas,
personalDetails,
],
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/ProcessMoneyReportHoldMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function ProcessMoneyReportHoldMenu({
const activePolicy = usePolicy(activePolicyID);
const policy = usePolicy(moneyRequestReport?.policyID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const [moneyRequestReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`, {canBeMissing: true});
const {isBetaEnabled} = usePermissions();
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
Expand All @@ -101,6 +102,7 @@ function ProcessMoneyReportHoldMenu({
hasViolations,
isASAPSubmitBetaEnabled,
moneyRequestReportNextStep,
betas,
full,
);
} else if (chatReport && paymentType) {
Expand All @@ -117,6 +119,7 @@ function ProcessMoneyReportHoldMenu({
full,
activePolicy,
policy,
betas,
});
}
onClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function MoneyRequestReportPreviewContent({
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const isDEWBetaEnabled = isBetaEnabled(CONST.BETAS.NEW_DOT_DEW);
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations, currentUserAccountID, currentUserEmail);

Expand Down Expand Up @@ -267,6 +268,7 @@ function MoneyRequestReportPreviewContent({
methodID,
paymentMethod,
activePolicy,
betas,
});
} else {
payMoneyRequest({
Expand All @@ -278,6 +280,7 @@ function MoneyRequestReportPreviewContent({
currentUserAccountID,
activePolicy,
policy,
betas,
});
}
}
Expand All @@ -295,6 +298,7 @@ function MoneyRequestReportPreviewContent({
existingB2BInvoiceReport,
activePolicy,
policy,
betas,
],
);

Expand All @@ -310,7 +314,7 @@ function MoneyRequestReportPreviewContent({
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest(iouReport, activePolicy, currentUserAccountID, currentUserEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, true);
approveMoneyRequest(iouReport, activePolicy, currentUserAccountID, currentUserEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, betas, true);
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function SettlementButton({
const paymentMethods = useSettlementButtonPaymentMethods(hasActivatedWallet, translate);
const [lastPaymentMethods, lastPaymentMethodResult] = useOnyx(ONYXKEYS.NVP_LAST_PAYMENT_METHOD, {canBeMissing: true});
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});

const lastPaymentMethod = useMemo(() => {
if (!iouReport?.type) {
Expand Down Expand Up @@ -451,7 +452,7 @@ function SettlementButton({
if (confirmApproval) {
confirmApproval();
} else {
approveMoneyRequest(iouReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, false);
approveMoneyRequest(iouReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, betas, false);
}
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useDeleteTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES, {canBeMissing: true});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, {canBeMissing: true});
const [iouReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${getNonEmptyStringOnyxID(report?.reportID)}`, {canBeMissing: true});

const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const {isBetaEnabled} = usePermissions();
const archivedReportsIdSet = useArchivedReportsIdSet();

Expand Down Expand Up @@ -152,6 +152,7 @@
policyRecentlyUsedCurrencies: policyRecentlyUsedCurrencies ?? [],
quickAction,
iouReportNextStep,
betas,
});
}

Expand Down Expand Up @@ -187,7 +188,7 @@

return Array.from(deletedTransactionThreadReportIDs);
},
[

Check warning on line 191 in src/hooks/useDeleteTransactions.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a missing dependency: 'betas'. Either include it or remove the dependency array

Check warning on line 191 in src/hooks/useDeleteTransactions.ts

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has a missing dependency: 'betas'. Either include it or remove the dependency array
allPolicyRecentlyUsedCategories,
allReportNameValuePairs,
allReports,
Expand Down
6 changes: 4 additions & 2 deletions src/libs/PaymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {BankAccountMenuItem} from '@components/Search/types';
import type {ThemeStyles} from '@styles/index';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {Policy, Report, ReportNextStepDeprecated} from '@src/types/onyx';
import type {Beta, Policy, Report, ReportNextStepDeprecated} from '@src/types/onyx';
import type BankAccount from '@src/types/onyx/BankAccount';
import type Fund from '@src/types/onyx/Fund';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
Expand Down Expand Up @@ -41,6 +41,7 @@ type SelectPaymentTypeParams = {
confirmApproval?: () => void;
iouReport?: OnyxEntry<Report>;
iouReportNextStep: OnyxEntry<ReportNextStepDeprecated>;
betas: OnyxEntry<Beta[]>;
};

/**
Expand Down Expand Up @@ -176,6 +177,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
confirmApproval,
iouReport,
iouReportNextStep,
betas,
} = params;
if (policy && shouldRestrictUserBillableActions(policy.id)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
Expand All @@ -195,7 +197,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
if (confirmApproval) {
confirmApproval();
} else {
approveMoneyRequest(iouReport, policy, currentAccountID, currentEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, true);
approveMoneyRequest(iouReport, policy, currentAccountID, currentEmail, hasViolations, isASAPSubmitBetaEnabled, iouReportNextStep, betas, true);
}
return;
}
Expand Down
67 changes: 45 additions & 22 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,20 @@ type GetReportStatusParams = {
translate: LocaleContextProps['translate'];
};

type BuildOptimisticExpenseReportParams = {
chatReportID: string | undefined;
policyID: string | undefined;
payeeAccountID: number;
total: number;
currency: string;
betas: OnyxEntry<Beta[]>;
nonReimbursableTotal?: number;
parentReportActionID?: string;
optimisticIOUReportID?: string;
reportTransactions?: Record<string, Transaction>;
createdTimestamp?: string;
};

type ReportByPolicyMap = Record<string, OnyxCollection<Report>>;

let currentUserEmail: string | undefined;
Expand All @@ -1009,6 +1023,12 @@ getEnvironment().then((env) => {
environment = env;
});

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

// This cache is used to save parse result of report action html message into text
// to prevent unnecessary parsing when the report action is not changed/modified.
// Example case: when we need to get a report name of a thread which is dependent on a report action message.
Expand Down Expand Up @@ -1110,12 +1130,6 @@ Onyx.connectWithoutView({
},
});

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

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connectWithoutView({
key: ONYXKEYS.BETA_CONFIGURATION,
Expand Down Expand Up @@ -6846,8 +6860,8 @@ function buildOptimisticInvoiceReport(
* Returns the stateNum and statusNum for an expense report based on the policy settings
* @param policy
*/
function getExpenseReportStateAndStatus(policy: OnyxEntry<Policy>, isEmptyOptimisticReport = false) {
const isASAPSubmitBetaEnabled = Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, allBetas);
function getExpenseReportStateAndStatus(policy: OnyxEntry<Policy>, betas: OnyxEntry<Beta[]>, isEmptyOptimisticReport = false) {
const isASAPSubmitBetaEnabled = Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, betas);
if (isASAPSubmitBetaEnabled) {
return {
stateNum: CONST.REPORT.STATE_NUM.OPEN,
Expand Down Expand Up @@ -6890,18 +6904,19 @@ function getExpenseReportStateAndStatus(policy: OnyxEntry<Policy>, isEmptyOptimi
* @param parentReportActionID – The parent ReportActionID of the PolicyExpenseChat
* @param optimisticIOUReportID – Optimistic IOU report id
*/
function buildOptimisticExpenseReport(
chatReportID: string | undefined,
policyID: string | undefined,
payeeAccountID: number,
total: number,
currency: string,
function buildOptimisticExpenseReport({
chatReportID,
policyID,
payeeAccountID,
total,
currency,
betas,
nonReimbursableTotal = 0,
parentReportActionID?: string,
optimisticIOUReportID?: string,
reportTransactions?: Record<string, Transaction>,
createdTimestamp?: string,
): OptimisticExpenseReport {
parentReportActionID,
optimisticIOUReportID,
reportTransactions,
createdTimestamp,
}: BuildOptimisticExpenseReportParams): OptimisticExpenseReport {
// The amount for Expense reports are stored as negative value in the database
const storedTotal = total * -1;
const storedNonReimbursableTotal = nonReimbursableTotal * -1;
Expand All @@ -6914,7 +6929,7 @@ function buildOptimisticExpenseReport(
const policyDraft = allPolicyDrafts?.[`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyID}`];
const policy = policyReal ?? policyDraft;

const {stateNum, statusNum} = getExpenseReportStateAndStatus(policy);
const {stateNum, statusNum} = getExpenseReportStateAndStatus(policy, betas);

const created = createdTimestamp ?? DateUtils.getDBTime();

Expand Down Expand Up @@ -6973,8 +6988,16 @@ function buildOptimisticExpenseReport(
return expenseReport;
}

function buildOptimisticEmptyReport(reportID: string, accountID: number, parentReport: OnyxEntry<Report>, parentReportActionID: string, policy: OnyxEntry<Policy>, timeOfCreation: string) {
const {stateNum, statusNum} = getExpenseReportStateAndStatus(policy, true);
function buildOptimisticEmptyReport(
reportID: string,
accountID: number,
parentReport: OnyxEntry<Report>,
parentReportActionID: string,
policy: OnyxEntry<Policy>,
timeOfCreation: string,
betas: OnyxEntry<Beta[]>,
) {
const {stateNum, statusNum} = getExpenseReportStateAndStatus(policy, betas, true);
const titleReportField = getTitleReportField(getReportFieldsByPolicyID(policy?.id) ?? {});
const optimisticEmptyReport: OptimisticNewReport = {
reportName: '',
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/IOU/Duplicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ type DuplicateExpenseTransactionParams = {
targetPolicy?: OnyxEntry<OnyxTypes.Policy>;
targetPolicyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>;
targetReport?: OnyxTypes.Report;
betas: OnyxEntry<OnyxTypes.Beta[]>;
personalDetails: OnyxEntry<OnyxTypes.PersonalDetailsList>;
};

Expand All @@ -492,6 +493,7 @@ function duplicateExpenseTransaction({
targetPolicy,
targetPolicyCategories,
targetReport,
betas,
personalDetails,
}: DuplicateExpenseTransactionParams) {
if (!transaction) {
Expand Down Expand Up @@ -546,6 +548,7 @@ function duplicateExpenseTransaction({
policyRecentlyUsedCurrencies,
quickAction,
isSelfTourViewed,
betas,
personalDetails,
};

Expand All @@ -567,6 +570,7 @@ function duplicateExpenseTransaction({
activePolicyID,
quickAction,
recentWaypoints,
betas,
};
return trackExpense(trackExpenseParams);
}
Expand Down
Loading
Loading