Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8437251
The final part
hungvu193 Apr 17, 2026
ce7e85b
Merge remote-tracking branch 'origin/main' into fix-664420-part8
MelvinBot Apr 30, 2026
a954a76
merge main
hungvu193 May 12, 2026
9bc726e
remove Onyx connect
hungvu193 May 12, 2026
c5a7d70
linting
hungvu193 May 13, 2026
c636ac0
sync main
hungvu193 May 13, 2026
af93956
prettier
hungvu193 May 13, 2026
358d49d
Merge remote-tracking branch 'origin' into fix-664420-part8
hungvu193 May 13, 2026
b434de6
fix ts
hungvu193 May 13, 2026
1306929
fix test
hungvu193 May 13, 2026
feedd1f
more refactor
hungvu193 May 14, 2026
3658986
fix tests
hungvu193 May 14, 2026
5811b0f
merge main
hungvu193 May 14, 2026
6ad20e8
Fix lint after merging main
hungvu193 May 14, 2026
a224936
update lint
hungvu193 May 14, 2026
d1b810c
fix linting
hungvu193 May 15, 2026
d5a57fc
update submodule
hungvu193 May 15, 2026
fd07935
lint and prettier
hungvu193 May 15, 2026
46c5a24
eslint
hungvu193 May 15, 2026
317970e
Merge remote-tracking branch 'origin' into fix-664420-part8
hungvu193 May 15, 2026
dd43872
merge main
hungvu193 May 19, 2026
61975c4
Update submodule version
hungvu193 May 19, 2026
c4adf55
merge main
hungvu193 May 21, 2026
90d18f0
update the usages
hungvu193 May 21, 2026
7427a96
Merge remote-tracking branch 'origin' into fix-664420-part8
hungvu193 May 24, 2026
533162d
complete Part 8
hungvu193 May 24, 2026
7b2c118
fix ts
hungvu193 May 24, 2026
c03e894
update the tests accordingly
hungvu193 May 24, 2026
dd75237
merge main
hungvu193 May 28, 2026
d0404c7
fix ts
hungvu193 May 28, 2026
80bc540
revert submodule
hungvu193 May 28, 2026
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useEffect, useRef} from 'react';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDefaultExpensePolicy from '@hooks/useDefaultExpensePolicy';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -34,14 +35,22 @@ function useUpdateGpsNotificationOnLanguageChange() {

function useUpdateGpsNotificationOnUnitChange() {
const {translate} = useLocalize();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();

const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${CONST.IOU.OPTIMISTIC_TRANSACTION_ID}`);

const defaultExpensePolicy = useDefaultExpensePolicy();
const shouldUseDefaultExpensePolicy = shouldUseDefaultExpensePolicyUtil(CONST.IOU.TYPE.CREATE, defaultExpensePolicy, amountOwed, userBillingGracePeriodEnds, ownerBillingGracePeriodEnd);
const shouldUseDefaultExpensePolicy = shouldUseDefaultExpensePolicyUtil(
CONST.IOU.TYPE.CREATE,
defaultExpensePolicy,
amountOwed,
userBillingGracePeriodEnds,
ownerBillingGracePeriodEnd,
currentUserPersonalDetails.accountID,
);

const unit = DistanceRequestUtils.getRate({transaction, policy: shouldUseDefaultExpensePolicy ? defaultExpensePolicy : undefined}).unit;

Expand Down
2 changes: 1 addition & 1 deletion src/components/MoneyRequestHeaderSecondaryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money
icon: expensifyIcons.ArrowSplit,
value: CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.SPLIT,
onSelected: () => {
initSplitExpense(transaction, policy, report);
initSplitExpense(transaction, policy, report, accountID);
},
},
[CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.MERGE]: {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ function MoneyRequestView({
}

if (shouldShowSplitIndicator && isSplitAvailable) {
initSplitExpense(transaction, policy, transactionThreadReport);
initSplitExpense(transaction, policy, transactionThreadReport, currentUserAccountIDParam);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useDeleteTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function useDeleteTransactions({report, reportActions, policy}: UseDeleteTransac
const transactionReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${splitExpenseEditTransaction.reportID}`];
const selfDMReport = isSelfDM(report) ? report : allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`];
const splitExpenseEditTransactionReport = transactionReport ?? selfDMReport;
initSplitExpense(splitExpenseEditTransaction, policy, splitExpenseEditTransactionReport, {navigateToEditSplitExpense: true});
initSplitExpense(splitExpenseEditTransaction, policy, splitExpenseEditTransactionReport, currentUserPersonalDetails.accountID, {navigateToEditSplitExpense: true});
return {
action: 'redirected',
};
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/useExpenseActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
amountOwed,
ownerBillingGracePeriodEnd,
lastDistanceExpenseType,
currentUserAccountID: accountID,
});

const expensifyIcons = useMemoizedLazyExpensifyIcons([
Expand Down Expand Up @@ -297,7 +298,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
if (transactions.length !== 1) {
return;
}
initSplitExpense(currentTransaction, policy, moneyRequestReport);
initSplitExpense(currentTransaction, policy, moneyRequestReport, accountID);
},
},
[CONST.REPORT.SECONDARY_ACTIONS.MERGE]: {
Expand All @@ -318,7 +319,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
iconFill: isDuplicateActive ? undefined : theme.icon,
value: CONST.REPORT.SECONDARY_ACTIONS.DUPLICATE_EXPENSE,
onSelected: () => {
if (defaultExpensePolicy && shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (defaultExpensePolicy && shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
onDuplicateReset?.();
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(defaultExpensePolicy.id));
return;
Expand Down Expand Up @@ -379,7 +380,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
const isSourcePolicyValid = !!policy && isPolicyAccessible(policy, currentUserLogin ?? '');
const targetPolicyForDuplicate = isSourcePolicyValid ? policy : defaultExpensePolicy;

if (targetPolicyForDuplicate && shouldRestrictUserBillableActions(targetPolicyForDuplicate, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (targetPolicyForDuplicate && shouldRestrictUserBillableActions(targetPolicyForDuplicate, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
onDuplicateReset?.();
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(targetPolicyForDuplicate.id));
return;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useParticipantSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function useParticipantSubmission({
iouType === CONST.IOU.TYPE.CREATE &&
isPaidGroupPolicy(activePolicy) &&
activePolicy?.isPolicyExpenseChatEnabled &&
!shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed);
!shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserPersonalDetails.accountID);

const dataRef = useRef({
allPolicies,
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
value: CONST.SEARCH.BULK_ACTION_TYPES.DUPLICATE,
shouldCloseModalOnSelect: true,
onSelected: () => {
if (defaultExpensePolicy && shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (defaultExpensePolicy && shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(defaultExpensePolicy.id));
return;
}
Expand Down Expand Up @@ -1573,7 +1573,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
icon: expensifyIcons.ArrowSplit,
value: CONST.SEARCH.BULK_ACTION_TYPES.SPLIT,
onSelected: () => {
initSplitExpense(firstTransaction, firstTransactionPolicy, firstTransactionReport);
initSplitExpense(firstTransaction, firstTransactionPolicy, firstTransactionReport, accountID);
},
});
}
Expand All @@ -1586,7 +1586,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
value: CONST.SEARCH.BULK_ACTION_TYPES.DUPLICATE,
shouldCloseModalOnSelect: true,
onSelected: () => {
if (defaultExpensePolicy && shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (defaultExpensePolicy && shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(defaultExpensePolicy.id));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSelectedTransactionsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ function useSelectedTransactionsActions({
icon: expensifyIcons.ArrowSplit,
value: SPLIT,
onSelected: () => {
initSplitExpense(firstTransaction, policy, report);
initSplitExpense(firstTransaction, policy, report, currentUserAccountID);
},
});
}
Expand Down
14 changes: 10 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2948,6 +2948,7 @@ type GetAddExpenseDropdownOptionsParams = {
iouRequestBackToReport?: string;
unreportedExpenseBackToReport?: string;
lastDistanceExpenseType?: IOURequestType;
currentUserAccountID?: number;
};

function getAddExpenseDropdownOptions({
Expand All @@ -2962,6 +2963,7 @@ function getAddExpenseDropdownOptions({
iouRequestBackToReport,
unreportedExpenseBackToReport,
lastDistanceExpenseType,
currentUserAccountID,
}: GetAddExpenseDropdownOptionsParams): Array<DropdownOption<ValueOf<typeof CONST.REPORT.ADD_EXPENSE_OPTIONS>>> {
return [
{
Expand All @@ -2973,7 +2975,11 @@ function getAddExpenseDropdownOptions({
if (!iouReportID) {
return;
}
if (policy && policy.type !== CONST.POLICY.TYPE.PERSONAL && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (
policy &&
policy.type !== CONST.POLICY.TYPE.PERSONAL &&
shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -2989,7 +2995,7 @@ function getAddExpenseDropdownOptions({
if (!iouReportID) {
return;
}
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand All @@ -3002,7 +3008,7 @@ function getAddExpenseDropdownOptions({
icon: icons.ReceiptPlus,
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.ADD_EXPENSE_EXISTING,
onSelected: () => {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down Expand Up @@ -11402,7 +11408,7 @@ function createDraftTransactionAndNavigateToParticipantSelector({
}

if (actionName === CONST.IOU.ACTION.CATEGORIZE) {
if (activePolicy && shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (activePolicy && shouldRestrictUserBillableActions(activePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(activePolicy.id));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/SubscriptionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {differenceInSeconds, fromUnixTime, isAfter, isBefore} from 'date-fns';
import {fromZonedTime} from 'date-fns-tz';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import type {PreferredCurrency} from '@hooks/usePreferredCurrency';
Expand Down Expand Up @@ -481,7 +481,7 @@ function shouldRestrictUserBillableActions(
ownerBillingGracePeriodEnd: OnyxEntry<number>,
userBillingGracePeriodEnds: OnyxCollection<BillingGraceEndPeriod>,
amountOwed: OnyxEntry<number>,
currentUserAccountID: number = deprecatedCurrentUserAccountID,
currentUserAccountID: number | undefined = deprecatedCurrentUserAccountID,
): boolean {
const currentDate = new Date();

Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/IOU/MoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ function handleMoneyRequestStepScanParticipants({

// If there was no reportID, then that means the user started this flow from the global + menu
// and an optimistic reportID was generated. In that case, the next step is to select the participants for this expense.
if (shouldUseDefaultExpensePolicy(iouType, defaultExpensePolicy, amountOwed, userBillingGracePeriodEnds, ownerBillingGracePeriodEnd)) {
if (shouldUseDefaultExpensePolicy(iouType, defaultExpensePolicy, amountOwed, userBillingGracePeriodEnds, ownerBillingGracePeriodEnd, currentUserAccountID)) {
const shouldAutoReport = !!defaultExpensePolicy?.autoReporting || isAutoReporting;
const targetReport = shouldAutoReport ? getPolicyExpenseChat(currentUserAccountID, defaultExpensePolicy?.id) : selfDMReport;
const transactionReportID = isSelfDM(targetReport) ? CONST.REPORT.UNREPORTED_REPORT_ID : targetReport?.reportID;
Expand Down Expand Up @@ -789,7 +789,7 @@ function handleMoneyRequestStepDistanceNavigation({

// If there was no reportID, then that means the user started this flow from the global menu
// and an optimistic reportID was generated. In that case, the next step is to select the participants for this expense.
if (defaultExpensePolicy && shouldUseDefaultExpensePolicy(iouType, defaultExpensePolicy, amountOwed, userBillingGracePeriodEnds, ownerBillingGracePeriodEnd)) {
if (defaultExpensePolicy && shouldUseDefaultExpensePolicy(iouType, defaultExpensePolicy, amountOwed, userBillingGracePeriodEnds, ownerBillingGracePeriodEnd, currentUserAccountID)) {
const shouldAutoReport = !!defaultExpensePolicy?.autoReporting || isAutoReporting;
const targetReport = shouldAutoReport ? getPolicyExpenseChat(currentUserAccountID, defaultExpensePolicy?.id) : selfDMReport;
const isSelfDMReport = isSelfDM(targetReport);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/PayMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ function payMoneyRequest(params: PayMoneyRequestFunctionParams) {
if (
chatReport.policyID &&
policyForBillingRestriction &&
shouldRestrictUserBillableActions(policyForBillingRestriction, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)
shouldRestrictUserBillableActions(policyForBillingRestriction, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(chatReport.policyID));
return;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/SplitExpenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ function initSplitExpense(
transaction: OnyxEntry<Transaction>,
policy: OnyxEntry<Policy>,
report: OnyxEntry<Report>,
currentUserAccountID: number | undefined,
{navigateToEditSplitExpense = false}: {navigateToEditSplitExpense?: boolean} = {},
): void {
if (!transaction) {
return;
}

if (!!policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)) {
if (!!policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/libs/shouldUseDefaultExpensePolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ function shouldUseDefaultExpensePolicy(
amountOwed: OnyxEntry<number>,
userBillingGracePeriodEnds: OnyxCollection<BillingGraceEndPeriod>,
ownerBillingGracePeriodEnd: OnyxEntry<number>,
currentUserAccountID?: number,
) {
return (
iouType === CONST.IOU.TYPE.CREATE &&
isPaidGroupPolicy(defaultExpensePolicy) &&
defaultExpensePolicy?.isPolicyExpenseChatEnabled &&
!shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed)
!shouldRestrictUserBillableActions(defaultExpensePolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentUserAccountID)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {OnyxEntry} from 'react-native-onyx';
import useOnyx from '@hooks/useOnyx';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Session} from '@src/types/onyx';

Expand All @@ -17,7 +18,7 @@ function useCreateReportRestrictionCheck(session: OnyxEntry<Session>): (restrict
if (!restrictionPolicy) {
return false;
}
return shouldRestrictUserBillableActions(restrictionPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, session?.accountID);
return shouldRestrictUserBillableActions(restrictionPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, session?.accountID ?? CONST.DEFAULT_NUMBER_ID);
};
}

Expand Down
Loading
Loading