From 6568086c7956df30d909d3654257eb7cfc7d9614 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 12 Jun 2025 23:11:55 +0100 Subject: [PATCH 1/5] Hide Create Expense for TU, hide Split for non-TU --- src/libs/ReportUtils.ts | 30 +++++++------ .../AttachmentPickerWithMenuItems.tsx | 6 --- tests/unit/ReportUtilsTest.ts | 45 +++++++++++++++++++ 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fb0dc176ab66..9cdaae20b683 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2343,10 +2343,6 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry, isRep return false; } - if (isInstantSubmitEnabled(policy) && isProcessingReport(moneyRequestReport)) { - return isAwaitingFirstLevelApproval(moneyRequestReport); - } - if (isReportApproved({report: moneyRequestReport}) || isClosedReport(moneyRequestReport) || isSettled(moneyRequestReport?.reportID)) { return false; } @@ -3473,7 +3469,7 @@ function getMoneyRequestSpendBreakdown(report: OnyxInputOrEntry, searchR if (nonReimbursableSpend + totalSpend !== 0) { // There is a possibility that if the Expense report has a negative total. // This is because there are instances where you can get a credit back on your card, - // or you enter a negative expense to “offset” future expenses + // or you enter a negative expense to "offset" future expenses nonReimbursableSpend = isExpenseReport(moneyRequestReport) ? nonReimbursableSpend * -1 : Math.abs(nonReimbursableSpend); totalSpend = isExpenseReport(moneyRequestReport) ? totalSpend * -1 : Math.abs(totalSpend); @@ -5652,7 +5648,7 @@ function buildOptimisticInvoiceReport( ownerAccountID: currentUserAccountID, managerID: receiverAccountID, currency, - // We don’t translate reportName because the server response is always in English + // We don't translate reportName because the server response is always in English reportName: `${receiverName} owes ${formattedTotal}`, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, statusNum: CONST.REPORT.STATUS_NUM.OPEN, @@ -8328,6 +8324,8 @@ function isGroupChatAdmin(report: OnyxEntry, accountID: number) { * as a participant of the report. */ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, reportParticipants: number[], filterDeprecatedTypes = false): IOUType[] { + const teacherUnitePolicyID = environment === CONST.ENVIRONMENT.PRODUCTION ? CONST.TEACHERS_UNITE.PROD_POLICY_ID : CONST.TEACHERS_UNITE.TEST_POLICY_ID; + // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation const reportNameValuePairs = getReportNameValuePairs(report?.reportID); @@ -8367,9 +8365,12 @@ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, policy: OnyxEntry 0) || - (isDM(report) && otherParticipants.length > 0) || - (isGroupChat(report) && otherParticipants.length > 0) || - (isPolicyExpenseChat(report) && report?.isOwnPolicyExpenseChat) + shouldShowSplitExpense && + ((isChatRoom(report) && !isAnnounceRoom(report) && otherParticipants.length > 0) || + (isDM(report) && otherParticipants.length > 0) || + (isGroupChat(report) && otherParticipants.length > 0) || + (isPolicyExpenseChat(report) && report?.isOwnPolicyExpenseChat)) ) { options = [...options, CONST.IOU.TYPE.SPLIT]; } diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 419d192d6869..60f9a99e9fa6 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -148,12 +148,6 @@ function AttachmentPickerWithMenuItems({ */ const moneyRequestOptions = useMemo(() => { const options: MoneyRequestOptions = { - [CONST.IOU.TYPE.SPLIT]: { - icon: Expensicons.Transfer, - text: translate('iou.splitExpense'), - shouldCallAfterModalHide: shouldUseNarrowLayout, - onSelected: () => selectOption(() => startMoneyRequest(CONST.IOU.TYPE.SPLIT, report?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)), true), - }, [CONST.IOU.TYPE.SUBMIT]: { icon: getIconForAction(CONST.IOU.TYPE.CREATE), text: translate('iou.createExpense'), diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index c6ad307cada7..fc06f1c0b4fc 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1181,6 +1181,51 @@ describe('ReportUtils', () => { expect(moneyRequestOptions.indexOf(CONST.IOU.TYPE.SUBMIT)).toBe(0); }); }); + + describe('Teachers Unite policy logic', () => { + const teachersUniteTestPolicyID = CONST.TEACHERS_UNITE.TEST_POLICY_ID; + const otherPolicyID = 'normal-policy-id'; + + it('should hide Create Expense option and show Split Expense for Teachers Unite policy', () => { + const report = { + ...LHNTestUtils.getFakeReport(), + policyID: teachersUniteTestPolicyID, + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + isOwnPolicyExpenseChat: true, + }; + + const moneyRequestOptions = temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); + + // Should not include SUBMIT (Create Expense) + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(false); + + // Should include SPLIT (Split Expense) + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); + + // Should include other options like TRACK + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); + }); + + it('should show Create Expense option and hide Split Expense for non-Teachers Unite policy', () => { + const report = { + ...LHNTestUtils.getFakeReport(), + policyID: otherPolicyID, + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + isOwnPolicyExpenseChat: true, + }; + + const moneyRequestOptions = temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); + + // Should include SUBMIT (Create Expense) + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); + + // Should not include SPLIT (Split Expense) + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(false); + + // Should include other options like TRACK + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); + }); + }); }); describe('getReportIDFromLink', () => { From 23302e0b9ed13b193b17e6fd337d4a4bdfb97cc8 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 12 Jun 2025 23:20:42 +0100 Subject: [PATCH 2/5] Hide Create Report for TU --- src/libs/ReportUtils.ts | 5 +++++ .../AttachmentPickerWithMenuItems.tsx | 6 ++++++ tests/unit/ReportUtilsTest.ts | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9cdaae20b683..e77d2c4a597b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8379,6 +8379,11 @@ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry option !== CONST.IOU.TYPE.SUBMIT); + } + // User created policy rooms and default rooms like #admins or #announce will always have the Split Expense option // unless there are no other participants at all (e.g. #admins room for a policy with only 1 admin) // DM chats will have the Split Expense option. diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 60f9a99e9fa6..419d192d6869 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -148,6 +148,12 @@ function AttachmentPickerWithMenuItems({ */ const moneyRequestOptions = useMemo(() => { const options: MoneyRequestOptions = { + [CONST.IOU.TYPE.SPLIT]: { + icon: Expensicons.Transfer, + text: translate('iou.splitExpense'), + shouldCallAfterModalHide: shouldUseNarrowLayout, + onSelected: () => selectOption(() => startMoneyRequest(CONST.IOU.TYPE.SPLIT, report?.reportID ?? String(CONST.DEFAULT_NUMBER_ID)), true), + }, [CONST.IOU.TYPE.SUBMIT]: { icon: getIconForAction(CONST.IOU.TYPE.CREATE), text: translate('iou.createExpense'), diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index fc06f1c0b4fc..b92097a0ac8b 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1225,6 +1225,24 @@ describe('ReportUtils', () => { // Should include other options like TRACK expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); }); + + it('should disable Create report option for expense chats on Teachers Unite workspace', () => { + const expenseReport = { + ...LHNTestUtils.getFakeReport(), + policyID: teachersUniteTestPolicyID, + type: CONST.REPORT.TYPE.EXPENSE, + chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, + isOwnPolicyExpenseChat: true, + }; + + const moneyRequestOptions = temporary_getMoneyRequestOptions(expenseReport, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); + + // Should not include SUBMIT (Create Expense/Create report) + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(false); + + // Should include TRACK (Track Expense) + expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); + }); }); }); From f4ab5822775187d6ef957a7054375712c5932531 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 12 Jun 2025 23:45:01 +0100 Subject: [PATCH 3/5] Fix logic --- src/libs/ReportUtils.ts | 10 +++++----- .../AttachmentPickerWithMenuItems.tsx | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e77d2c4a597b..2b877ca37768 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8325,6 +8325,7 @@ function isGroupChatAdmin(report: OnyxEntry, accountID: number) { */ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, reportParticipants: number[], filterDeprecatedTypes = false): IOUType[] { const teacherUnitePolicyID = environment === CONST.ENVIRONMENT.PRODUCTION ? CONST.TEACHERS_UNITE.PROD_POLICY_ID : CONST.TEACHERS_UNITE.TEST_POLICY_ID; + const isTeachersUniteReport = report?.policyID === teacherUnitePolicyID; // This will get removed as part of https://github.com/Expensify/App/issues/59961 // eslint-disable-next-line deprecation/deprecation @@ -8366,7 +8367,7 @@ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, policy: OnyxEntry option !== CONST.IOU.TYPE.SUBMIT); + options = options.filter((option) => option !== CONST.IOU.TYPE.SUBMIT); } // User created policy rooms and default rooms like #admins or #announce will always have the Split Expense option @@ -8389,9 +8390,8 @@ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry 0) || (isDM(report) && otherParticipants.length > 0) || (isGroupChat(report) && otherParticipants.length > 0) || diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 419d192d6869..736de9a67d56 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -10,6 +10,7 @@ import type {PopoverMenuItem} from '@components/PopoverMenu'; import PopoverMenu from '@components/PopoverMenu'; import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; import Tooltip from '@components/Tooltip/PopoverAnchorTooltip'; +import useEnvironment from '@hooks/useEnvironment'; import useLocalize from '@hooks/useLocalize'; import usePrevious from '@hooks/usePrevious'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; @@ -131,6 +132,7 @@ function AttachmentPickerWithMenuItems({ const {isDelegateAccessRestricted} = useDelegateUserDetails(); const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true}); + const {isProduction} = useEnvironment(); const selectOption = useCallback( (onSelected: () => void, shouldRestrictAction: boolean) => { @@ -143,6 +145,10 @@ function AttachmentPickerWithMenuItems({ }, [policy], ); + + const teacherUnitePolicyID = isProduction ? CONST.TEACHERS_UNITE.PROD_POLICY_ID : CONST.TEACHERS_UNITE.TEST_POLICY_ID; + const isTeachersUniteReport = report?.policyID === teacherUnitePolicyID; + /** * Returns the list of IOU Options */ @@ -285,7 +291,7 @@ function AttachmentPickerWithMenuItems({ }; const menuItems = [ ...moneyRequestOptions, - ...createReportOption, + ...(!isTeachersUniteReport ? createReportOption : []), ...taskOption, { icon: Expensicons.Paperclip, From d5051c8823077b514c7f1bdb57809abefd7c56f1 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Thu, 12 Jun 2025 23:49:51 +0100 Subject: [PATCH 4/5] Cleanup --- src/libs/ReportUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2b877ca37768..355368d42656 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2343,6 +2343,10 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry, isRep return false; } + if (isInstantSubmitEnabled(policy) && isProcessingReport(moneyRequestReport)) { + return isAwaitingFirstLevelApproval(moneyRequestReport); + } + if (isReportApproved({report: moneyRequestReport}) || isClosedReport(moneyRequestReport) || isSettled(moneyRequestReport?.reportID)) { return false; } From 2f6aefa2021f58b64ef6855f3a52c588fac20599 Mon Sep 17 00:00:00 2001 From: Youssef Lourayad Date: Fri, 13 Jun 2025 00:23:15 +0100 Subject: [PATCH 5/5] Fix test --- src/libs/ReportUtils.ts | 11 +++++------ tests/unit/ReportUtilsTest.ts | 11 ++--------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 355368d42656..1dbb57a5f8d1 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8379,7 +8379,7 @@ function getMoneyRequestOptions(report: OnyxEntry, policy: OnyxEntry, policy: OnyxEntry 0) || - (isDM(report) && otherParticipants.length > 0) || - (isGroupChat(report) && otherParticipants.length > 0) || - (isPolicyExpenseChat(report) && report?.isOwnPolicyExpenseChat)) + (isChatRoom(report) && !isAnnounceRoom(report) && otherParticipants.length > 0) || + (isDM(report) && otherParticipants.length > 0) || + (isGroupChat(report) && otherParticipants.length > 0) || + (isPolicyExpenseChat(report) && report?.isOwnPolicyExpenseChat && isTeachersUniteReport) ) { options = [...options, CONST.IOU.TYPE.SPLIT]; } diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index b92097a0ac8b..feb74c4b925d 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -1174,9 +1174,8 @@ describe('ReportUtils', () => { managerID: currentUserAccountID, }; const moneyRequestOptions = temporary_getMoneyRequestOptions(report, undefined, [currentUserAccountID, ...participantsAccountIDs]); - expect(moneyRequestOptions.length).toBe(3); + expect(moneyRequestOptions.length).toBe(2); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(true); - expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); expect(moneyRequestOptions.indexOf(CONST.IOU.TYPE.SUBMIT)).toBe(0); }); @@ -1201,9 +1200,6 @@ describe('ReportUtils', () => { // Should include SPLIT (Split Expense) expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SPLIT)).toBe(true); - - // Should include other options like TRACK - expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); }); it('should show Create Expense option and hide Split Expense for non-Teachers Unite policy', () => { @@ -1237,11 +1233,8 @@ describe('ReportUtils', () => { const moneyRequestOptions = temporary_getMoneyRequestOptions(expenseReport, undefined, [currentUserAccountID, participantsAccountIDs.at(0) ?? CONST.DEFAULT_NUMBER_ID]); - // Should not include SUBMIT (Create Expense/Create report) + // Should not include SUBMIT expect(moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT)).toBe(false); - - // Should include TRACK (Track Expense) - expect(moneyRequestOptions.includes(CONST.IOU.TYPE.TRACK)).toBe(true); }); }); });