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
4 changes: 2 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,8 @@ function MoneyReportHeader({
if (!moneyRequestReport) {
return [];
}
return getSecondaryExportReportActions(moneyRequestReport, policy, exportTemplates);
}, [moneyRequestReport, policy, exportTemplates]);
return getSecondaryExportReportActions(accountID, email ?? '', moneyRequestReport, policy, exportTemplates);
}, [moneyRequestReport, accountID, email, policy, exportTemplates]);

const connectedIntegrationName = connectedIntegration ? translate('workspace.accounting.connectionName', {connectionName: connectedIntegration}) : '';
const unapproveWarningText = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,30 +516,31 @@ function MoneyRequestReportPreviewContent({
}, [iouReportID]);

const reportPreviewAction = useMemo(() => {
return getReportPreviewAction(
isIouReportArchived || isChatReportArchived,
currentUserAccountID,
iouReport,
return getReportPreviewAction({
isReportArchived: isIouReportArchived || isChatReportArchived,
currentUserAccountID: currentUserDetails.accountID,
currentUserEmail: currentUserDetails.email ?? '',
report: iouReport,
policy,
transactions,
invoiceReceiverPolicy,
isPaidAnimationRunning,
isApprovedAnimationRunning,
isSubmittingAnimationRunning,
{currentUserEmail, violations: transactionViolations},
);
violationsData: transactionViolations,
});
}, [
isPaidAnimationRunning,
isApprovedAnimationRunning,
isSubmittingAnimationRunning,
isIouReportArchived,
isChatReportArchived,
currentUserDetails.accountID,
currentUserDetails.email,
iouReport,
policy,
transactions,
isIouReportArchived,
invoiceReceiverPolicy,
isChatReportArchived,
currentUserEmail,
currentUserAccountID,
isPaidAnimationRunning,
isApprovedAnimationRunning,
isSubmittingAnimationRunning,
transactionViolations,
]);

Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useTodos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {isApproveAction, isExportAction, isPrimaryPayAction, isSubmitAction} fro
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Report, Transaction} from '@src/types/onyx';
import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useOnyx from './useOnyx';

export default function useTodos() {
Expand All @@ -11,6 +12,7 @@ export default function useTodos() {
const [allReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {canBeMissing: false});
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: false});
const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: false});
const {email = '', accountID} = useCurrentUserPersonalDetails();

return useMemo(() => {
const reportsToSubmit: Report[] = [];
Expand Down Expand Up @@ -48,7 +50,7 @@ export default function useTodos() {
if (isApproveAction(report, reportTransactions, policy)) {
reportsToApprove.push(report);
}
if (isPrimaryPayAction(report, policy, reportNameValuePair)) {
if (isPrimaryPayAction(report, accountID, email, policy, reportNameValuePair)) {
reportsToPay.push(report);
}
if (isExportAction(report, policy, reportActions)) {
Expand All @@ -57,5 +59,5 @@ export default function useTodos() {
}

return {reportsToSubmit, reportsToApprove, reportsToPay, reportsToExport};
}, [allReports, allPolicies, allReportNameValuePairs, allTransactions, allReportActions]);
}, [allReports, allTransactions, allPolicies, allReportNameValuePairs, allReportActions, accountID, email]);
}
14 changes: 11 additions & 3 deletions src/libs/Firebase/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// We have opted for `Onyx.connectWithoutView` here as this logic is strictly non-UI in nature.
import Onyx from 'react-native-onyx';
import * as SessionUtils from '@libs/SessionUtils';
import type {OnyxEntry} from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Session} from '@src/types/onyx';
import type {PerfAttributes} from './types';

let reportsCount = 0;
Expand Down Expand Up @@ -57,9 +58,16 @@ Onyx.connectWithoutView({
},
});

function getAttributes<T extends keyof PerfAttributes>(attributes?: T[]): Pick<PerfAttributes, T> {
const session = SessionUtils.getSession();
let session: OnyxEntry<Session>;
// Firebase Utils are used for performance monitoring which does not affect the UI, hence using connectWithoutView
Onyx.connectWithoutView({
key: ONYXKEYS.SESSION,
callback: (value) => {
session = value;
},
});

function getAttributes<T extends keyof PerfAttributes>(attributes?: T[]): Pick<PerfAttributes, T> {
const allAttributes: PerfAttributes = {
accountId: session?.accountID?.toString() ?? 'N/A',
reportsLength: reportsCount.toString(),
Expand Down
43 changes: 5 additions & 38 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function buildOptimisticNextStep(params: BuildNextStepNewParams): ReportNextStep
nextStep = {
messageKey: CONST.NEXT_STEP.MESSAGE_KEY.WAITING_TO_PAY,
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
actorAccountID: isPayer({accountID: currentUserAccountIDParam, email: currentUserEmailParam}, report) ? currentUserAccountIDParam : -1,
actorAccountID: isPayer(currentUserAccountIDParam, currentUserEmailParam, report) ? currentUserAccountIDParam : -1,
};
}
break;
Expand All @@ -230,16 +230,7 @@ function buildOptimisticNextStep(params: BuildNextStepNewParams): ReportNextStep

// Generates an optimistic nextStep once a report has been approved
case CONST.REPORT.STATUS_NUM.APPROVED:
if (
isInvoiceReport(report) ||
!isPayer(
{
accountID: currentUserAccountIDParam,
email: currentUserEmailParam,
},
report,
)
) {
if (isInvoiceReport(report) || !isPayer(currentUserAccountIDParam, currentUserEmailParam, report)) {
nextStep = nextStepNoActionRequired;
break;
}
Expand Down Expand Up @@ -624,13 +615,7 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca
{
text: 'Waiting for ',
},
isPayer(
{
accountID: currentUserAccountIDParam,
email: currentUserEmailParam,
},
report,
)
isPayer(currentUserAccountIDParam, currentUserEmailParam, report)
? {
text: `you`,
type: 'strong',
Expand Down Expand Up @@ -667,32 +652,14 @@ function buildNextStepNew(params: BuildNextStepNewParams): ReportNextStepDepreca

// Generates an optimistic nextStep once a report has been approved
case CONST.REPORT.STATUS_NUM.APPROVED: {
if (
isInvoiceReport(report) ||
!isPayer(
{
accountID: currentUserAccountIDParam,
email: currentUserEmailParam,
},
report,
) ||
reimbursableSpend === 0
) {
if (isInvoiceReport(report) || !isPayer(currentUserAccountIDParam, currentUserEmailParam, report) || reimbursableSpend === 0) {
optimisticNextStep = noActionRequired;

break;
}
// Self review
let payerMessage: Message;
if (
isPayer(
{
accountID: currentUserAccountIDParam,
email: currentUserEmailParam,
},
report,
)
) {
if (isPayer(currentUserAccountIDParam, currentUserEmailParam, report)) {
payerMessage = {text: 'you', type: 'strong'};
} else if (reimburserAccountID === -1) {
payerMessage = {text: 'an admin'};
Expand Down
46 changes: 29 additions & 17 deletions src/libs/ReportPreviewActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
isReportApproved,
isSettled,
} from './ReportUtils';
import {getSession} from './SessionUtils';
import {hasSmartScanFailedViolation, isPending, isScanning} from './TransactionUtils';

function canSubmit(
Expand Down Expand Up @@ -87,12 +86,12 @@ function canApprove(report: Report, currentUserAccountID: number, policy?: Polic
return isExpense && isProcessing && !!isApprovalEnabled && reportTransactions.length > 0 && isCurrentUserManager;
}

function canPay(report: Report, isReportArchived: boolean, currentUserAccountID: number, policy?: Policy, invoiceReceiverPolicy?: Policy) {
function canPay(report: Report, isReportArchived: boolean, currentUserAccountID: number, currentUserEmail: string, policy?: Policy, invoiceReceiverPolicy?: Policy) {
if (isReportArchived) {
return false;
}

const isReportPayer = isPayer(getSession(), report, false, policy);
const isReportPayer = isPayer(currentUserAccountID, currentUserEmail, report, false, policy);
const isExpense = isExpenseReport(report);
const isPaymentsEnabled = arePaymentsEnabled(policy);
const isProcessing = isProcessingReport(report);
Expand Down Expand Up @@ -166,18 +165,31 @@ function canExport(report: Report, policy?: Policy) {
return isApproved || isReimbursed || isClosed;
}

function getReportPreviewAction(
isReportArchived: boolean,
currentUserAccountID: number,
report: Report | undefined,
policy: Policy | undefined,
transactions: Transaction[],
invoiceReceiverPolicy?: Policy,
isPaidAnimationRunning?: boolean,
isApprovedAnimationRunning?: boolean,
isSubmittingAnimationRunning?: boolean,
violationsData?: {currentUserEmail?: string; violations?: OnyxCollection<TransactionViolation[]>},
): ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS> {
function getReportPreviewAction({
isReportArchived,
currentUserAccountID,
currentUserEmail,
report,
policy,
transactions,
invoiceReceiverPolicy,
isPaidAnimationRunning,
isApprovedAnimationRunning,
isSubmittingAnimationRunning,
violationsData,
}: {
isReportArchived: boolean;
currentUserAccountID: number;
currentUserEmail: string;
report: Report | undefined;
policy: Policy | undefined;
transactions: Transaction[];
invoiceReceiverPolicy?: Policy;
isPaidAnimationRunning?: boolean;
isApprovedAnimationRunning?: boolean;
isSubmittingAnimationRunning?: boolean;
violationsData?: OnyxCollection<TransactionViolation[]>;
}): ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS> {
if (!report) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW;
}
Expand All @@ -195,13 +207,13 @@ function getReportPreviewAction(
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE;
}

if (canSubmit(report, isReportArchived, currentUserAccountID, violationsData?.currentUserEmail ?? '', violationsData?.violations, policy, transactions)) {
if (canSubmit(report, isReportArchived, currentUserAccountID, currentUserEmail, violationsData, policy, transactions)) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT;
}
if (canApprove(report, currentUserAccountID, policy, transactions)) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.APPROVE;
}
if (canPay(report, isReportArchived, currentUserAccountID, policy, invoiceReceiverPolicy)) {
if (canPay(report, isReportArchived, currentUserAccountID, currentUserEmail, policy, invoiceReceiverPolicy)) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
}
if (canExport(report, policy)) {
Expand Down
10 changes: 6 additions & 4 deletions src/libs/ReportPrimaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
isReportManager,
isSettled,
} from './ReportUtils';
import {getSession} from './SessionUtils';
import {
allHavePendingRTERViolation,
getTransactionViolations,
Expand Down Expand Up @@ -150,6 +149,8 @@ function isApproveAction(report: Report, reportTransactions: Transaction[], poli

function isPrimaryPayAction(
report: Report,
currentUserAccountID: number,
currentUserEmail: string,
policy?: Policy,
reportNameValuePairs?: ReportNameValuePairs,
isChatReportArchived?: boolean,
Expand All @@ -161,7 +162,7 @@ function isPrimaryPayAction(
return false;
}
const isExpenseReport = isExpenseReportUtils(report);
const isReportPayer = isPayer(getSession(), report, false, policy);
const isReportPayer = isPayer(currentUserAccountID, currentUserEmail, report, false, policy);
const arePaymentsEnabled = arePaymentsEnabledUtils(policy);
const isReportApproved = isReportApprovedUtils({report});
const isReportClosed = isClosedReportUtils(report);
Expand Down Expand Up @@ -419,7 +420,8 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf<t
}

const isPayActionWithAllExpensesHeld =
isPrimaryPayAction(report, policy, reportNameValuePairs, isChatReportArchived, invoiceReceiverPolicy, reportActions) && hasOnlyHeldExpenses(report?.reportID);
isPrimaryPayAction(report, currentUserAccountID, currentUserEmail, policy, reportNameValuePairs, isChatReportArchived, invoiceReceiverPolicy, reportActions) &&
hasOnlyHeldExpenses(report?.reportID);
const expensesToHold = getAllExpensesToHoldIfApplicable(report, reportActions, reportTransactions, policy);

if (isMarkAsCashAction(currentUserEmail, currentUserAccountID, report, reportTransactions, violations, policy)) {
Expand All @@ -445,7 +447,7 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf<t
return CONST.REPORT.PRIMARY_ACTIONS.SUBMIT;
}

if (isPrimaryPayAction(report, policy, reportNameValuePairs, isChatReportArchived, invoiceReceiverPolicy, reportActions)) {
if (isPrimaryPayAction(report, currentUserAccountID, currentUserEmail, policy, reportNameValuePairs, isChatReportArchived, invoiceReceiverPolicy, reportActions)) {
return CONST.REPORT.PRIMARY_ACTIONS.PAY;
}

Expand Down
Loading
Loading