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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePayChatReportActions from '@hooks/usePayChatReportActions';
import usePaymentOptions from '@hooks/usePaymentOptions';
import usePermissions from '@hooks/usePermissions';
import {useGetPersonalDetailsByLogin} from '@hooks/usePersonalDetailByLogin';
import {usePersonalDetail} from '@hooks/usePersonalDetails';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
Expand Down Expand Up @@ -151,6 +152,8 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo

const {getCurrencyDecimals, convertToDisplayString} = useCurrencyListActions();

const getPersonalDetailsByLogin = useGetPersonalDetailsByLogin();

const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);

Expand Down Expand Up @@ -458,6 +461,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
const onPaymentSelect = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => {
const runPaymentSelection = () =>
selectPaymentType({
personalDetailsByLogins: getPersonalDetailsByLogin(),
getCurrencyDecimals,
event,
iouPaymentType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {usePaymentAnimationsContext} from '@components/PaymentAnimationsContext'

import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useOnyx from '@hooks/useOnyx';
import usePersonalDetailsByLogin from '@hooks/usePersonalDetailsByLogin';
import usePolicy from '@hooks/usePolicy';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport';
Expand Down Expand Up @@ -36,6 +37,7 @@ function ApprovePrimaryAction({reportID, chatReportID, isDisabled}: ApprovePrima
const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
const [expenseReportPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(iouReport?.policyID)}`);
const [rules] = useOnyx(ONYXKEYS.COLLECTION.RULE);
const personalDetailsByLogins = usePersonalDetailsByLogin();

const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`);
Expand All @@ -44,7 +46,7 @@ function ApprovePrimaryAction({reportID, chatReportID, isDisabled}: ApprovePrima
`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.invoiceReceiver && 'policyID' in iouReport.invoiceReceiver ? iouReport.invoiceReceiver.policyID : ''}`,
);

const nextApproverAccountID = getNextApproverAccountID(iouReport, rules);
const nextApproverAccountID = getNextApproverAccountID(iouReport, rules, undefined, undefined, personalDetailsByLogins);
const isSubmitterSameAsNextApprover = isReportOwner(iouReport) && (nextApproverAccountID === iouReport?.ownerAccountID || iouReport?.managerID === iouReport?.ownerAccountID);
const isBlockSubmitDueToPreventSelfApproval = isSubmitterSameAsNextApprover && expenseReportPolicy?.preventSelfApproval;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useDelegateAccountID from '@hooks/useDelegateAccountID';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import {useGetPersonalDetailsByLogin} from '@hooks/usePersonalDetailByLogin';
import {usePersonalDetail} from '@hooks/usePersonalDetails';
import useTransactionsAndViolationsForReport from '@hooks/useTransactionsAndViolationsForReport';

Expand All @@ -24,6 +25,7 @@ import {loginSelector} from '@selectors/PersonalDetails';
function useConfirmApproval(reportID: string | undefined, startApprovedAnimation: () => void) {
const {accountID, email} = useCurrentUserPersonalDetails();
const {getCurrencyDecimals} = useCurrencyListActions();
const getPersonalDetailsByLogin = useGetPersonalDetailsByLogin();
const {isBetaEnabled} = usePermissions();
const {isDelegateAccessRestricted} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
Expand Down Expand Up @@ -54,6 +56,7 @@ function useConfirmApproval(reportID: string | undefined, startApprovedAnimation
startApprovedAnimation();
}
approveMoneyRequest({
personalDetailsByLogins: getPersonalDetailsByLogin(),
getCurrencyDecimals,
expenseReport: moneyRequestReport,
expenseReportPolicy: policy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import {useGetPersonalDetailsByLogin} from '@hooks/usePersonalDetailByLogin';

import {approveMoneyRequest} from '@userActions/IOU/ReportWorkflow';

Expand All @@ -24,6 +25,7 @@ import {useReportPreviewActions} from './MoneyRequestReportPreviewContext';
function useConfirmApproveReportAction(actionButtonData: ReturnType<typeof useReportPreviewActionButtonData>, hasViolations: boolean) {
const currentUserDetails = useCurrentUserPersonalDetails();
const {getCurrencyDecimals} = useCurrencyListActions();
const getPersonalDetailsByLogin = useGetPersonalDetailsByLogin();
const {isBetaEnabled} = usePermissions();
const {isDelegateAccessRestricted} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
Expand All @@ -38,6 +40,7 @@ function useConfirmApproveReportAction(actionButtonData: ReturnType<typeof useRe
showDelegateNoAccessModal();
} else {
approveMoneyRequest({
personalDetailsByLogins: getPersonalDetailsByLogin(),
getCurrencyDecimals,
expenseReport: iouReport,
expenseReportPolicy: policy,
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useHoldMenuSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import useDelegateAccountID from './useDelegateAccountID';
import useOnyx from './useOnyx';
import usePayChatReportActions from './usePayChatReportActions';
import usePermissions from './usePermissions';
import {useGetPersonalDetailsByLogin} from './usePersonalDetailByLogin';
import {usePersonalDetail} from './usePersonalDetails';
import usePolicy from './usePolicy';
import useReportTransactions from './useReportTransactions';
Expand Down Expand Up @@ -64,6 +65,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const currentUserDetails = useCurrentUserPersonalDetails();
const {getCurrencyDecimals} = useCurrencyListActions();
const getPersonalDetailsByLogin = useGetPersonalDetailsByLogin();
const delegateAccountID = useDelegateAccountID();
const hasViolations = hasViolationsReportUtils(moneyRequestReport?.reportID, transactionViolations, currentUserDetails.accountID, currentUserDetails.email ?? '');

Expand All @@ -89,6 +91,7 @@ function useHoldMenuSubmit({moneyRequestReport, chatReport, requestType, payment

if (isApprove) {
approveMoneyRequest({
personalDetailsByLogins: getPersonalDetailsByLogin(),
getCurrencyDecimals,
expenseReport: currentMoneyRequestReport,
rules,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useLifecycleActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function useLifecycleActions({reportID, startApprovedAnimation, startAnimation,
startApprovedAnimation();
}
approveMoneyRequest({
personalDetailsByLogins: getPersonalDetailsByLogin(),
getCurrencyDecimals,
expenseReport: moneyRequestReport,
currentUserAccountIDParam: accountID,
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
!!expenseReport.policyID && shouldRestrictUserBillableActions(reportPolicy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID);

approveMoneyRequest({
personalDetailsByLogins: getPersonalDetailsByLogin(),
getCurrencyDecimals,
expenseReport,
expenseReportPolicy: reportPolicy,
Expand Down Expand Up @@ -1487,6 +1488,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
currentSearchKey,
isTrackIntentUser,
personalDetails,
getPersonalDetailsByLogin,
delegateAccountID,
getCurrencyDecimals,
rules,
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useSelectionModePayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import useParticipantsInvoiceReport from './useParticipantsInvoiceReport';
import usePayChatReportActions from './usePayChatReportActions';
import usePaymentOptions from './usePaymentOptions';
import usePermissions from './usePermissions';
import {useGetPersonalDetailsByLogin} from './usePersonalDetailByLogin';
import {usePersonalDetail} from './usePersonalDetails';
import usePolicy from './usePolicy';
import useSearchShouldCalculateTotals from './useSearchShouldCalculateTotals';
Expand Down Expand Up @@ -82,6 +83,7 @@ function useSelectionModePayment({
}: UseSelectionModePaymentParams) {
const {translate, localeCompare} = useLocalize();
const {getCurrencyDecimals} = useCurrencyListActions();
const getPersonalDetailsByLogin = useGetPersonalDetailsByLogin();
const {isOffline} = useNetwork();
const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
Expand Down Expand Up @@ -311,6 +313,7 @@ function useSelectionModePayment({

const invokePaymentSelect = (event: KYCFlowEvent, iouPaymentType: PaymentMethodType, triggerKYCFlow: TriggerKYCFlow) => {
selectPaymentType({
personalDetailsByLogins: getPersonalDetailsByLogin(),
getCurrencyDecimals,
event,
iouPaymentType,
Expand Down
4 changes: 4 additions & 0 deletions src/libs/PaymentUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';
import getBankIcon from '@components/Icon/BankIcons';
import type {ContinueActionParams} from '@components/KYCWall/types';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import type {PersonalDetailsByLogin} from '@components/PersonalDetailsByLoginProvider';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import type {BankAccountMenuItem} from '@components/Search/types';
import type {PaymentActionParams} from '@components/SettlementButton/types';
Expand Down Expand Up @@ -58,6 +59,7 @@ type SelectPaymentTypeParams = {
isTrackIntentUser: boolean | undefined;
ownerLogin: string | undefined;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
personalDetailsByLogins: PersonalDetailsByLogin;
};

type BusinessBankAccountOption = {
Expand Down Expand Up @@ -242,6 +244,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
isTrackIntentUser,
ownerLogin,
getCurrencyDecimals,
personalDetailsByLogins,
} = params;
if (policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, currentAccountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
Expand Down Expand Up @@ -279,6 +282,7 @@ const selectPaymentType = (params: SelectPaymentTypeParams) => {
delegateAccountID,
isTrackIntentUser,
getCurrencyDecimals,
personalDetailsByLogins,
});
}
return;
Expand Down
5 changes: 3 additions & 2 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';
import type {PersonalDetailsByLogin} from '@components/PersonalDetailsByLoginProvider';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -195,9 +196,9 @@ function getPersonalDetailByEmail(email: string | undefined): PersonalDetails |
* @param logins Array of user logins
* @returns Array of accountIDs according to passed logins
*/
function getAccountIDsByLogins(logins: string[]): number[] {
function getAccountIDsByLogins(logins: string[], personalDetailsByLogins?: PersonalDetailsByLogin): number[] {
return logins.reduce<number[]>((foundAccountIDs, login) => {
const currentDetail = getPersonalDetailByEmail(login);
const currentDetail = personalDetailsByLogins ? personalDetailsByLogins[login] : getPersonalDetailByEmail(login);
Comment thread
bernhardoj marked this conversation as resolved.
Resolved
if (!currentDetail) {
// generate an account ID because in this case the detail is probably new, so we don't have a real accountID yet
foundAccountIDs.push(generateAccountID(login));
Expand Down
9 changes: 5 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as defaultGroupAvatars from '@components/Icon/GroupDefaultAvatars';
import * as defaultWorkspaceAvatars from '@components/Icon/WorkspaceDefaultAvatars';
import type {LocaleContextProps, LocalizedTranslate} from '@components/LocaleContextProvider';
import type {MoneyRequestAmountInputProps} from '@components/MoneyRequestAmountInput';
import type {PersonalDetailsByLogin} from '@components/PersonalDetailsByLoginProvider';
import type {SearchColumnType} from '@components/Search/types';
import type {TransactionWithOptionalSearchFields} from '@components/TransactionItemRow/types';

Expand Down Expand Up @@ -5924,7 +5925,7 @@ function canEditMoneyRequest(
}

// TODO: currentUserEmail will be required eventually so this becomes a pure function. Subscribe the data via useOnyx and pass it from the component. Refactor issue: https://github.com/Expensify/App/issues/66412
function getNextApproverAccountID(report: OnyxEntry<Report>, rules: OnyxCollection<Rule>, isUnapproved = false, currentUserEmail?: string) {
function getNextApproverAccountID(report: OnyxEntry<Report>, rules: OnyxCollection<Rule>, isUnapproved = false, currentUserEmail?: string, personalDetailsByLogins?: PersonalDetailsByLogin) {
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
const policy = getPolicy(report?.policyID);
const currentUserLogin = currentUserEmail ?? deprecatedCurrentUserEmail ?? '';
Expand Down Expand Up @@ -5960,7 +5961,7 @@ function getNextApproverAccountID(report: OnyxEntry<Report>, rules: OnyxCollecti
return undefined;
}

return getAccountIDsByLogins([nextApproverEmail]).at(0);
return getAccountIDsByLogins([nextApproverEmail], personalDetailsByLogins).at(0);
}

function canEditReportPolicy(report: OnyxEntry<Report>, reportPolicy: OnyxEntry<Policy>): boolean {
Expand Down Expand Up @@ -8788,7 +8789,7 @@ function buildOptimisticCreatedReportForUnapprovedAction(
originalReportID: string | undefined,
): ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.CREATED_REPORT_FOR_UNAPPROVED_TRANSACTIONS> {
const createdTime = DateUtils.getDBTime();
const actor = getAccountIDsByLogins([CONST.EMAIL.CONCIERGE]).at(0);
const actor = CONST.ACCOUNT_ID.CONCIERGE;

return {
actionName: CONST.REPORT.ACTIONS.TYPE.CREATED_REPORT_FOR_UNAPPROVED_TRANSACTIONS,
Expand Down Expand Up @@ -9088,7 +9089,7 @@ function buildOptimisticReportPreview(
function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOUReportAction, transactionID: string, optimisticReportActionID?: string): ReportAction {
const currentTime = DateUtils.getDBTime();
const targetEmail = CONST.EMAIL.CONCIERGE;
const actorAccountID = getAccountIDsByLogins([targetEmail]).at(0);
const actorAccountID = CONST.ACCOUNT_ID.CONCIERGE;
const reportActionID = optimisticReportActionID ?? rand64();
return {
actionName: CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_TRACK_EXPENSE_WHISPER,
Expand Down
4 changes: 3 additions & 1 deletion src/libs/actions/IOU/ReportWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type ApproveMoneyRequestFunctionParams = {
additionalOnyxData?: AdditionalPayOnyxData;
shouldPlaySuccessSound?: boolean;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
personalDetailsByLogins: PersonalDetailsByLogin;
};

type SubmitReportFunctionParams = {
Expand Down Expand Up @@ -156,6 +157,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) {
shouldPlaySuccessSound = true,
isTrackIntentUser,
getCurrencyDecimals,
personalDetailsByLogins,
} = params;
if (!expenseReport) {
return;
Expand Down Expand Up @@ -194,7 +196,7 @@ function approveMoneyRequest(params: ApproveMoneyRequestFunctionParams) {
const isDEWPolicy = hasDynamicExternalWorkflow(expenseReportPolicy);
const shouldAddOptimisticApproveAction = !isDEWPolicy || getIsOffline();

const nextApproverAccountID = getNextApproverAccountID(expenseReport, rules);
const nextApproverAccountID = getNextApproverAccountID(expenseReport, rules, undefined, undefined, personalDetailsByLogins);
const predictedNextStatus = !nextApproverAccountID ? CONST.REPORT.STATUS_NUM.APPROVED : CONST.REPORT.STATUS_NUM.SUBMITTED;
const predictedNextState = !nextApproverAccountID ? CONST.REPORT.STATE_NUM.APPROVED : CONST.REPORT.STATE_NUM.SUBMITTED;
const managerID = !nextApproverAccountID ? expenseReport.managerID : nextApproverAccountID;
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ function handleActionButtonPress({
allViolations,
rules,
getCurrencyDecimals,
personalDetailsByLogins,
});
return;
case CONST.SEARCH.ACTION_TYPES.SUBMIT: {
Expand Down Expand Up @@ -759,6 +760,7 @@ type GetApproveActionCallbackParams = {
allViolations: OnyxCollection<TransactionViolations>;
rules: OnyxCollection<Rule>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
personalDetailsByLogins: PersonalDetailsByLogin;
};

function getApproveActionCallback({
Expand All @@ -781,6 +783,7 @@ function getApproveActionCallback({
allViolations,
rules,
getCurrencyDecimals,
personalDetailsByLogins,
}: GetApproveActionCallbackParams) {
if (!item.reportID) {
return;
Expand All @@ -807,6 +810,7 @@ function getApproveActionCallback({
additionalOnyxData: getSearchApproveOnyxData(hash, item.reportID, currentSearchKey),
isTrackIntentUser,
getCurrencyDecimals,
personalDetailsByLogins,
});
}

Expand Down
Loading
Loading