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
17 changes: 16 additions & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1962,7 +1962,22 @@ function MoneyReportHeader({
icon: expensifyIcons.CircularArrowBackwards,
value: CONST.REPORT.SECONDARY_ACTIONS.RETRACT,
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.RETRACT,
onSelected: () => {
onSelected: async () => {
if (isExported) {
const result = await showConfirmModal({
title: translate('iou.reopenReport'),
prompt: reopenExportedReportWarningText,
confirmText: translate('iou.reopenReport'),
cancelText: translate('common.cancel'),
danger: true,
});

if (result.action !== ModalActions.CONFIRM) {
return;
}
retractReport(moneyRequestReport, chatReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep);
return;
}
retractReport(moneyRequestReport, chatReport, policy, accountID, email ?? '', hasViolations, isASAPSubmitBetaEnabled, nextStep);
},
},
Expand Down
19 changes: 17 additions & 2 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {

Check warning on line 374 in src/libs/actions/Report/index.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
return;
}
const reportID = CollectionUtils.extractCollectionItemID(key);
Expand All @@ -383,7 +383,7 @@
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {

Check warning on line 386 in src/libs/actions/Report/index.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
allReports = value;
},
});
Expand All @@ -392,7 +392,7 @@
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};

Check warning on line 395 in src/libs/actions/Report/index.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
},
});

Expand All @@ -410,7 +410,7 @@
Onyx.connect({
key: ONYXKEYS.NVP_ONBOARDING,
callback: (val) => {
if (Array.isArray(val)) {

Check warning on line 413 in src/libs/actions/Report/index.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
return;
}
onboarding = val;
Expand Down Expand Up @@ -5299,18 +5299,26 @@
function exportToIntegration(reportID: string, connectionName: ConnectionName) {
const action = buildOptimisticExportIntegrationAction(connectionName);
const optimisticReportActionID = action.reportActionID;
const previousExportedValue = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.isExportedToIntegration;

const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>> = [
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>> = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[optimisticReportActionID]: action,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
isExportedToIntegration: true,
},
},
];

const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS>> = [
const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>> = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
Expand All @@ -5320,6 +5328,13 @@
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
value: {
isExportedToIntegration: previousExportedValue,
},
Comment on lines +5334 to +5336
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore prior export state on export API failure

In exportToIntegration(), the failure path always writes isExportedToIntegration: false, which is incorrect when the user is re-exporting a report that was already exported. If the write fails (for example offline or transient network error), this clears the exported flag in Onyx even though the report is still exported, and ReportUtils.isExported() will trust that false value over action history, so follow-up safeguards (like re-export/reopen warnings) stop appearing until state is re-synced. Please preserve and restore the previous value (similar to markAsManuallyExported) instead of hard-coding false.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot Fix this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 638147a. Changed exportToIntegration() to capture previousExportedValue from Onyx before the optimistic update and restore it in failure data, matching the pattern already used in markAsManuallyExported().

},
];

const params = {
Expand Down
Loading