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
8 changes: 4 additions & 4 deletions src/hooks/useTodos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function useTodos() {
const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: false});
const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: false});
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
const {login = '', accountID} = useCurrentUserPersonalDetails();
const {login = '', accountID: currentUserAccountID} = useCurrentUserPersonalDetails();

return useMemo(() => {
const reportsToSubmit: Report[] = [];
Expand Down Expand Up @@ -48,10 +48,10 @@ export default function useTodos() {
if (isSubmitAction(report, reportTransactions, policy, reportNameValuePair)) {
reportsToSubmit.push(report);
}
if (isApproveAction(report, reportTransactions, policy)) {
if (isApproveAction(report, reportTransactions, currentUserAccountID, policy)) {
reportsToApprove.push(report);
}
if (isPrimaryPayAction(report, accountID, login, bankAccountList, policy, reportNameValuePair)) {
if (isPrimaryPayAction(report, currentUserAccountID, login, bankAccountList, policy, reportNameValuePair)) {
reportsToPay.push(report);
}
if (isExportAction(report, login, policy, reportActions)) {
Expand All @@ -60,5 +60,5 @@ export default function useTodos() {
}

return {reportsToSubmit, reportsToApprove, reportsToPay, reportsToExport};
}, [allReports, allTransactions, allPolicies, allReportNameValuePairs, allReportActions, accountID, login, bankAccountList]);
}, [allReports, allTransactions, allPolicies, allReportNameValuePairs, allReportActions, currentUserAccountID, login, bankAccountList]);
}
7 changes: 2 additions & 5 deletions src/libs/ReportPrimaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {BankAccountList, Policy, Report, ReportAction, ReportMetadata, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
import {isApprover as isApproverUtils} from './actions/Policy/Member';
import {getCurrentUserAccountID} from './actions/Report';
import {
arePaymentsEnabled as arePaymentsEnabledUtils,
getSubmitToAccountID,
Expand Down Expand Up @@ -129,14 +128,12 @@ function isSubmitAction(
return isExpenseReport && isReportSubmitter && isOpenReport && reportTransactions.length !== 0 && transactionAreComplete;
}

function isApproveAction(report: Report, reportTransactions: Transaction[], policy?: Policy) {
function isApproveAction(report: Report, reportTransactions: Transaction[], currentUserAccountID: number, policy?: Policy) {
const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isScanning(transaction));

if (isAnyReceiptBeingScanned) {
return false;
}
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Temporarily disabling the rule for deprecated functions; it will be removed soon in https://github.com/Expensify/App/issues/73648.
const currentUserAccountID = getCurrentUserAccountID();
const managerID = report?.managerID ?? CONST.DEFAULT_NUMBER_ID;
const isCurrentUserManager = managerID === currentUserAccountID;
if (!isCurrentUserManager) {
Expand Down Expand Up @@ -449,7 +446,7 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf<t
return CONST.REPORT.PRIMARY_ACTIONS.REVIEW_DUPLICATES;
}

if (isApproveAction(report, reportTransactions, policy)) {
if (isApproveAction(report, reportTransactions, currentUserAccountID, policy)) {
return CONST.REPORT.PRIMARY_ACTIONS.APPROVE;
}

Expand Down
26 changes: 15 additions & 11 deletions src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function isSubmitAction({
primaryAction?: ValueOf<typeof CONST.REPORT.PRIMARY_ACTIONS> | '';
violations?: OnyxCollection<TransactionViolation[]>;
currentUserLogin?: string;
currentUserAccountID?: number;
currentUserAccountID: number;
}): boolean {
if (isArchivedReport(reportNameValuePairs) || isChatReportArchived) {
return false;
Expand Down Expand Up @@ -217,8 +217,8 @@ function isSubmitAction({

const isReportSubmitter = isCurrentUserSubmitter(report);
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Temporarily disabling the rule for deprecated functions; it will be removed soon in https://github.com/Expensify/App/issues/73648.
const isManager = report.managerID === getCurrentUserAccountID();

const isManager = report.managerID === currentUserAccountID;
if (!isReportSubmitter && !isAdmin && !isManager) {
return false;
}
Expand Down Expand Up @@ -255,15 +255,20 @@ function isSubmitAction({
return !!isScheduledSubmitEnabled || !isPrimarySubmitAction;
}

function isApproveAction(currentUserLogin: string, report: Report, reportTransactions: Transaction[], violations: OnyxCollection<TransactionViolation[]>, policy?: Policy): boolean {
function isApproveAction(
currentUserLogin: string,
currentUserAccountID: number,
report: Report,
reportTransactions: Transaction[],
violations: OnyxCollection<TransactionViolation[]>,
policy?: Policy,
): boolean {
const isAnyReceiptBeingScanned = reportTransactions?.some((transaction) => isReceiptBeingScanned(transaction));

if (isAnyReceiptBeingScanned) {
return false;
}

// eslint-disable-next-line @typescript-eslint/no-deprecated -- Temporarily disabling the rule for deprecated functions; it will be removed soon in https://github.com/Expensify/App/issues/73648.
const currentUserAccountID = getCurrentUserAccountID();
const managerID = report?.managerID ?? CONST.DEFAULT_NUMBER_ID;
const isCurrentUserManager = managerID === currentUserAccountID;
if (!isCurrentUserManager) {
Expand Down Expand Up @@ -314,15 +319,14 @@ function isApproveAction(currentUserLogin: string, report: Report, reportTransac
return userControlsReport && shouldShowBrokenConnectionViolation;
}

function isUnapproveAction(currentUserLogin: string, report: Report, policy?: Policy): boolean {
function isUnapproveAction(currentUserLogin: string, currentUserAccountID: number, report: Report, policy?: Policy): boolean {
const isExpenseReport = isExpenseReportUtils(report);
const isReportApprover = isApproverUtils(policy, currentUserLogin);
const isReportApproved = isReportApprovedUtils({report});
const isReportSettled = isSettled(report);
const isPaymentProcessing = report.isWaitingOnBankAccount && report.statusNum === CONST.REPORT.STATUS_NUM.APPROVED;
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
// eslint-disable-next-line @typescript-eslint/no-deprecated -- Temporarily disabling the rule for deprecated functions; it will be removed soon in https://github.com/Expensify/App/issues/73648.
const isManager = report.managerID === getCurrentUserAccountID();
const isManager = report.managerID === currentUserAccountID;

if (isReportSettled || !isExpenseReport || !isReportApproved || isPaymentProcessing) {
return false;
Expand Down Expand Up @@ -856,11 +860,11 @@ function getSecondaryReportActions({
options.push(CONST.REPORT.SECONDARY_ACTIONS.SUBMIT);
}

if (isApproveAction(currentUserLogin, report, reportTransactions, violations, policy)) {
if (isApproveAction(currentUserLogin, currentUserAccountID, report, reportTransactions, violations, policy)) {
options.push(CONST.REPORT.SECONDARY_ACTIONS.APPROVE);
}

if (isUnapproveAction(currentUserLogin, report, policy)) {
if (isUnapproveAction(currentUserLogin, currentUserAccountID, report, policy)) {
options.push(CONST.REPORT.SECONDARY_ACTIONS.UNAPPROVE);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/useTodosTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ const POLICY_WITH_CONNECTION_ID = 'policy_with_connection';

// This keeps the error "@rnmapbox/maps native code not available." from causing the tests to fail
jest.mock('@components/ConfirmedRoute.tsx');
jest.mock('@hooks/useCurrentUserPersonalDetails', () => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
__esModule: true,
default: jest.fn(() => ({
email: CURRENT_USER_EMAIL,
accountID: CURRENT_USER_ACCOUNT_ID,
})),
}));

const createMockReport = (reportID: string, overrides: Partial<Report> = {}): Report =>
({
Expand Down
Loading