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
14 changes: 9 additions & 5 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useRoute} from '@react-navigation/native';
import {isUserValidatedSelector} from '@selectors/Account';
import {delegateEmailSelector, isUserValidatedSelector} from '@selectors/Account';
import {hasSeenTourSelector} from '@selectors/Onboarding';
import passthroughPolicyTagListSelector from '@selectors/PolicyTagList';
import {validTransactionDraftsSelector} from '@selectors/TransactionDraft';
Expand Down Expand Up @@ -223,6 +223,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
const [isUserValidated] = useOnyx(ONYXKEYS.ACCOUNT, {
selector: isUserValidatedSelector,
});
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`);
const [session] = useOnyx(ONYXKEYS.SESSION);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
Expand Down Expand Up @@ -855,6 +856,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
startSubmittingAnimation();
},
ownerBillingGracePeriodEnd,
delegateEmail,
});
if (currentSearchQueryJSON && !isOffline) {
search({
Expand Down Expand Up @@ -892,6 +894,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
clearSelectedTransactions,
confirmPendingRTERAndProceed,
ownerBillingGracePeriodEnd,
delegateEmail,
],
);

Expand Down Expand Up @@ -1438,6 +1441,7 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
userBillingGracePeriodEnds,
amountOwed,
ownerBillingGracePeriodEnd,
delegateEmail,
});
});
},
Expand Down Expand Up @@ -1472,11 +1476,11 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
if (result.action !== ModalActions.CONFIRM) {
return;
}
unapproveExpenseReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep);
unapproveExpenseReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, delegateEmail);
return;
}

unapproveExpenseReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep);
unapproveExpenseReport(moneyRequestReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, delegateEmail);
},
},
[CONST.REPORT.SECONDARY_ACTIONS.CANCEL_PAYMENT]: {
Expand Down Expand Up @@ -1814,10 +1818,10 @@ function MoneyReportHeader({reportID: reportIDProp, shouldDisplayBackButton = fa
if (result.action !== ModalActions.CONFIRM) {
return;
}
retractReport(moneyRequestReport, chatReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep);
retractReport(moneyRequestReport, chatReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, delegateEmail);
return;
}
retractReport(moneyRequestReport, chatReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep);
retractReport(moneyRequestReport, chatReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep, delegateEmail);
},
},
[CONST.REPORT.SECONDARY_ACTIONS.REOPEN]: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {delegateEmailSelector} from '@selectors/Account';
import React from 'react';
import AnimatedSubmitButton from '@components/AnimatedSubmitButton';
import {useSearchStateContext} from '@components/Search/SearchContext';
Expand Down Expand Up @@ -42,6 +43,7 @@ function SubmitPrimaryAction({reportID, isSubmittingAnimationRunning, stopAnimat
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});

const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const {reportActions: unfilteredReportActions} = usePaginatedReportActions(moneyRequestReport?.reportID);
Expand Down Expand Up @@ -90,6 +92,7 @@ function SubmitPrimaryAction({reportID, isSubmittingAnimationRunning, stopAnimat
amountOwed,
onSubmitted: startSubmittingAnimation,
ownerBillingGracePeriodEnd,
delegateEmail,
});
if (currentSearchQueryJSON && !isOffline) {
search({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {delegateEmailSelector} from '@selectors/Account';
import React from 'react';
import AnimatedSubmitButton from '@components/AnimatedSubmitButton';
import useConfirmPendingRTERAndProceed from '@hooks/useConfirmPendingRTERAndProceed';
Expand Down Expand Up @@ -37,6 +38,7 @@ function SubmitActionButton({iouReportID, chatReportID, isSubmittingAnimationRun
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`);
const [delegateEmail] = useOnyx(ONYXKEYS.ACCOUNT, {selector: delegateEmailSelector});
const {isOffline} = useNetwork();
const transactions = getReportTransactions(iouReportID).filter((t) => isOffline || t.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);

Expand Down Expand Up @@ -79,6 +81,7 @@ function SubmitActionButton({iouReportID, chatReportID, isSubmittingAnimationRun
amountOwed,
onSubmitted: startSubmittingAnimation,
ownerBillingGracePeriodEnd,
delegateEmail,
});
});
}}
Expand Down
11 changes: 6 additions & 5 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1058 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1063,7 +1063,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1066 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1081,7 +1081,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1084 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (deprecatedCurrentUserAccountID) {
Expand All @@ -1093,7 +1093,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1096 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1101,7 +1101,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1104 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1111,7 +1111,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1114 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1119,7 +1119,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1122 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1155,14 +1155,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1158 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1165 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1188,7 +1188,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1191 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -7366,8 +7366,8 @@
/**
* Builds an optimistic APPROVED report action with a randomly generated reportActionID.
*/
function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string): OptimisticUnapprovedReportAction {
const delegateAccountDetails = getPersonalDetailByEmail(delegateEmail);
function buildOptimisticUnapprovedReportAction(amount: number, currency: string, expenseReportID: string, delegateEmailParam: string | undefined): OptimisticUnapprovedReportAction {
const delegateAccountDetails = delegateEmailParam ? getPersonalDetailByEmail(delegateEmailParam) : undefined;
return {
actionName: CONST.REPORT.ACTIONS.TYPE.UNAPPROVED,
actorAccountID: deprecatedCurrentUserAccountID,
Expand Down Expand Up @@ -7599,6 +7599,7 @@
expenseReportID: string,
adminAccountID: number | undefined,
workflow: ValueOf<typeof CONST.POLICY.APPROVAL_MODE> | undefined,
delegateEmailParam: string | undefined,
): OptimisticSubmittedReportAction {
const originalMessage = {
amount,
Expand All @@ -7607,7 +7608,7 @@
workflow,
};

const delegateAccountDetails = getPersonalDetailByEmail(delegateEmail);
const delegateAccountDetails = delegateEmailParam ? getPersonalDetailByEmail(delegateEmailParam) : undefined;

return {
actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
Expand Down Expand Up @@ -8268,7 +8269,7 @@
};
}

function buildOptimisticRetractedReportAction(created = DateUtils.getDBTime()): OptimisticRetractedReportAction {
function buildOptimisticRetractedReportAction(delegateEmailParam: string | undefined, created = DateUtils.getDBTime()): OptimisticRetractedReportAction {
return {
reportActionID: rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.RETRACTED,
Expand All @@ -8292,7 +8293,7 @@
avatar: getCurrentUserAvatar(),
created,
shouldShow: true,
delegateAccountID: getPersonalDetailByEmail(delegateEmail)?.accountID,
delegateAccountID: delegateEmailParam ? getPersonalDetailByEmail(delegateEmailParam)?.accountID : undefined,
};
}

Expand Down
9 changes: 7 additions & 2 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ type SubmitReportFunctionParams = {
amountOwed: OnyxEntry<number>;
onSubmitted?: () => void;
ownerBillingGracePeriodEnd: OnyxEntry<number>;
delegateEmail: string | undefined;
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Expand Down Expand Up @@ -7773,12 +7774,13 @@ function retractReport(
hasViolations: boolean,
isASAPSubmitBetaEnabled: boolean,
expenseReportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>,
delegateEmail: string | undefined,
) {
if (!expenseReport) {
return;
}

const optimisticRetractReportAction = buildOptimisticRetractedReportAction();
const optimisticRetractReportAction = buildOptimisticRetractedReportAction(delegateEmail);
const predictedNextState = CONST.REPORT.STATE_NUM.OPEN;
const predictedNextStatus = CONST.REPORT.STATUS_NUM.OPEN;

Expand Down Expand Up @@ -7946,12 +7948,13 @@ function unapproveExpenseReport(
hasViolations: boolean,
isASAPSubmitBetaEnabled: boolean,
expenseReportCurrentNextStepDeprecated: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>,
delegateEmail: string | undefined,
) {
if (isEmptyObject(expenseReport)) {
return;
}

const optimisticUnapprovedReportAction = buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID);
const optimisticUnapprovedReportAction = buildOptimisticUnapprovedReportAction(expenseReport.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, delegateEmail);

// buildOptimisticNextStep is used in parallel
// eslint-disable-next-line @typescript-eslint/no-deprecated
Expand Down Expand Up @@ -8113,6 +8116,7 @@ function submitReport({
amountOwed,
onSubmitted,
ownerBillingGracePeriodEnd,
delegateEmail,
}: SubmitReportFunctionParams) {
if (!expenseReport) {
return;
Expand All @@ -8132,6 +8136,7 @@ function submitReport({
expenseReport.reportID,
adminAccountID,
policy?.approvalMode,
delegateEmail,
);
const isDEWPolicy = hasDynamicExternalWorkflow(policy);
// For DEW policies, only add optimistic submit action when offline
Expand Down
Loading
Loading