Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Bootstrap secondary actions getter #57678

13 changes: 13 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,19 @@ const CONST = {
MIN_INITIAL_REPORT_ACTION_COUNT: 15,
UNREPORTED_REPORTID: '0',
SPLIT_REPORTID: '-2',
SECONDARY_ACTIONS: {
SUBMIT: 'submit',
APPROVE: 'approve',
UNAPPROVE: 'unapprove',
CANCEL_PAYMENT: 'cancelPayment',
EXPORT_TO_ACCOUNTING: 'exportToAccounting',
MARK_AS_EXPORTED: 'markAsExported',
HOLD: 'hold',
DOWNLOAD: 'download',
CHANGE_WORKSPACE: 'changeWorkspace',
VIEW_DETAILS: 'viewDetails',
DELETE: 'delete',
},
PRIMARY_ACTIONS: {
SUBMIT: 'submit',
APPROVE: 'approve',
Expand Down
5 changes: 5 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,10 @@ function getReportActionsLength() {
return Object.keys(allReportActions ?? {}).length;
}

function getReportActions(report: Report) {
return allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`];
}

function wasActionCreatedWhileOffline(action: ReportAction, isOffline: boolean, lastOfflineAt: Date | undefined, lastOnlineAt: Date | undefined, locale: Locale): boolean {
// The user has never gone offline or never come back online
if (!lastOfflineAt || !lastOnlineAt) {
Expand Down Expand Up @@ -2333,6 +2337,7 @@ export {
getWorkspaceTagUpdateMessage,
getWorkspaceReportFieldUpdateMessage,
getWorkspaceReportFieldDeleteMessage,
getReportActions,
};

export type {LastVisibleMessage};
98 changes: 49 additions & 49 deletions src/libs/ReportPrimaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,72 @@ import type {OnyxCollection} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import type {Policy, Report, Transaction, TransactionViolation} from '@src/types/onyx';
import {isApprover as isApprovedMember} from './actions/Policy/Member';
import {isApprover as isApproverUtils} from './actions/Policy/Member';
import {getCurrentUserAccountID} from './actions/Report';
import {arePaymentsEnabled, getCorrectedAutoReportingFrequency, hasAccountingConnections, isAutoSyncEnabled, isPrefferedExporter} from './PolicyUtils';
import {arePaymentsEnabled as arePaymentsEnabledUtils, getCorrectedAutoReportingFrequency, hasAccountingConnections, isAutoSyncEnabled, isPrefferedExporter} from './PolicyUtils';
import {
isClosedReport,
isClosedReport as isClosedReportUtils,
isCurrentUserSubmitter,
isExpenseReport,
isExpenseReport as isExpenseReportUtils,
isHoldCreator,
isInvoiceReport,
isIOUReport,
isOpenReport,
isInvoiceReport as isInvoiceReportUtils,
isIOUReport as isIOUReportUtils,
isOpenReport as isOpenReportUtils,
isPayer,
isProcessingReport,
isReportApproved,
isProcessingReport as isProcessingReportUtils,
isReportApproved as isReportApprovedUtils,
isSettled,
} from './ReportUtils';
import {getSession} from './SessionUtils';
import {allHavePendingRTERViolation, isDuplicate, isOnHold as isOnHoldTransactionUtils, shouldShowBrokenConnectionViolationForMultipleTransactions} from './TransactionUtils';

function isSubmitAction(report: Report, policy: Policy) {
const isExpense = isExpenseReport(report);
const isSubmitter = isCurrentUserSubmitter(report.reportID);
const isOpen = isOpenReport(report);
const isExpenseReport = isExpenseReportUtils(report);
const isReportSubmitter = isCurrentUserSubmitter(report.reportID);
const isOpenReport = isOpenReportUtils(report);
const isManualSubmitEnabled = getCorrectedAutoReportingFrequency(policy) === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL;

return isExpense && isSubmitter && isOpen && isManualSubmitEnabled;
return isExpenseReport && isReportSubmitter && isOpenReport && isManualSubmitEnabled;
}

function isApproveAction(report: Report, policy: Policy, reportTransactions: Transaction[]) {
const isExpense = isExpenseReport(report);
const isApprover = isApprovedMember(policy, getCurrentUserAccountID());
const isExpenseReport = isExpenseReportUtils(report);
const isReportApprover = isApproverUtils(policy, getCurrentUserAccountID());
const isApprovalEnabled = policy.approvalMode && policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL;

if (!isExpense || !isApprover || !isApprovalEnabled) {
if (!isExpenseReport || !isReportApprover || !isApprovalEnabled) {
return false;
}

const isOneExpenseReport = isExpense && reportTransactions.length === 1;
const isOnHold = reportTransactions.some(isOnHoldTransactionUtils);
const isProcessing = isProcessingReport(report);
const isOneExpenseReportOnHold = isOneExpenseReport && isOnHold;
const isOneExpenseReport = isExpenseReport && reportTransactions.length === 1;
const isReportOnHold = reportTransactions.some(isOnHoldTransactionUtils);
const isProcessingReport = isProcessingReportUtils(report);
const isOneExpenseReportOnHold = isOneExpenseReport && isReportOnHold;

if (isProcessing || isOneExpenseReportOnHold) {
if (isProcessingReport || isOneExpenseReportOnHold) {
return true;
}

return false;
}

function isPayAction(report: Report, policy: Policy) {
const isExpense = isExpenseReport(report);
const isExpenseReport = isExpenseReportUtils(report);
const isReportPayer = isPayer(getSession(), report, false, policy);
const isPaymentsEnabled = arePaymentsEnabled(policy);
const isApproved = isReportApproved({report});
const isClosed = isClosedReport(report);
const isFinished = isApproved || isClosed;
const arePaymentsEnabled = arePaymentsEnabledUtils(policy);
const isReportApproved = isReportApprovedUtils({report});
const isReportClosed = isClosedReportUtils(report);
const isReportFinished = isReportApproved || isReportClosed;

if (isReportPayer && isExpense && isPaymentsEnabled && isFinished) {
if (isReportPayer && isExpenseReport && arePaymentsEnabled && isReportFinished) {
return true;
}

const isProcessing = isProcessingReport(report);
const isInvoice = isInvoiceReport(report);
const isIOU = isIOUReport(report);
const isProcessingReport = isProcessingReportUtils(report);
const isInvoiceReport = isInvoiceReportUtils(report);
const isIOUReport = isIOUReportUtils(report);

if ((isInvoice || isIOU) && isProcessing) {
if ((isInvoiceReport || isIOUReport) && isProcessingReport) {
return true;
}

Expand All @@ -80,8 +80,8 @@ function isExportAction(report: Report, policy: Policy) {
return false;
}

const isExporter = isPrefferedExporter(policy);
if (!isExporter) {
const isReportExporter = isPrefferedExporter(policy);
if (!isReportExporter) {
return false;
}

Expand All @@ -90,22 +90,22 @@ function isExportAction(report: Report, policy: Policy) {
return false;
}

const isReimbursed = isSettled(report);
const isApproved = isReportApproved({report});
const isClosed = isClosedReport(report);
const isReportReimbursed = isSettled(report);
const isReportApproved = isReportApprovedUtils({report});
const isReportClosed = isClosedReportUtils(report);

if (isApproved || isReimbursed || isClosed) {
if (isReportApproved || isReportReimbursed || isReportClosed) {
return true;
}

return false;
}

function isRemoveHoldAction(report: Report, reportTransactions: Transaction[]) {
const isOnHold = reportTransactions.some(isOnHoldTransactionUtils);
const isReportOnHold = reportTransactions.some(isOnHoldTransactionUtils);
const isHolder = reportTransactions.some((transaction) => isHoldCreator(transaction, report.reportID));

return isOnHold && isHolder;
return isReportOnHold && isHolder;
}

function isReviewDuplicatesAction(report: Report, policy: Policy, reportTransactions: Transaction[]) {
Expand All @@ -115,15 +115,15 @@ function isReviewDuplicatesAction(report: Report, policy: Policy, reportTransact
return false;
}

const isApprover = isApprovedMember(policy, getCurrentUserAccountID());
const isSubmitter = isCurrentUserSubmitter(report.reportID);
const isProcessing = isProcessingReport(report);
const isOpen = isOpenReport(report);
const isReportApprover = isApproverUtils(policy, getCurrentUserAccountID());
const isReportSubmitter = isCurrentUserSubmitter(report.reportID);
const isProcessingReport = isProcessingReportUtils(report);
const isReportOpen = isOpenReportUtils(report);

const isSubmitterOrApprover = isSubmitter || isApprover;
const isActive = isOpen || isProcessing;
const isSubmitterOrApprover = isReportSubmitter || isReportApprover;
const isReportActive = isReportOpen || isProcessingReport;

if (isSubmitterOrApprover && isActive) {
if (isSubmitterOrApprover && isReportActive) {
return true;
}

Expand All @@ -138,13 +138,13 @@ function isMarkAsCashAction(report: Report, policy: Policy, reportTransactions:
return true;
}

const isSubmitter = isCurrentUserSubmitter(report.reportID);
const isApprover = isApprovedMember(policy, getCurrentUserAccountID());
const isReportSubmitter = isCurrentUserSubmitter(report.reportID);
const isReportApprover = isApproverUtils(policy, getCurrentUserAccountID());
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;

const shouldShowBrokenConnectionViolation = shouldShowBrokenConnectionViolationForMultipleTransactions(transactionIDs, report, policy, violations);

const userControlsReport = isSubmitter || isApprover || isAdmin;
const userControlsReport = isReportSubmitter || isReportApprover || isAdmin;
return userControlsReport && shouldShowBrokenConnectionViolation;
}

Expand Down
Loading
Loading