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
33 changes: 23 additions & 10 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import useOnyx from '@hooks/useOnyx';
import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import usePaymentOptions from '@hooks/usePaymentOptions';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand All @@ -43,7 +44,6 @@ import type {ReportsSplitNavigatorParamList, SearchFullscreenNavigatorParamList,
import {buildOptimisticNextStepForPreventSelfApprovalsEnabled, buildOptimisticNextStepForStrictPolicyRuleViolations} from '@libs/NextStepUtils';
import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
import {selectPaymentType} from '@libs/PaymentUtils';
import Permissions from '@libs/Permissions';
import {getConnectedIntegration, getValidConnectedIntegration, hasDynamicExternalWorkflow} from '@libs/PolicyUtils';
import {getIOUActionForReportID, getOriginalMessage, getReportAction, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {getAllExpensesToHoldIfApplicable, getReportPrimaryAction, isMarkAsResolvedAction} from '@libs/ReportPrimaryActionUtils';
Expand Down Expand Up @@ -261,9 +261,9 @@ function MoneyReportHeader({
const [isExportWithTemplateModalVisible, setIsExportWithTemplateModalVisible] = useState(false);
const [isDEWModalVisible, setIsDEWModalVisible] = useState(false);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const [allBetas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const isASAPSubmitBetaEnabled = Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, allBetas);
const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, allTransactionViolations);

const [exportModalStatus, setExportModalStatus] = useState<ExportType | null>(null);
Expand Down Expand Up @@ -481,7 +481,7 @@ function MoneyReportHeader({
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest(moneyRequestReport, true);
approveMoneyRequest(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, true);
if (currentSearchQueryJSON) {
search({
searchKey: currentSearchKey,
Expand Down Expand Up @@ -953,7 +953,7 @@ function MoneyReportHeader({
return;
}

unapproveExpenseReport(moneyRequestReport);
unapproveExpenseReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled);
},
},
[CONST.REPORT.SECONDARY_ACTIONS.CANCEL_PAYMENT]: {
Expand Down Expand Up @@ -1060,7 +1060,7 @@ function MoneyReportHeader({
icon: Expensicons.CircularArrowBackwards,
value: CONST.REPORT.SECONDARY_ACTIONS.RETRACT,
onSelected: () => {
retractReport(moneyRequestReport, chatReport);
retractReport(moneyRequestReport, chatReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled);
},
},
[CONST.REPORT.SECONDARY_ACTIONS.REOPEN]: {
Expand All @@ -1072,7 +1072,7 @@ function MoneyReportHeader({
setIsReopenWarningModalVisible(true);
return;
}
reopenReport(moneyRequestReport);
reopenReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled);
},
},
[CONST.REPORT.SECONDARY_ACTIONS.REJECT]: {
Expand Down Expand Up @@ -1175,7 +1175,20 @@ function MoneyReportHeader({
</Text>
);
const onPaymentSelect = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) =>
selectPaymentType(event, iouPaymentType, triggerKYCFlow, policy, confirmPayment, isUserValidated, confirmApproval, moneyRequestReport);
selectPaymentType({
event,
iouPaymentType,
triggerKYCFlow,
policy,
onPress: confirmPayment,
currentAccountID: accountID,
currentEmail: email ?? '',
hasViolations,
isASAPSubmitBetaEnabled,
isUserValidated,
confirmApproval,
iouReport: moneyRequestReport,
});

const showNextStepBar = shouldShowNextStep && !!optimisticNextStep?.message?.length;
const showNextStepSkeleton = shouldShowNextStep && !optimisticNextStep && !!isLoadingInitialReportActions && !isOffline;
Expand Down Expand Up @@ -1403,7 +1416,7 @@ function MoneyReportHeader({
confirmText={translate('iou.unapproveReport')}
onConfirm={() => {
setIsUnapproveModalVisible(false);
unapproveExpenseReport(moneyRequestReport);
unapproveExpenseReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled);
}}
cancelText={translate('common.cancel')}
onCancel={() => setIsUnapproveModalVisible(false)}
Expand All @@ -1416,7 +1429,7 @@ function MoneyReportHeader({
confirmText={translate('iou.reopenReport')}
onConfirm={() => {
setIsReopenWarningModalVisible(false);
reopenReport(moneyRequestReport);
reopenReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled);
}}
cancelText={translate('common.cancel')}
onCancel={() => setIsReopenWarningModalVisible(false)}
Expand Down
10 changes: 9 additions & 1 deletion src/components/ProcessMoneyReportHoldMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React, {useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import {hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
import {approveMoneyRequest, payMoneyRequest} from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -66,13 +69,18 @@ function ProcessMoneyReportHoldMenu({
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
const activePolicy = usePolicy(activePolicyID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const {isBetaEnabled} = usePermissions();
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, transactionViolations);
const currentUserDetails = useCurrentUserPersonalDetails();

const onSubmit = (full: boolean) => {
if (isApprove) {
if (startAnimation) {
startAnimation();
}
approveMoneyRequest(moneyRequestReport, full);
approveMoneyRequest(moneyRequestReport, activePolicy, currentUserDetails.accountID, currentUserDetails.email ?? '', hasViolations, isASAPSubmitBetaEnabled, full);
} else if (chatReport && paymentType) {
if (startAnimation) {
startAnimation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePaymentAnimations from '@hooks/usePaymentAnimations';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand All @@ -41,7 +42,6 @@ import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
import Navigation from '@libs/Navigation/Navigation';
import Performance from '@libs/Performance';
import Permissions from '@libs/Permissions';
import {getConnectedIntegration, hasDynamicExternalWorkflow} from '@libs/PolicyUtils';
import {getReportPreviewAction} from '@libs/ReportPreviewActionUtils';
import {
Expand Down Expand Up @@ -162,9 +162,9 @@ function MoneyRequestReportPreviewContent({
const isIouReportArchived = useReportIsArchived(iouReportID);
const isChatReportArchived = useReportIsArchived(chatReport?.reportID);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
const [allBetas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const {isBetaEnabled} = usePermissions();
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const isASAPSubmitBetaEnabled = Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, allBetas);
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations);

const getCanIOUBePaid = useCallback(
Expand Down Expand Up @@ -267,7 +267,7 @@ function MoneyRequestReportPreviewContent({
setIsHoldMenuVisible(true);
} else {
startApprovedAnimation();
approveMoneyRequest(iouReport, true);
approveMoneyRequest(iouReport, activePolicy, currentUserDetails.accountID, currentUserDetails.email ?? '', hasViolations, isASAPSubmitBetaEnabled, true);
}
};

Expand Down
10 changes: 8 additions & 2 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import {isCurrencySupportedForDirectReimbursement} from '@libs/actions/Policy/Policy';
Expand All @@ -26,6 +27,7 @@ import {hasRequestFromCurrentAccount} from '@libs/ReportActionsUtils';
import {
doesReportBelongToWorkspace,
getBankAccountRoute,
hasViolations as hasViolationsReportUtils,
isExpenseReport as isExpenseReportUtil,
isIndividualInvoiceRoom as isIndividualInvoiceRoomUtil,
isInvoiceReport as isInvoiceReportUtil,
Expand Down Expand Up @@ -90,7 +92,7 @@ function SettlementButton({
const {translate, localeCompare} = useLocalize();
const {isOffline} = useNetwork();
const policy = usePolicy(policyID);
const {accountID} = useCurrentUserPersonalDetails();
const {accountID, email} = useCurrentUserPersonalDetails();

// The app would crash due to subscribing to the entire report collection if chatReportID is an empty string. So we should have a fallback ID here.
// eslint-disable-next-line rulesdir/no-default-id-values
Expand Down Expand Up @@ -131,6 +133,10 @@ function SettlementButton({
const lastPaymentMethodRef = useRef(lastPaymentMethod);
const formattedPaymentMethods = formatPaymentMethods(bankAccountList ?? {}, fundList ?? {}, styles);
const hasIntentToPay = ((formattedPaymentMethods.length === 1 && isIOUReport(iouReport)) || !!policy?.achAccount) && !lastPaymentMethod;
const {isBetaEnabled} = usePermissions();
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const hasViolations = hasViolationsReportUtils(iouReport?.reportID, transactionViolations);

useEffect(() => {
if (isLoadingLastPaymentMethod) {
Expand Down Expand Up @@ -366,7 +372,7 @@ function SettlementButton({
if (confirmApproval) {
confirmApproval();
} else {
approveMoneyRequest(iouReport);
approveMoneyRequest(iouReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, false);
}
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useSearchTypeMenuSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {createPoliciesSelector} from '@selectors/Policy';
import {useMemo} from 'react';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import memoize from '@libs/memoize';
import Permissions from '@libs/Permissions';
import {hasViolations as hasViolationsReportUtils} from '@libs/ReportUtils';
import {createTypeMenuSections} from '@libs/SearchUIUtils';
import CONST from '@src/CONST';
Expand All @@ -11,6 +10,7 @@ import type {Policy, Session} from '@src/types/onyx';
import useCardFeedsForDisplay from './useCardFeedsForDisplay';
import useNetwork from './useNetwork';
import useOnyx from './useOnyx';
import usePermissions from './usePermissions';

const policySelector = (policy: OnyxEntry<Policy>): OnyxEntry<Policy> =>
policy && {
Expand Down Expand Up @@ -56,8 +56,8 @@ const useSearchTypeMenuSections = () => {
const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true});
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const [allBetas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
const isASAPSubmitBetaEnabled = Permissions.isBetaEnabled(CONST.BETAS.ASAP_SUBMIT, allBetas);
const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const hasViolations = hasViolationsReportUtils(undefined, transactionViolations);

const typeMenuSections = useMemo(
Expand Down
12 changes: 6 additions & 6 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

type BuildNextStepNewParams = {
report: OnyxEntry<Report>;
policy: OnyxEntry<Policy>;
currentUserAccountIDParam: number;
currentUserEmailParam: string;
hasViolations: boolean;
isASAPSubmitBetaEnabled: boolean;
policy?: OnyxEntry<Policy>;
currentUserAccountIDParam?: number;
currentUserEmailParam?: string;
hasViolations?: boolean;
isASAPSubmitBetaEnabled?: boolean;
predictedNextStatus: ValueOf<typeof CONST.REPORT.STATUS_NUM>;
shouldFixViolations?: boolean;
isUnapprove?: boolean;
Expand All @@ -38,7 +38,7 @@

let currentUserAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 41 in src/libs/NextStepUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
if (!value) {
Expand Down Expand Up @@ -547,7 +547,7 @@
const shouldShowFixMessage = hasViolations && isInstantSubmitEnabled && !isASAPSubmitBetaEnabled;
const [policyOwnerPersonalDetails, ownerPersonalDetails] = getPersonalDetailsByIDs({
accountIDs: [policy?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID, ownerAccountID],
currentUserAccountID: currentUserAccountIDParam,
currentUserAccountID: currentUserAccountIDParam ?? CONST.DEFAULT_NUMBER_ID,
shouldChangeUserDisplayName: true,
});
const isReportContainingTransactions =
Expand Down
32 changes: 20 additions & 12 deletions src/libs/PaymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ type KYCFlowEvent = GestureResponderEvent | KeyboardEvent | undefined;
type TriggerKYCFlow = (params: ContinueActionParams) => void;
type AccountType = ValueOf<typeof CONST.PAYMENT_METHODS> | undefined;

type SelectPaymentTypeParams = {
event: KYCFlowEvent;
iouPaymentType: PaymentMethodType;
triggerKYCFlow: TriggerKYCFlow;
policy: OnyxEntry<Policy>;
onPress: (paymentType?: PaymentMethodType, payAsBusiness?: boolean, methodID?: number, paymentMethod?: KYCPaymentMethod) => void;
currentAccountID: number;
currentEmail: string;
hasViolations: boolean;
isASAPSubmitBetaEnabled: boolean;
isUserValidated?: boolean;
confirmApproval?: () => void;
iouReport?: OnyxEntry<Report>;
};

/**
* Check to see if user has either a debit card or personal US bank account added that can be used with a wallet.
*/
Expand Down Expand Up @@ -123,16 +138,9 @@ function calculateWalletTransferBalanceFee(currentBalance: number, methodType: s
* It navigates users to verification pages if necessary, triggers KYC flows for specific payment methods,
* handles direct approvals, or proceeds with basic payment processing.
*/
const selectPaymentType = (
event: KYCFlowEvent,
iouPaymentType: PaymentMethodType,
triggerKYCFlow: TriggerKYCFlow,
policy: OnyxEntry<Policy>,
onPress: (paymentType?: PaymentMethodType, payAsBusiness?: boolean, methodID?: number, paymentMethod?: KYCPaymentMethod) => void,
isUserValidated?: boolean,
confirmApproval?: () => void,
iouReport?: OnyxEntry<Report>,
) => {
const selectPaymentType = (params: SelectPaymentTypeParams) => {
const {event, iouPaymentType, triggerKYCFlow, policy, onPress, currentAccountID, currentEmail, hasViolations, isASAPSubmitBetaEnabled, isUserValidated, confirmApproval, iouReport} =
params;
if (policy && shouldRestrictUserBillableActions(policy.id)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
Expand All @@ -152,7 +160,7 @@ const selectPaymentType = (
if (confirmApproval) {
confirmApproval();
} else {
approveMoneyRequest(iouReport);
approveMoneyRequest(iouReport, policy, currentAccountID, currentEmail, hasViolations, isASAPSubmitBetaEnabled, true);
}
return;
}
Expand Down Expand Up @@ -212,4 +220,4 @@ export {
isSecondaryActionAPaymentOption,
getActivePaymentType,
};
export type {KYCFlowEvent, TriggerKYCFlow, PaymentOrApproveOption, PaymentOption};
export type {KYCFlowEvent, TriggerKYCFlow, PaymentOrApproveOption, PaymentOption, SelectPaymentTypeParams};
Loading
Loading