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
2 changes: 1 addition & 1 deletion src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
isScanning,
} from '@libs/TransactionUtils';
import variables from '@styles/variables';
import {initBulkEditDraftTransaction} from '@userActions/IOU';
import {initBulkEditDraftTransaction} from '@userActions/IOU/BulkEdit';
import {dismissRejectUseExplanation} from '@userActions/IOU/RejectMoneyRequest';
import {canIOUBePaid} from '@userActions/IOU/ReportWorkflow';
import CONST from '@src/CONST';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSelectedTransactionsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';
import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/DelegateNoAccessModalProvider';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import {useSearchActionsContext, useSearchStateContext} from '@components/Search/SearchContext';
import {initBulkEditDraftTransaction} from '@libs/actions/IOU';
import {initBulkEditDraftTransaction} from '@libs/actions/IOU/BulkEdit';
import {unholdRequest} from '@libs/actions/IOU/Hold';
import {setupMergeTransactionDataAndNavigate} from '@libs/actions/MergeTransaction';
import {exportReportToCSV} from '@libs/actions/Report';
Expand Down
584 changes: 584 additions & 0 deletions src/libs/actions/IOU/BulkEdit.ts

Large diffs are not rendered by default.

243 changes: 242 additions & 1 deletion src/libs/actions/IOU/ReportWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import * as API from '@libs/API';
import type {ApproveMoneyRequestParams, ReopenReportParams, RetractReportParams, SubmitReportParams, UnapproveExpenseReportParams} from '@libs/API/parameters';
import type {
AddReportApproverParams,
ApproveMoneyRequestParams,
AssignReportToMeParams,
ReopenReportParams,
RetractReportParams,
SubmitReportParams,
UnapproveExpenseReportParams,
} from '@libs/API/parameters';
import {WRITE_COMMANDS} from '@libs/API/types';
import {getMicroSecondOnyxErrorWithTranslationKey} from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand All @@ -14,6 +22,7 @@ import {arePaymentsEnabled, getSubmitToAccountID, hasDynamicExternalWorkflow, is
import {getAllReportActions, getReportActionHtml, getReportActionText, hasPendingDEWApprove, isCreatedAction, isDeletedAction} from '@libs/ReportActionsUtils';
import {
buildOptimisticApprovedReportAction,
buildOptimisticChangeApproverReportAction,
buildOptimisticReopenedReportAction,
buildOptimisticRetractedReportAction,
buildOptimisticSubmittedReportAction,
Expand Down Expand Up @@ -62,6 +71,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import type ReportAction from '@src/types/onyx/ReportAction';
import type {OnyxData} from '@src/types/onyx/Request';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {getAllReportActionsFromIOU, getAllReportNameValuePairs, getAllTransactionViolations, getCurrentUserEmail, getUserAccountID} from '.';
import {getReportFromHoldRequestsOnyxData} from './Hold';
Expand Down Expand Up @@ -1491,8 +1501,239 @@ function submitReport({
API.write(WRITE_COMMANDS.SUBMIT_REPORT, parameters, {optimisticData, successData, failureData});
}

function assignReportToMe(
report: OnyxTypes.Report,
accountID: number,
email: string,
policy: OnyxEntry<OnyxTypes.Policy>,
hasViolations: boolean,
isASAPSubmitBetaEnabled: boolean,
reportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>,
) {
const takeControlReportAction = buildOptimisticChangeApproverReportAction(accountID, accountID);

// buildOptimisticNextStep is used in parallel
// eslint-disable-next-line @typescript-eslint/no-deprecated
const optimisticNextStepDeprecated = buildNextStepNew({
report: {...report, managerID: accountID},
predictedNextStatus: report.statusNum ?? CONST.REPORT.STATUS_NUM.SUBMITTED,
shouldFixViolations: false,
isUnapprove: true,
policy,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email,
hasViolations,
isASAPSubmitBetaEnabled,
bypassNextApproverID: accountID,
});
const optimisticNextStep = buildOptimisticNextStep({
report: {...report, managerID: accountID},
predictedNextStatus: report.statusNum ?? CONST.REPORT.STATUS_NUM.SUBMITTED,
shouldFixViolations: false,
isUnapprove: true,
policy,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email,
hasViolations,
isASAPSubmitBetaEnabled,
bypassNextApproverID: accountID,
});

const onyxData: OnyxData<typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.NEXT_STEP> = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
managerID: accountID,
nextStep: optimisticNextStep,
pendingFields: {
nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
value: {
[takeControlReportAction.reportActionID]: takeControlReportAction,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${report.reportID}`,
value: optimisticNextStepDeprecated,
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
pendingFields: {
nextStep: null,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
value: {
[takeControlReportAction.reportActionID]: {
pendingAction: null,
isOptimisticAction: null,
errors: null,
},
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
managerID: report.managerID,
nextStep: report.nextStep ?? null,
pendingFields: {
nextStep: null,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${report?.reportID}`,
value: reportCurrentNextStepDeprecated ?? null,
},
],
};

const params: AssignReportToMeParams = {
reportID: report.reportID,
reportActionID: takeControlReportAction.reportActionID,
};

API.write(WRITE_COMMANDS.ASSIGN_REPORT_TO_ME, params, onyxData);
}

function addReportApprover(
report: OnyxTypes.Report,
newApproverEmail: string,
newApproverAccountID: number,
accountID: number,
email: string,
policy: OnyxEntry<OnyxTypes.Policy>,
hasViolations: boolean,
isASAPSubmitBetaEnabled: boolean,
reportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>,
) {
const takeControlReportAction = buildOptimisticChangeApproverReportAction(newApproverAccountID, accountID);

// buildOptimisticNextStep is used in parallel
// eslint-disable-next-line @typescript-eslint/no-deprecated
const optimisticNextStepDeprecated = buildNextStepNew({
report: {...report, managerID: newApproverAccountID},
predictedNextStatus: report.statusNum ?? CONST.REPORT.STATUS_NUM.SUBMITTED,
shouldFixViolations: false,
isUnapprove: true,
policy,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email,
hasViolations,
isASAPSubmitBetaEnabled,
bypassNextApproverID: newApproverAccountID,
});
const optimisticNextStep = buildOptimisticNextStep({
report: {...report, managerID: newApproverAccountID},
predictedNextStatus: report.statusNum ?? CONST.REPORT.STATUS_NUM.SUBMITTED,
shouldFixViolations: false,
isUnapprove: true,
policy,
currentUserAccountIDParam: accountID,
currentUserEmailParam: email,
hasViolations,
isASAPSubmitBetaEnabled,
bypassNextApproverID: newApproverAccountID,
});
const onyxData: OnyxData<typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.NEXT_STEP> = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
managerID: newApproverAccountID,
nextStep: optimisticNextStep,
pendingFields: {
nextStep: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
value: {
[takeControlReportAction.reportActionID]: takeControlReportAction,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${report.reportID}`,
value: optimisticNextStepDeprecated,
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
pendingFields: {
nextStep: null,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`,
value: {
[takeControlReportAction.reportActionID]: {
pendingAction: null,
errors: null,
},
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
managerID: report.managerID,
nextStep: report.nextStep ?? null,
pendingFields: {
nextStep: null,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${report?.reportID}`,
value: reportCurrentNextStepDeprecated ?? null,
},
],
};

const params: AddReportApproverParams = {
reportID: report.reportID,
reportActionID: takeControlReportAction.reportActionID,
newApproverEmail,
};

API.write(WRITE_COMMANDS.ADD_REPORT_APPROVER, params, onyxData);
}

export {
addReportApprover,
approveMoneyRequest,
assignReportToMe,
canApproveIOU,
canCancelPayment,
canIOUBePaid,
Expand Down
Loading
Loading