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
7 changes: 5 additions & 2 deletions src/libs/actions/ImportTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function buildTransactionListFromSpreadsheet(spreadsheet: ImportedSpreadsheet, s
/**
* Creates an optimistic card object for the imported transactions
*/
function buildOptimisticCard(cardDisplayName: string, accountID: number): {card: Card; cardID: number} {
function buildOptimisticCard(cardDisplayName: string, accountID: number, isReimbursable: boolean): {card: Card; cardID: number} {
const cardID = generateCardID();
return {
cardID,
Expand All @@ -209,6 +209,9 @@ function buildOptimisticCard(cardDisplayName: string, accountID: number): {card:
scrapeMinDate: '',
fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.NONE,
lastUpdated: DateUtils.getDBTime(),
// Persist the user's reimbursable selection so the card details toggle matches it immediately,
// instead of falling back to the enabled default until the card is re-fetched from the server.
Comment on lines +212 to +213

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unecessary comment.

reimbursable: isReimbursable,
nameValuePairs: {
cardTitle: cardDisplayName,
} as Card['nameValuePairs'],
Expand Down Expand Up @@ -310,7 +313,7 @@ async function importTransactionsFromCSV(
if (isAddingToExistingCard) {
cardID = existingCardID;
} else {
const optimisticCardData = buildOptimisticCard(cardDisplayName, accountID);
const optimisticCardData = buildOptimisticCard(cardDisplayName, accountID, isReimbursable);
cardID = optimisticCardData.cardID;
optimisticCard = optimisticCardData.card;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/ImportTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,17 @@ describe('ImportTransactions', () => {
getRequiredOnyxUpdate(onyxData, 'optimisticData', ONYXKEYS.CARD_LIST, Onyx.METHOD.MERGE);
});

it('stores the reimbursable selection on the optimistic card', async () => {
const nonReimbursableSpreadsheet = {...validSpreadsheet, importTransactionSettings: {isReimbursable: false}};

await importTransactionsFromCSV(nonReimbursableSpreadsheet, CURRENT_USER_ACCOUNT_ID);

const [, , onyxData] = getRequiredWriteCall(writeSpy.mock.calls, 0);
const cardUpdate = getRequiredOnyxUpdate(onyxData, 'optimisticData', ONYXKEYS.CARD_LIST, Onyx.METHOD.MERGE, true);
const [optimisticCard] = Object.values(cardUpdate.value);
expect(optimisticCard).toEqual(expect.objectContaining({reimbursable: false}));
});

it('reuses an existingCardID without queuing an optimistic card', async () => {
const existingCardID = 987654321;

Expand Down
Loading