Skip to content
Open
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
15 changes: 10 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8067,7 +8067,13 @@ function buildOptimisticMovedReportAction(
* Builds an optimistic CHANGE_POLICY report action with a randomly generated reportActionID.
* This action is used when we change the workspace of a report.
*/
function buildOptimisticChangePolicyReportAction(fromPolicyID: string | undefined, toPolicyID: string, currentUserAccountID: number, automaticAction = false): ReportAction {
function buildOptimisticChangePolicyReportAction(
fromPolicyID: string | undefined,
toPolicyID: string,
currentUserAccountID: number,
delegateAccountID: number | undefined,
automaticAction = false,
): ReportAction {
const originalMessage = {
fromPolicy: fromPolicyID,
toPolicy: toPolicyID,
Expand Down Expand Up @@ -8097,6 +8103,7 @@ function buildOptimisticChangePolicyReportAction(fromPolicyID: string | undefine
return {
actionName: CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY,
actorAccountID: currentUserAccountID,
delegateAccountID,
avatar: getCurrentUserAvatar(),
created: DateUtils.getDBTime(),
originalMessage,
Expand Down Expand Up @@ -8228,18 +8235,16 @@ function buildOptimisticReportPreview(
chatReport: OnyxInputOrEntry<Report>,
iouReport: Report,
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'],
delegateAccountIDParam: number | undefined,
comment = '',
transaction: OnyxInputOrEntry<Transaction> = null,
childReportID?: string,
reportActionID?: string,
delegateAccountIDParam: number | undefined = undefined,
): ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW> {
const hasReceipt = hasReceiptTransactionUtils(transaction);
const message = getReportPreviewReportActionMessage({reportOrID: iouReport}, getCurrencyDecimals);
const created = DateUtils.getDBTime();
const reportActorAccountID = (isInvoiceReport(iouReport) || isExpenseReport(iouReport) ? iouReport?.ownerAccountID : iouReport?.managerID) ?? -1;
// Falls back to module-level delegateEmail (from Onyx.connect) for callers not yet migrated; will be removed in https://github.com/Expensify/App/issues/66425
const effectiveDelegateAccountID = delegateAccountIDParam ?? (delegateEmail ? getPersonalDetailByEmail(delegateEmail)?.accountID : undefined);
const isTestDriveTransaction = !!transaction?.receipt?.isTestDriveReceipt;
const isScanRequest = transaction ? isScanRequestTransactionUtils(transaction) : false;
return {
Expand All @@ -8258,7 +8263,7 @@ function buildOptimisticReportPreview(
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
},
],
delegateAccountID: effectiveDelegateAccountID,
delegateAccountID: delegateAccountIDParam,
created,
accountID: iouReport?.managerID,
// The preview is initially whispered if created with a receipt, so the actor is the current user as well
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/Hold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,11 +768,11 @@ function getReportFromHoldRequestsOnyxData({
chatReport,
optimisticExpenseReport,
getCurrencyDecimals,
delegateAccountID,
'',
firstHoldTransaction,
optimisticExpenseReport.reportID,
newParentReportActionID,
delegateAccountID,
);

let optimisticCreatedReportForUnapprovedAction: OnyxTypes.ReportAction | null = null;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/MoneyRequestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1684,11 +1684,11 @@ function getMoneyRequestInformation(moneyRequestInformation: MoneyRequestInforma
chatReport,
iouReport,
getCurrencyDecimals,
delegateAccountID,
comment,
optimisticTransaction,
undefined,
optimisticReportPreviewActionID,
delegateAccountID,
);
chatReport.lastVisibleActionCreated = reportPreviewAction.created;

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/PerDiem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,11 @@ function getPerDiemExpenseInformation(perDiemExpenseInformation: PerDiemExpenseI
chatReport,
iouReport,
getCurrencyDecimals,
delegateAccountID,
comment,
optimisticTransaction,
undefined,
optimisticReportPreviewActionID,
delegateAccountID,
);
chatReport.lastVisibleActionCreated = reportPreviewAction.created;

Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/RejectMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ function prepareRejectMoneyRequestData({
delegateAccountIDParam: delegateAccountID,
});

reportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, newExpenseReport, getCurrencyDecimals, undefined, transaction, undefined, undefined, delegateAccountID);
reportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, newExpenseReport, getCurrencyDecimals, delegateAccountID, undefined, transaction);
// The reject action posted below already tells the user this expense left the report,
// so a MOVED_TRANSACTION action in the same thread would repeat it
createdIOUReportActionID = iouAction.reportActionID;
Expand Down
11 changes: 1 addition & 10 deletions src/libs/actions/IOU/SendInvoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,16 +737,7 @@ function getSendInvoiceInformation({
}

// STEP 5: Build optimistic reportActions.
const reportPreviewAction = buildOptimisticReportPreview(
chatReport,
optimisticInvoiceReport,
getCurrencyDecimals,
trimmedComment,
optimisticTransaction,
undefined,
undefined,
delegateAccountID,
);
const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticInvoiceReport, getCurrencyDecimals, delegateAccountID, trimmedComment, optimisticTransaction);
optimisticInvoiceReport.parentReportActionID = reportPreviewAction.reportActionID;
chatReport.lastVisibleActionCreated = reportPreviewAction.created;
const [optimisticCreatedActionForChat, optimisticCreatedActionForIOUReport, iouAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] =
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/SendMoney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function getSendMoneyParams({
delegateAccountIDParam: delegateAccountID,
});

const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticIOUReport, getCurrencyDecimals, undefined, undefined, undefined, undefined, delegateAccountID);
const reportPreviewAction = buildOptimisticReportPreview(chatReport, optimisticIOUReport, getCurrencyDecimals, delegateAccountID);

// Change the method to set for new reports because it doesn't exist yet, is faster,
// and we need the data to be available when we navigate to the chat page
Expand Down
22 changes: 2 additions & 20 deletions src/libs/actions/IOU/Split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,16 +1148,7 @@ function completeSplitBill({
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction, getCurrencyDecimals);
} else {
oneOnOneReportPreviewAction = buildOptimisticReportPreview(
oneOnOneChatReport,
oneOnOneIOUReport,
getCurrencyDecimals,
'',
oneOnOneTransaction,
undefined,
undefined,
delegateAccountID,
);
oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, getCurrencyDecimals, delegateAccountID, '', oneOnOneTransaction);
}
const hasViolations = hasViolationsReportUtils(oneOnOneIOUReport.reportID, transactionViolations, sessionAccountID, sessionEmail ?? '');

Expand Down Expand Up @@ -1933,16 +1924,7 @@ function createSplitsAndOnyxData({
if (oneOnOneReportPreviewAction) {
oneOnOneReportPreviewAction = updateReportPreview(oneOnOneIOUReport, oneOnOneReportPreviewAction, getCurrencyDecimals);
} else {
oneOnOneReportPreviewAction = buildOptimisticReportPreview(
oneOnOneChatReport,
oneOnOneIOUReport,
getCurrencyDecimals,
'',
oneOnOneTransaction,
undefined,
undefined,
delegateAccountID,
);
oneOnOneReportPreviewAction = buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport, getCurrencyDecimals, delegateAccountID, '', oneOnOneTransaction);
}

const optimisticPolicyRecentlyUsedCategories = isPolicyExpenseChat ? mergePolicyRecentlyUsedCategories(category, policyRecentlyUsedCategories) : [];
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/IOU/TrackExpense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
if (reportPreviewAction) {
reportPreviewAction = updateReportPreview(iouReport, reportPreviewAction, getCurrencyDecimals, false, comment, optimisticTransaction);
} else {
reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimals, comment, optimisticTransaction, undefined, undefined, delegateAccountID);
reportPreviewAction = buildOptimisticReportPreview(chatReport, iouReport, getCurrencyDecimals, delegateAccountID, comment, optimisticTransaction);
// Generated ReportPreview action is a parent report action of the iou report.
// We are setting the iou report's parentReportActionID to display subtitle correctly in IOU page when offline.
iouReport.parentReportActionID = reportPreviewAction.reportActionID;
Expand Down
13 changes: 10 additions & 3 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7945,6 +7945,7 @@ function buildOptimisticChangePolicyData({
isTrackIntentUser,
getCurrencyDecimals,
rules,
delegateAccountID,
}: {
report: Report;
parentReport: OnyxEntry<Report>;
Expand All @@ -7961,6 +7962,7 @@ function buildOptimisticChangePolicyData({
isTrackIntentUser: boolean | undefined;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
rules: OnyxCollection<Rule>;
delegateAccountID: number | undefined;
}) {
const optimisticData: Array<
OnyxUpdate<
Expand Down Expand Up @@ -8192,8 +8194,7 @@ function buildOptimisticChangePolicyData({
// 3. Optimistically create a new REPORT_PREVIEW reportAction with the newReportPreviewActionID
// and set it as a parent of the moved report
const policyExpenseChat = optimisticPolicyExpenseChatReport ?? getPolicyExpenseChat(report.ownerAccountID, policy.id);
// TODO: delegateAccountIDParam will be threaded in PR 15 (https://github.com/Expensify/App/issues/66425)
const optimisticReportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, report, getCurrencyDecimals, '', null, undefined, undefined, undefined);
const optimisticReportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, report, getCurrencyDecimals, delegateAccountID, '', null);

const newPolicyExpenseChatReportID = policyExpenseChat?.reportID;

Expand Down Expand Up @@ -8247,7 +8248,7 @@ function buildOptimisticChangePolicyData({
});

// 4. Optimistically create a CHANGE_POLICY reportAction on the report using the reportActionID
const optimisticMovedReportAction = buildOptimisticChangePolicyReportAction(report.policyID, policy.id, currentUserAccountID);
const optimisticMovedReportAction = buildOptimisticChangePolicyReportAction(report.policyID, policy.id, currentUserAccountID, delegateAccountID);
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
Expand Down Expand Up @@ -8445,6 +8446,7 @@ function changeReportPolicy({
getCurrencyDecimals,
reportTransactions,
rules,
delegateAccountID,
}: {
report: Report;
parentReport: OnyxEntry<Report>;
Expand All @@ -8462,6 +8464,7 @@ function changeReportPolicy({
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
reportTransactions: Transaction[];
rules: OnyxCollection<Rule>;
delegateAccountID: number | undefined;
}) {
if (!report || !policy || report.policyID === policy.id || !isExpenseReport(report) || shouldBlockChangeReportPolicyForMapOrGPSRequirement(reportTransactions, policy)) {
return;
Expand All @@ -8482,6 +8485,7 @@ function changeReportPolicy({
isTrackIntentUser,
getCurrencyDecimals,
rules,
delegateAccountID,
});

const params = {
Expand Down Expand Up @@ -8518,6 +8522,7 @@ function changeReportPolicyAndInviteSubmitter({
getCurrencyDecimals,
reportTransactions,
rules,
delegateAccountID,
}: {
report: Report;
parentReport: OnyxEntry<Report>;
Expand All @@ -8536,6 +8541,7 @@ function changeReportPolicyAndInviteSubmitter({
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
reportTransactions: Transaction[];
rules: OnyxCollection<Rule>;
delegateAccountID: number | undefined;
}) {
if (
!report.reportID ||
Expand Down Expand Up @@ -8599,6 +8605,7 @@ function changeReportPolicyAndInviteSubmitter({
isTrackIntentUser,
getCurrencyDecimals,
rules,
delegateAccountID,
});

const optimisticData = [...optimisticAddMembersData, ...optimisticChangePolicyData];
Expand Down
4 changes: 4 additions & 0 deletions src/pages/DynamicReportChangeWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import useBlockDistanceRequest from '@hooks/useBlockDistanceRequest';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDebouncedState from '@hooks/useDebouncedState';
import useDelegateAccountID from '@hooks/useDelegateAccountID';
import useDynamicBackPath from '@hooks/useDynamicBackPath';
import {useIsAppLoadPending} from '@hooks/useInFlightRequests';
import useIsInLandscapeMode from '@hooks/useIsInLandscapeMode';
Expand Down Expand Up @@ -101,6 +102,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const session = useSession();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const delegateAccountID = useDelegateAccountID();
const hasViolations = hasViolationsReportUtils(report?.reportID, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? '');
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [userBillingGracePeriods] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
Expand Down Expand Up @@ -201,6 +203,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace
isTrackIntentUser,
reportTransactions,
rules,
delegateAccountID,
});
refreshSearch();
return;
Expand All @@ -223,6 +226,7 @@ function DynamicReportChangeWorkspacePage({report}: DynamicReportChangeWorkspace
isTrackIntentUser,
reportTransactions,
rules,
delegateAccountID,
});
refreshSearch();
};
Expand Down
Loading
Loading