Skip to content

Commit

Permalink
delete cache for transaction receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Feb 26, 2024
1 parent f7ed37e commit abd5347
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/Attachments/AttachmentView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ function AttachmentView({
const encryptedSourceUrl = isAuthTokenRequired ? addEncryptedAuthTokenToURL(source) : source;

const onPDFLoadComplete = (path) => {
if (reportActionID && path) {
CachedPDFPaths.add(reportActionID, path);
if (path && (transaction.transactionID || reportActionID)) {
CachedPDFPaths.add(transaction.transactionID || reportActionID, path);
}
if (!loadComplete) {
setLoadComplete(true);
Expand Down
10 changes: 5 additions & 5 deletions src/libs/actions/CachedPDFPaths/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Onyx.connect({
},
});

const add: Add = (reportActionID: string, path: string) => {
if (pdfPaths[reportActionID]) {
const add: Add = (id: string, path: string) => {
if (pdfPaths[id]) {
return Promise.resolve();
}
return Onyx.merge(ONYXKEYS.CACHED_PDF_PATHS, {[reportActionID]: path});
return Onyx.merge(ONYXKEYS.CACHED_PDF_PATHS, {[id]: path});
};

const clear: Clear = (path: string) => {
Expand All @@ -36,8 +36,8 @@ const clear: Clear = (path: string) => {
});
};

const clearByKey: ClearByKey = (reportActionID: string) => {
clear(pdfPaths[reportActionID] ?? '').then(() => Onyx.merge(ONYXKEYS.CACHED_PDF_PATHS, {[reportActionID]: null}));
const clearByKey: ClearByKey = (id: string) => {
clear(pdfPaths[id] ?? '').then(() => Onyx.merge(ONYXKEYS.CACHED_PDF_PATHS, {[id]: null}));
};

const clearAll: ClearAll = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/CachedPDFPaths/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type Add = (reportActionID: string, path: string) => Promise<void>;
type Add = (id: string, path: string) => Promise<void>;
type Clear = (path: string) => Promise<void>;
type ClearAll = () => void;
type ClearByKey = (reportActionID: string) => void;
type ClearByKey = (id: string) => void;

export type {Add, Clear, ClearAll, ClearByKey};
2 changes: 2 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import type {OnyxData} from '@src/types/onyx/Request';
import type {Comment, Receipt, ReceiptSource, TaxRate, TransactionChanges, WaypointCollection} from '@src/types/onyx/Transaction';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import * as CachedPDFPaths from './CachedPDFPaths';
import * as Policy from './Policy';
import * as Report from './Report';

Expand Down Expand Up @@ -3139,6 +3140,7 @@ function deleteMoneyRequest(transactionID: string, reportAction: OnyxTypes.Repor

// STEP 6: Make the API request
API.write(WRITE_COMMANDS.DELETE_MONEY_REQUEST, parameters, {optimisticData, successData, failureData});
CachedPDFPaths.clearByKey(transactionID);

// STEP 7: Navigate the user depending on which page they are on and which resources were deleted
if (iouReport && isSingleTransactionView && shouldDeleteTransactionThread && !shouldDeleteIOUReport) {
Expand Down

0 comments on commit abd5347

Please sign in to comment.