Skip to content
Draft
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
12 changes: 12 additions & 0 deletions src/components/MoneyRequestHeaderSecondaryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
navigateToDetailsPage,
rejectMoneyRequestReason,
} from '@libs/ReportUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {
getOriginalTransactionWithSplitInfo,
hasCustomUnitOutOfPolicyViolation as hasCustomUnitOutOfPolicyViolationTransactionUtils,
Expand Down Expand Up @@ -138,6 +139,9 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money
const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS);
const [shouldFailAllRequests] = useOnyx(ONYXKEYS.NETWORK, {selector: shouldFailAllRequestsSelector});
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [betas] = useOnyx(ONYXKEYS.BETAS);

Expand Down Expand Up @@ -350,6 +354,14 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money
iconFill: isDuplicateActive ? undefined : theme.icon,
value: CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.DUPLICATE,
onSelected: () => {
if (
defaultExpensePolicy &&
shouldRestrictUserBillableActions(defaultExpensePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultExpensePolicy)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(defaultExpensePolicy.id));
return;
}

if (hasCustomUnitOutOfPolicyViolation) {
showConfirmModal({
title: translate('common.duplicateExpense'),
Expand Down
21 changes: 19 additions & 2 deletions src/hooks/useExpenseActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
iconFill: isDuplicateActive ? undefined : theme.icon,
value: CONST.REPORT.SECONDARY_ACTIONS.DUPLICATE_EXPENSE,
onSelected: () => {
if (
defaultExpensePolicy &&
shouldRestrictUserBillableActions(defaultExpensePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultExpensePolicy)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(defaultExpensePolicy.id));
return;
}

if (hasCustomUnitOutOfPolicyViolation) {
showConfirmModal({
title: translate('common.duplicateExpense'),
Expand Down Expand Up @@ -369,11 +377,20 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
return;
}

const isSourcePolicyValid = !!policy && isPolicyAccessible(policy, currentUserLogin ?? '');
const targetPolicyForDuplicate = isSourcePolicyValid ? policy : defaultExpensePolicy;

if (
targetPolicyForDuplicate &&
shouldRestrictUserBillableActions(targetPolicyForDuplicate.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, targetPolicyForDuplicate)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(targetPolicyForDuplicate.id));
return;
}

temporarilyDisableDuplicateReportAction();
wasDuplicateReportTriggeredRef.current = true;

const isSourcePolicyValid = !!policy && isPolicyAccessible(policy, currentUserLogin ?? '');
const targetPolicyForDuplicate = isSourcePolicyValid ? policy : defaultExpensePolicy;
const targetChatForDuplicate = isSourcePolicyValid ? chatReport : activePolicyExpenseChat;
const activePolicyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${targetPolicyForDuplicate?.id}`] ?? {};

Expand Down
19 changes: 18 additions & 1 deletion src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,16 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
icon: expensifyIcons.ExpenseCopy,
value: CONST.SEARCH.BULK_ACTION_TYPES.DUPLICATE,
shouldCloseModalOnSelect: true,
onSelected: invokeDuplicateHandler,
onSelected: () => {
if (
defaultExpensePolicy &&
shouldRestrictUserBillableActions(defaultExpensePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultExpensePolicy)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(defaultExpensePolicy.id));
return;
}
invokeDuplicateHandler();
},
});
}

Expand Down Expand Up @@ -1368,6 +1377,13 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
value: CONST.SEARCH.BULK_ACTION_TYPES.DUPLICATE,
shouldCloseModalOnSelect: true,
onSelected: () => {
if (
defaultExpensePolicy &&
shouldRestrictUserBillableActions(defaultExpensePolicy.id, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, defaultExpensePolicy)
) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(defaultExpensePolicy.id));
return;
}
if (exceedsBulkDuplicateLimit) {
showConfirmModal({
title: translate('common.duplicateExpense'),
Expand Down Expand Up @@ -1477,6 +1493,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
allTransactions,
isBetaEnabled,
shouldShowBusinessBankAccountOptions,
defaultExpensePolicy,
]);

const handleOfflineModalClose = useCallback(() => {
Expand Down
Loading