Skip to content
Open
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
9 changes: 5 additions & 4 deletions src/components/KYCWall/BaseKYCWall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {Dimensions} from 'react-native';
import type {EmitterSubscription, View} from 'react-native';
import AddPaymentMethodMenu from '@components/AddPaymentMethodMenu';
import {usePersonalDetails} from '@components/OnyxListItemProvider';

Check failure on line 6 in src/components/KYCWall/BaseKYCWall.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

'usePersonalDetails' is defined but never used

Check failure on line 6 in src/components/KYCWall/BaseKYCWall.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

'usePersonalDetails' is defined but never used
import useAllPolicyExpenseChatReportActions from '@hooks/useAllPolicyExpenseChatReportActions';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -27,6 +27,7 @@
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails';
import {lastWorkspaceNumberSelector} from '@src/selectors/Policy';
import type {BankAccountList, Policy} from '@src/types/onyx';
import {getEmptyObject} from '@src/types/utils/EmptyObject';
Expand Down Expand Up @@ -68,15 +69,14 @@
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const [employeeLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(iouReport?.ownerAccountID)});

const {formatPhoneNumber, translate} = useLocalize();
const currentUserDetails = useCurrentUserPersonalDetails();
const currentUserAccountID = currentUserDetails.accountID;
const currentUserEmail = currentUserDetails.email ?? '';
const localCurrency = currentUserDetails.localCurrencyCode ?? CONST.CURRENCY.USD;
const reportPreviewAction = useParentReportAction(iouReport);
const personalDetails = usePersonalDetails();
const employeeEmail = personalDetails?.[iouReport?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID]?.login ?? '';
const reportTransactions = useReportTransactions(iouReport?.reportID);
const filteredReportActions = useAllPolicyExpenseChatReportActions();
const anchorRef = useRef<HTMLDivElement | View>(null);
Expand Down Expand Up @@ -150,6 +150,7 @@
formatPhoneNumber,
filteredReportActions,
currentUserAccountID,
employeeLogin,
reportTransactions,
);
if (inviteResult?.policyExpenseChatReportID) {
Expand Down Expand Up @@ -184,7 +185,7 @@
reportPreviewAction,
currentUserAccountID,
currentUserEmail,
employeeEmail,
employeeLogin ?? '',
conciergeReportID,
localCurrency,
lastWorkspaceNumber,
Expand Down Expand Up @@ -234,7 +235,7 @@
reportPreviewAction,
currentUserAccountID,
currentUserEmail,
employeeEmail,
employeeLogin,
introSelected,
formatPhoneNumber,
translate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {canApproveIOU, canIOUBePaid as canIOUBePaidAction} from '@userActions/IO
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';

type MoneyReportHeaderSecondaryActionsProps = {
Expand All @@ -84,6 +85,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
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)}`);
const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(moneyRequestReport?.ownerAccountID)});
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [nextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${moneyRequestReport?.reportID}`);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${moneyRequestReport?.reportID}`);
Expand Down Expand Up @@ -317,6 +319,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
? getSecondaryReportActions({
currentUserLogin: currentUserLogin ?? '',
currentUserAccountID: accountID,
submitterLogin,
report: moneyRequestReport,
chatReport,
reportTransactions: nonPendingDeleteTransactions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';

const PAYMENT_ICONS = ['Send', 'ThumbsUp', 'Cash', 'ArrowRight', 'Building'] as const;
Expand Down Expand Up @@ -96,6 +97,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
const [moneyRequestReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportID)}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(moneyRequestReport?.chatReportID)}`);
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(moneyRequestReport?.policyID)}`);
const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(moneyRequestReport?.ownerAccountID)});
const [session] = useOnyx(ONYXKEYS.SESSION);
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isUserValidatedSelector});
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
Expand Down Expand Up @@ -194,6 +196,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
? getSecondaryReportActions({
currentUserLogin: currentUserLogin ?? '',
currentUserAccountID: accountID,
submitterLogin,
report: moneyRequestReport,
chatReport,
reportTransactions: nonPendingDeleteTransactions,
Expand Down
13 changes: 12 additions & 1 deletion src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import initSplitExpense from '@libs/actions/SplitExpenses';
import {setNameValuePair} from '@libs/actions/User';
import {getTransactionsAndReportsFromSearch} from '@libs/MergeTransactionUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getLoginByAccountID} from '@libs/PersonalDetailsUtils';
import {getConnectedIntegration} from '@libs/PolicyUtils';
import {getSecondaryExportReportActions, isMergeActionForSelectedTransactions} from '@libs/ReportSecondaryActionUtils';
import {
Expand Down Expand Up @@ -229,6 +230,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const {isBetaEnabled} = usePermissions();
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);

const defaultExpensePolicy = useDefaultExpensePolicy();
const undeleteTransactions = useUndeleteTransactions();
Expand Down Expand Up @@ -751,7 +753,15 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
);
return;
}
const invite = moveIOUReportToPolicyAndInviteSubmitter(itemReport, adminPolicy, formatPhoneNumber, policyExpenseChatReportActions, accountID, reportTransactions);
const invite = moveIOUReportToPolicyAndInviteSubmitter(
itemReport,
adminPolicy,
formatPhoneNumber,
policyExpenseChatReportActions,
accountID,
getLoginByAccountID(itemReport?.ownerAccountID, personalDetails),
reportTransactions,
);
if (!invite?.policyExpenseChatReportID) {
moveIOUReportToPolicy(itemReport, adminPolicy, false, reportTransactions);
}
Expand Down Expand Up @@ -818,6 +828,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
formatPhoneNumber,
clearSelectedTransactions,
accountID,
personalDetails,
],
);

Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useSelectionModeReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {hasAnyPendingRTERViolation as hasAnyPendingRTERViolationTransactionUtils
import {markPendingRTERTransactionsAsCash} from '@userActions/Transaction';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {personalDetailsLoginSelector} from '@src/selectors/PersonalDetails';
import type * as OnyxTypes from '@src/types/onyx';
import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
import useActiveAdminPolicies from './useActiveAdminPolicies';
Expand Down Expand Up @@ -111,6 +112,7 @@ function useSelectionModeReportActions({
const [betas] = useOnyx(ONYXKEYS.BETAS);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [isSelfTourViewed = false] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector});
const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(report?.ownerAccountID)});
const {isOffline} = useNetwork();

const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
Expand Down Expand Up @@ -235,6 +237,7 @@ function useSelectionModeReportActions({
return getSecondaryReportActions({
currentUserLogin: currentUserEmail ?? '',
currentUserAccountID,
submitterLogin,
report,
chatReport,
reportTransactions: transactions,
Expand Down
10 changes: 2 additions & 8 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,8 @@
}, []);
}

/**
* Given an accountID, find the associated personal detail and return related login.
*
* @param accountID User accountID
* @returns Login according to passed accountID
*/
function getLoginByAccountID(accountID: number): string | undefined {
return allPersonalDetails?.[accountID]?.login;
function getLoginByAccountID(accountID: number | undefined, personalDetails: OnyxEntry<PersonalDetailsList> = allPersonalDetails): string | undefined {

Check failure on line 165 in src/libs/PersonalDetailsUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint check

'personalDetails' is already declared in the upper scope on line 22 column 5

Check failure on line 165 in src/libs/PersonalDetailsUtils.ts

View workflow job for this annotation

GitHub Actions / ESLint check

'personalDetails' is already declared in the upper scope on line 22 column 5
return accountID ? personalDetails?.[accountID]?.login : undefined;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
TransactionViolation,
} from '@src/types/onyx';
import {areTransactionsEligibleForMerge} from './MergeTransactionUtils';
import {getLoginByAccountID} from './PersonalDetailsUtils';
import {
arePaymentsEnabled as arePaymentsEnabledUtils,
getConnectedIntegration,
Expand Down Expand Up @@ -602,7 +601,7 @@ function isHoldActionForTransaction(
return true;
}

function isChangeWorkspaceAction(report: Report, policies: OnyxCollection<Policy>, currentUserLogin: string, reportActions?: ReportAction[]): boolean {
function isChangeWorkspaceAction(report: Report, policies: OnyxCollection<Policy>, currentUserLogin: string, submitterLogin: string | undefined, reportActions?: ReportAction[]): boolean {
// We can't move the iou report to the workspace if both users from the iou report create the expense
if (isIOUReportUtils(report) && doesReportContainRequestsFromMultipleUsers(report)) {
return false;
Expand All @@ -615,14 +614,13 @@ function isChangeWorkspaceAction(report: Report, policies: OnyxCollection<Policy
return false;
}

const submitterEmail = getLoginByAccountID(report?.ownerAccountID ?? CONST.DEFAULT_NUMBER_ID);
const isReportSettled = isSettled(report);

// Find available policies - stop early once we find 2 or after checking all
let firstAvailablePolicy: Policy | undefined;
let availablePoliciesCount = 0;
for (const policy of Object.values(policies ?? {})) {
if (!policy || !isWorkspaceEligibleForReportChange(submitterEmail, policy, report)) {
if (!policy || !isWorkspaceEligibleForReportChange(submitterLogin, policy, report)) {
continue;
}

Expand Down Expand Up @@ -864,6 +862,7 @@ function isDuplicateAction(report: Report, reportTransactions: Transaction[]): b
function getSecondaryReportActions({
currentUserLogin,
currentUserAccountID,
submitterLogin,
report,
chatReport,
reportTransactions,
Expand All @@ -880,6 +879,7 @@ function getSecondaryReportActions({
}: {
currentUserLogin: string;
currentUserAccountID: number;
submitterLogin: string | undefined;
report: Report;
chatReport: OnyxEntry<Report>;
reportTransactions: Transaction[];
Expand Down Expand Up @@ -1014,7 +1014,7 @@ function getSecondaryReportActions({

options.push(CONST.REPORT.SECONDARY_ACTIONS.PRINT);

if (isChangeWorkspaceAction(report, policies, currentUserLogin, reportActions)) {
if (isChangeWorkspaceAction(report, policies, currentUserLogin, submitterLogin, reportActions)) {
options.push(CONST.REPORT.SECONDARY_ACTIONS.CHANGE_WORKSPACE);
}

Expand Down
Loading
Loading