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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import type {KYCFlowEvent, TriggerKYCFlow} from '@libs/PaymentUtils';
import type CONST from '@src/CONST';
import type {Report} from '@src/types/onyx';
import type {Policy, Report} from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';

type SelectionDropdownProps = {
Expand All @@ -30,6 +30,9 @@ type SelectionDropdownProps = {
/** Callback for the end of the onContinue trigger on option selection */
selectionModeKYCSuccess: (type?: PaymentMethodType) => void;

/** Callback when a workspace policy payment option is selected */
onWorkspacePolicySelect: (policy: Policy, triggerKYCFlow: TriggerKYCFlow) => void;

/** Reference to the KYC wall */
kycWallRef: React.RefObject<KYCWallRef | null>;

Expand All @@ -43,6 +46,7 @@ function SelectionDropdown({
report,
onSelectionModePaymentSelect,
selectionModeKYCSuccess,
onWorkspacePolicySelect,
primaryAction,
selectedTransactionsOptions,
selectedTransactionIDs,
Expand All @@ -60,6 +64,7 @@ function SelectionDropdown({
chatReportID={chatReport?.reportID}
iouReport={report}
onPaymentSelect={onSelectionModePaymentSelect}
onWorkspacePolicySelect={onWorkspacePolicySelect}
onSuccessfulKYC={selectionModeKYCSuccess}
primaryAction={primaryAction}
applicableSecondaryActions={selectedTransactionsOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function SelectionToolbar({reportID, transactions, reportActions}: SelectionTool
hasPayInSelectionMode,
onSelectionModePaymentSelect,
selectionModeKYCSuccess,
shouldBlockAction,
primaryAction,
kycWallRef,
isHoldMenuVisible,
Expand Down Expand Up @@ -251,6 +252,12 @@ function SelectionToolbar({reportID, transactions, reportActions}: SelectionTool
report={report}
onSelectionModePaymentSelect={onSelectionModePaymentSelect}
selectionModeKYCSuccess={selectionModeKYCSuccess}
onWorkspacePolicySelect={(selectedPolicy, triggerKYCFlow) => {
if (shouldBlockAction()) {
return;
}
triggerKYCFlow({policy: selectedPolicy});
}}
primaryAction={primaryAction}
selectedTransactionsOptions={selectedTransactionsOptions}
selectedTransactionIDs={selectedTransactionIDs}
Expand Down
24 changes: 12 additions & 12 deletions src/hooks/useLifecycleActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {ModalActions} from '@components/Modal/Global/ModalContext';
import type {SecondaryActionEntry} from '@components/MoneyReportHeaderActions/types';
import {useSearchQueryContext, useSearchResultsContext, useSearchSelectionActions} from '@components/Search/SearchContext';
import Text from '@components/Text';
import {search} from '@libs/actions/Search';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {getValidConnectedIntegration, isSubmitPolicy} from '@libs/PolicyUtils';
import {getFilteredReportActionsForReportView} from '@libs/ReportActionsUtils';
Expand All @@ -21,6 +20,7 @@ import {
shouldBlockSubmitDueToStrictPolicyRules,
shouldShowMarkAsDone,
} from '@libs/ReportUtils';
import refreshSearchAfterReportAction from '@libs/SearchRefreshUtils';
import {hasAnyPendingRTERViolation as hasAnyPendingRTERViolationTransactionUtils, hasOnlyPendingCardTransactions, showPendingCardTransactionsBlockModal} from '@libs/TransactionUtils';
import {cancelPayment, markReportPaymentReceived} from '@userActions/IOU/PayMoneyRequest';
import {approveMoneyRequest, reopenReport, retractReport, submitReport, unapproveExpenseReport} from '@userActions/IOU/ReportWorkflow';
Expand Down Expand Up @@ -49,6 +49,7 @@ type UseLifecycleActionsParams = {
startAnimation: () => void;
startSubmittingAnimation: () => void;
onHoldMenuOpen: (requestType: ActionHandledType, onConfirm?: () => void, paymentType?: PaymentMethodType) => void;
onCleanup?: () => void;
};

type UseLifecycleActionsResult = {
Expand All @@ -63,7 +64,7 @@ type UseLifecycleActionsResult = {
* Provides report lifecycle transition actions (submit, approve, unapprove, cancel payment, retract, reopen)
* and their associated guards (delegate access, hold, pending RTER, strict policy rules).
*/
function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, startSubmittingAnimation, onHoldMenuOpen}: UseLifecycleActionsParams): UseLifecycleActionsResult {
function useLifecycleActions({reportID, startApprovedAnimation, startAnimation, startSubmittingAnimation, onHoldMenuOpen, onCleanup}: UseLifecycleActionsParams): UseLifecycleActionsResult {
const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(moneyRequestReport?.policyID)}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(moneyRequestReport?.chatReportID)}`);
Expand Down Expand Up @@ -179,6 +180,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation,
});
if (skipAnimation) {
clearSelectedTransactions(true);
onCleanup?.();
}
};

Expand Down Expand Up @@ -213,18 +215,16 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation,
delegateEmail,
submitterLogin,
});
if (currentSearchQueryJSON && !isOffline) {
search({
searchKey: currentSearchKey,
shouldCalculateTotals,
offset: 0,
queryJSON: currentSearchQueryJSON,
isOffline,
isLoading: !!currentSearchResults?.search?.isLoading,
});
}
refreshSearchAfterReportAction({
currentSearchQueryJSON,
currentSearchKey,
shouldCalculateTotals,
isOffline,
isLoading: !!currentSearchResults?.search?.isLoading,
});
if (skipAnimation) {
clearSelectedTransactions(true);
onCleanup?.();
}
};

Expand Down
Loading
Loading