Skip to content

Commit f660f73

Browse files
authored
Merge pull request Expensify#65360 from dukenv0307/fix/65027
Excluded User Still Sees “Your Split” Label in Split Expense UI
2 parents b7032b5 + 3f37988 commit f660f73

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/libs/TransactionPreviewUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {TranslationPaths} from '@src/languages/types';
55
import ROUTES from '@src/ROUTES';
66
import type * as OnyxTypes from '@src/types/onyx';
77
import {isEmptyObject} from '@src/types/utils/EmptyObject';
8+
import {getCurrentUserAccountID} from './actions/Report';
89
import {abandonReviewDuplicateTransactions, setReviewDuplicatesKey} from './actions/Transaction';
910
import {isCategoryMissing} from './CategoryUtils';
1011
import {convertToDisplayString} from './CurrencyUtils';
@@ -325,8 +326,8 @@ function createTransactionPreviewConditionals({
325326

326327
// When there are no settled transactions in duplicates, show the "Keep this one" button
327328
const shouldShowKeepButton = areThereDuplicates;
328-
const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0;
329-
329+
const participantAccountIDs = isMoneyRequestAction(action) && isBillSplit ? (getOriginalMessage(action)?.participantAccountIDs ?? []) : [];
330+
const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0 && participantAccountIDs.includes(getCurrentUserAccountID());
330331
/*
331332
Show the merchant for IOUs and expenses only if:
332333
- the merchant is not empty, is custom, or is not related to scanning smartscan;

tests/unit/TransactionPreviewUtils.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ describe('TransactionPreviewUtils', () => {
180180
});
181181

182182
describe('createTransactionPreviewConditionals', () => {
183+
beforeAll(() => {
184+
Onyx.merge(ONYXKEYS.SESSION, {accountID: 999});
185+
});
186+
afterAll(() => {
187+
Onyx.clear([ONYXKEYS.SESSION]);
188+
});
189+
183190
it('should determine RBR visibility according to violation and hold conditions', () => {
184191
const functionArgs = {
185192
...basicProps,
@@ -208,6 +215,15 @@ describe('TransactionPreviewUtils', () => {
208215
transactionDetails: {
209216
amount: 1,
210217
},
218+
action: {
219+
...basicProps.action,
220+
originalMessage: {
221+
participantAccountIDs: [999],
222+
amount: 100,
223+
currency: 'USD',
224+
type: CONST.REPORT.ACTIONS.TYPE.IOU,
225+
},
226+
},
211227
};
212228
const result = createTransactionPreviewConditionals(functionArgs);
213229
expect(result.shouldShowSplitShare).toBeTruthy();
@@ -261,6 +277,35 @@ describe('TransactionPreviewUtils', () => {
261277
const result = createTransactionPreviewConditionals(functionArgs);
262278
expect(result.shouldShowDescription).toBeTruthy();
263279
});
280+
281+
it('should show split share only if user is part of the split bill transaction', () => {
282+
const functionArgs = {
283+
...basicProps,
284+
isBillSplit: true,
285+
transactionDetails: {amount: 100},
286+
action: {
287+
...basicProps.action,
288+
originalMessage: {
289+
participantAccountIDs: [999],
290+
amount: 100,
291+
currency: 'USD',
292+
type: CONST.REPORT.ACTIONS.TYPE.IOU,
293+
},
294+
},
295+
};
296+
const result = createTransactionPreviewConditionals(functionArgs);
297+
expect(result.shouldShowSplitShare).toBeTruthy();
298+
});
299+
300+
it('should not show split share if user is not a participant', () => {
301+
const functionArgs = {
302+
...basicProps,
303+
isBillSplit: true,
304+
transactionDetails: {amount: 100},
305+
};
306+
const result = createTransactionPreviewConditionals(functionArgs);
307+
expect(result.shouldShowSplitShare).toBeFalsy();
308+
});
264309
});
265310

266311
describe('getViolationTranslatePath', () => {

0 commit comments

Comments
 (0)