Skip to content

fix: reverting the amount and currency after error clearance. #55102

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

Merged
merged 20 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
const receiptFieldViolationNames: OnyxTypes.ViolationName[] = [CONST.VIOLATIONS.MODIFIED_AMOUNT, CONST.VIOLATIONS.MODIFIED_DATE];

const getTransactionID = (report: OnyxEntry<OnyxTypes.Report>, parentReportActions: OnyxEntry<OnyxTypes.ReportActions>) => {
const parentReportAction = parentReportActions?.[report?.parentReportActionID ?? '-1'];

Check failure on line 74 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const originalMessage = parentReportAction && ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction) : undefined;
return originalMessage?.IOUTransactionID ?? -1;

Check failure on line 76 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

};

function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = false, updatedTransaction, isFromReviewDuplicates = false}: MoneyRequestViewProps) {
Expand All @@ -81,8 +81,8 @@
const session = useSession();
const {isOffline} = useNetwork();
const {translate, toLocaleDigit} = useLocalize();
const parentReportID = report?.parentReportID ?? '-1';

Check failure on line 84 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const policyID = report?.policyID ?? '-1';

Check failure on line 85 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`);
const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReport?.parentReportID}`, {
selector: (chatReportValue) => chatReportValue && {reportID: chatReportValue.reportID, errorFields: chatReportValue.errorFields},
Expand All @@ -97,12 +97,12 @@
});
const [transactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${getTransactionID(report, parentReportActions)}`);

const parentReportAction = parentReportActions?.[report?.parentReportActionID ?? '-1'];

Check failure on line 100 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const isTrackExpense = ReportUtils.isTrackExpenseReport(report);
const moneyRequestReport = parentReport;
const linkedTransactionID = useMemo(() => {
const originalMessage = parentReportAction && ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction) : undefined;
return originalMessage?.IOUTransactionID ?? '-1';

Check failure on line 105 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

}, [parentReportAction]);

const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${linkedTransactionID}`);
Expand Down Expand Up @@ -227,7 +227,7 @@
if (newBillable === TransactionUtils.getBillable(transaction)) {
return;
}
IOU.updateMoneyRequestBillable(transaction?.transactionID ?? '-1', report?.reportID ?? '-1', newBillable, policy, policyTagList, policyCategories);

Check failure on line 230 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Check failure on line 230 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

},
[transaction, report, policy, policyTagList, policyCategories],
);
Expand Down Expand Up @@ -323,8 +323,8 @@
ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(
CONST.IOU.ACTION.EDIT,
iouType,
transaction?.transactionID ?? '-1',

Check failure on line 326 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

report?.reportID ?? '-1',

Check failure on line 327 in src/components/ReportActionItem/MoneyRequestView.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Navigation.getReportRHPActiveRoute(),
),
)
Expand Down Expand Up @@ -469,7 +469,7 @@
return;
}
}
Transaction.clearError(transaction?.transactionID ?? linkedTransactionID);
Transaction.clearError(transaction?.transactionID ?? linkedTransactionID, {});
ReportActions.clearAllRelatedReportActionErrors(report?.reportID ?? '-1', parentReportAction);
}}
>
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ function abandonReviewDuplicateTransactions() {
Onyx.set(ONYXKEYS.REVIEW_DUPLICATES, null);
}

function clearError(transactionID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {errors: null, errorFields: {route: null, waypoints: null, routes: null}});
function clearError(transactionID: string, oldTransactionValues: Partial<Transaction>) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {...oldTransactionValues, errors: null, errorFields: {route: null, waypoints: null, routes: null}});
}

function markAsCash(transactionID: string, transactionThreadReportID: string) {
Expand Down
30 changes: 27 additions & 3 deletions src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ type PureReportActionItemProps = {
isCurrentUserTheOnlyParticipant?: (participantAccountIDs?: number[]) => boolean;

/** Function to clear an error from a transaction */
clearError?: (transactionID: string) => void;
clearError?: (transactionID: string, oldTransactionValues: Partial<OnyxTypes.Transaction>) => void;

/** Function to clear all errors from a report action */
clearAllRelatedReportActionErrors?: (reportID: string, reportAction: OnyxTypes.ReportAction | null | undefined, ignore?: IgnoreDirection, keys?: string[]) => void;
Expand Down Expand Up @@ -1126,9 +1126,33 @@ function PureReportActionItem({
>
<OfflineWithFeedback
onClose={() => {
const transactionID = ReportActionsUtils.isMoneyRequestAction(action) ? ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID : undefined;
let transactionID;
let data = {};
if (ReportActionsUtils.isMoneyRequestAction(action)) {
transactionID = ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID;
} else if (ReportActionsUtils.isModifiedExpenseAction(action) && report?.reportID) {
const moneyRequestAction = Object.values(ReportActionsUtils.getAllReportActions(report?.reportID)).find(ReportActionsUtils.isMoneyRequestAction);
if (!moneyRequestAction) {
return;
}
transactionID = ReportActionsUtils.getOriginalMessage(moneyRequestAction)?.IOUTransactionID;
const moneyRequestActionOriginalMessage = ReportActionsUtils.getOriginalMessage(action);
if (
moneyRequestActionOriginalMessage &&
typeof moneyRequestActionOriginalMessage === 'object' &&
moneyRequestActionOriginalMessage.oldAmount &&
moneyRequestActionOriginalMessage.oldCurrency &&
'amount' in moneyRequestActionOriginalMessage &&
'currency' in moneyRequestActionOriginalMessage
) {
data = {
modifiedAmount: moneyRequestActionOriginalMessage.oldAmount,
modifiedCurrency: moneyRequestActionOriginalMessage.oldCurrency,
};
}
}
if (transactionID) {
clearError(transactionID);
clearError(transactionID, data);
}
clearAllRelatedReportActionErrors(reportID, action);
}}
Expand Down
Loading