Skip to content

Commit e243b65

Browse files
authored
Merge pull request Expensify#67510 from linhvovan29546/fix/66731-do-not-show-qab-for-mctest-and-create-report
Update QAB so we don't show Manager McTest OR a second Create Reports option
2 parents 6b0b4f9 + 60eb9ba commit e243b65

7 files changed

Lines changed: 51 additions & 97 deletions

File tree

src/libs/QuickActionUtils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {Policy, Report} from '@src/types/onyx';
66
import type {QuickActionName} from '@src/types/onyx/QuickAction';
77
import type QuickAction from '@src/types/onyx/QuickAction';
88
import getIconForAction from './getIconForAction';
9-
import {shouldShowPolicy} from './PolicyUtils';
109
import {canCreateRequest} from './ReportUtils';
1110

1211
const getQuickActionIcon = (action: QuickActionName): React.FC<SvgProps> => {
@@ -85,23 +84,31 @@ const getQuickActionTitle = (action: QuickActionName): TranslationPaths => {
8584
return 'quickAction.paySomeone';
8685
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
8786
return 'quickAction.assignTask';
88-
case CONST.QUICK_ACTIONS.CREATE_REPORT:
89-
return 'quickAction.createReport';
9087
default:
9188
return '' as TranslationPaths;
9289
}
9390
};
91+
const isManagerMcTestQuickActionReport = (report: Report | undefined) => {
92+
return !!report?.participants?.[CONST.ACCOUNT_ID.MANAGER_MCTEST];
93+
};
9494

9595
const isQuickActionAllowed = (quickAction: QuickAction, quickActionReport: Report | undefined, quickActionPolicy: Policy | undefined, isReportArchived = false) => {
9696
const iouType = getIOUType(quickAction?.action);
9797
if (iouType) {
98+
// We're disabling QAB for Manager McTest reports to prevent confusion when submitting real data for Manager McTest
99+
const isReportHasManagerMCTest = isManagerMcTestQuickActionReport(quickActionReport);
100+
if (isReportHasManagerMCTest) {
101+
return false;
102+
}
98103
return canCreateRequest(quickActionReport, quickActionPolicy, iouType, isReportArchived);
99104
}
100105
if (quickAction?.action === CONST.QUICK_ACTIONS.PER_DIEM) {
101106
return !!quickActionPolicy?.arePerDiemRatesEnabled;
102107
}
108+
// We don't want to show this QAB since this is already available in the FloatingActionButtonAndPopover
109+
// In the future, we will remove this when the BE no longer returns this action
103110
if (quickAction?.action === CONST.QUICK_ACTIONS.CREATE_REPORT) {
104-
return shouldShowPolicy(quickActionPolicy, false, undefined) && !!quickActionPolicy?.isPolicyExpenseChatEnabled;
111+
return false;
105112
}
106113
return true;
107114
};

src/libs/actions/QuickActionNavigation.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
2-
import Navigation from '@libs/Navigation/Navigation';
31
import {generateReportID} from '@libs/ReportUtils';
42
import CONST from '@src/CONST';
5-
import ROUTES from '@src/ROUTES';
6-
import type {PersonalDetails} from '@src/types/onyx';
73
import type {QuickActionName} from '@src/types/onyx/QuickAction';
84
import type QuickAction from '@src/types/onyx/QuickAction';
95
import type {IOURequestType} from './IOU';
106
import {startMoneyRequest} from './IOU';
11-
import {createNewReport} from './Report';
127
import {startOutCreateTaskQuickAction} from './Task';
138

149
function getQuickActionRequestType(action: QuickActionName | undefined): IOURequestType | undefined {
@@ -30,13 +25,7 @@ function getQuickActionRequestType(action: QuickActionName | undefined): IOURequ
3025
return requestType;
3126
}
3227

33-
function navigateToQuickAction(
34-
isValidReport: boolean,
35-
quickAction: QuickAction,
36-
currentUserPersonalDetails: PersonalDetails,
37-
policyID: string | undefined,
38-
selectOption: (onSelected: () => void, shouldRestrictAction: boolean) => void,
39-
) {
28+
function navigateToQuickAction(isValidReport: boolean, quickAction: QuickAction, selectOption: (onSelected: () => void, shouldRestrictAction: boolean) => void) {
4029
const reportID = isValidReport && quickAction?.chatReportID ? quickAction?.chatReportID : generateReportID();
4130
const requestType = getQuickActionRequestType(quickAction?.action);
4231

@@ -63,18 +52,6 @@ function navigateToQuickAction(
6352
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
6453
selectOption(() => startMoneyRequest(CONST.IOU.TYPE.TRACK, reportID, requestType, true), false);
6554
break;
66-
case CONST.QUICK_ACTIONS.CREATE_REPORT:
67-
selectOption(() => {
68-
const optimisticReportID = createNewReport(currentUserPersonalDetails, policyID);
69-
Navigation.setNavigationActionToMicrotaskQueue(() => {
70-
Navigation.navigate(
71-
isSearchTopmostFullScreenRoute()
72-
? ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: optimisticReportID, backTo: Navigation.getActiveRoute()})
73-
: ROUTES.REPORT_WITH_ID.getRoute(optimisticReportID, undefined, undefined, undefined, undefined, Navigation.getActiveRoute()),
74-
);
75-
});
76-
}, true);
77-
break;
7855
default:
7956
}
8057
}

src/libs/actions/Report.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,15 +2753,6 @@ function buildNewReportOptimisticData(policy: OnyxEntry<Policy>, reportID: strin
27532753
key: `${ONYXKEYS.COLLECTION.NEXT_STEP}${reportID}`,
27542754
value: optimisticNextStep,
27552755
},
2756-
{
2757-
onyxMethod: Onyx.METHOD.SET,
2758-
key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE,
2759-
value: {
2760-
action: CONST.QUICK_ACTIONS.CREATE_REPORT,
2761-
chatReportID: parentReport?.reportID,
2762-
isFirstQuickAction: isEmptyObject(quickAction),
2763-
},
2764-
},
27652756
];
27662757

27672758
const failureData: OnyxUpdate[] = [
@@ -2775,11 +2766,6 @@ function buildNewReportOptimisticData(policy: OnyxEntry<Policy>, reportID: strin
27752766
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
27762767
value: {[reportActionID]: {errorFields: {createReport: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage')}}},
27772768
},
2778-
{
2779-
onyxMethod: Onyx.METHOD.SET,
2780-
key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE,
2781-
value: quickAction ?? null,
2782-
},
27832769

27842770
{
27852771
onyxMethod: Onyx.METHOD.MERGE,

src/pages/home/sidebar/FloatingActionButtonAndPopover.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
189189
}, [isValidReport, quickActionAvatars, personalDetails, quickAction?.action]);
190190

191191
const quickActionSubtitle = useMemo(() => {
192-
if (quickAction?.action === CONST.QUICK_ACTIONS.CREATE_REPORT) {
193-
return quickActionPolicy?.name;
194-
}
195192
return !hideQABSubtitle ? (getReportName(quickActionReport) ?? translate('quickAction.updateDestination')) : '';
196193
// eslint-disable-next-line react-compiler/react-compiler
197194
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -334,7 +331,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
334331
showDelegateNoAccessModal();
335332
return;
336333
}
337-
navigateToQuickAction(isValidReport, quickAction, currentUserPersonalDetails, quickActionPolicy?.id, selectOption);
334+
navigateToQuickAction(isValidReport, quickAction, selectOption);
338335
});
339336
};
340337
return [
@@ -386,7 +383,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu, isT
386383
policyChatForActivePolicy,
387384
quickActionTitle,
388385
quickActionSubtitle,
389-
currentUserPersonalDetails,
390386
quickActionPolicy,
391387
quickActionReport,
392388
isValidReport,

tests/actions/ReportTest.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,20 +1585,6 @@ describe('actions/Report', () => {
15851585
});
15861586
});
15871587

1588-
await new Promise<void>((resolve) => {
1589-
const connection = Onyx.connect({
1590-
key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE,
1591-
callback: (quickAction) => {
1592-
Onyx.disconnect(connection);
1593-
1594-
// Then the quickAction.action should be set to CREATE_REPORT
1595-
expect(quickAction?.action).toBe(CONST.QUICK_ACTIONS.CREATE_REPORT);
1596-
expect(quickAction?.chatReportID).toBe('1234');
1597-
resolve();
1598-
},
1599-
});
1600-
});
1601-
16021588
// When the request fails
16031589
mockFetchData.fail();
16041590
await mockFetchData.resume();

tests/unit/QuickActionNavigationTest.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {startMoneyRequest} from '@libs/actions/IOU';
22
import {navigateToQuickAction} from '@libs/actions/QuickActionNavigation';
3-
import {createNewReport} from '@libs/actions/Report';
43
import {startOutCreateTaskQuickAction} from '@libs/actions/Task';
54
import {generateReportID} from '@libs/ReportUtils';
65
import CONST from '@src/CONST';
@@ -22,7 +21,7 @@ describe('IOU Utils', () => {
2221

2322
it('should be navigated to Manual Submit Expense', () => {
2423
// When the quick action is REQUEST_MANUAL
25-
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.REQUEST_MANUAL, chatReportID: reportID}, {accountID: 1234}, undefined, (onSelected: () => void) => {
24+
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.REQUEST_MANUAL, chatReportID: reportID}, (onSelected: () => void) => {
2625
onSelected();
2726
});
2827
// Then we should start manual submit request flow
@@ -31,7 +30,7 @@ describe('IOU Utils', () => {
3130

3231
it('should be navigated to Scan receipt Split Expense', () => {
3332
// When the quick action is SPLIT_SCAN
34-
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.SPLIT_SCAN, chatReportID: reportID}, {accountID: 1234}, undefined, (onSelected: () => void) => {
33+
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.SPLIT_SCAN, chatReportID: reportID}, (onSelected: () => void) => {
3534
onSelected();
3635
});
3736
// Then we should start scan split request flow
@@ -40,7 +39,7 @@ describe('IOU Utils', () => {
4039

4140
it('should be navigated to Track distance Expense', () => {
4241
// When the quick action is TRACK_DISTANCE
43-
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.TRACK_DISTANCE, chatReportID: reportID}, {accountID: 1234}, undefined, (onSelected: () => void) => {
42+
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.TRACK_DISTANCE, chatReportID: reportID}, (onSelected: () => void) => {
4443
onSelected();
4544
});
4645
// Then we should start distance track request flow
@@ -49,7 +48,7 @@ describe('IOU Utils', () => {
4948

5049
it('should be navigated to Per Diem Expense', () => {
5150
// When the quick action is PER_DIEM
52-
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.PER_DIEM, chatReportID: reportID}, {accountID: 1234}, undefined, (onSelected: () => void) => {
51+
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.PER_DIEM, chatReportID: reportID}, (onSelected: () => void) => {
5352
onSelected();
5453
});
5554
// Then we should start per diem request flow
@@ -59,17 +58,9 @@ describe('IOU Utils', () => {
5958
});
6059

6160
describe('Non IOU quickActions test:', () => {
62-
const reportID = generateReportID();
63-
6461
describe('navigateToQuickAction', () => {
65-
it('creates new report for "createReport" quick action', () => {
66-
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.CREATE_REPORT, chatReportID: reportID}, {accountID: 1234}, undefined, (onSelected: () => void) => {
67-
onSelected();
68-
});
69-
expect(createNewReport).toHaveBeenCalled();
70-
});
7162
it('starts create task flow for "assignTask" quick action', () => {
72-
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.ASSIGN_TASK, targetAccountID: 123}, {accountID: 1234}, undefined, (onSelected: () => void) => {
63+
navigateToQuickAction(true, {action: CONST.QUICK_ACTIONS.ASSIGN_TASK, targetAccountID: 123}, (onSelected: () => void) => {
7364
onSelected();
7465
});
7566
expect(startOutCreateTaskQuickAction).toHaveBeenCalled();

tests/unit/QuickActionUtilsTest.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import * as PolicyUtils from '@libs/PolicyUtils';
33
import {isQuickActionAllowed} from '@libs/QuickActionUtils';
44
import CONST from '@src/CONST';
5-
import type {Policy} from '@src/types/onyx';
5+
import type {Policy, Report} from '@src/types/onyx';
66

77
// Mock the PolicyUtils module
88
jest.mock('@libs/PolicyUtils');
@@ -22,21 +22,7 @@ describe('QuickActionUtils', () => {
2222
jest.clearAllMocks();
2323
});
2424

25-
it('should return true when shouldShowPolicy returns true and isPolicyExpenseChatEnabled is true', () => {
26-
const policy: Partial<Policy> = {
27-
id: 'policy123',
28-
isPolicyExpenseChatEnabled: true,
29-
};
30-
31-
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(true);
32-
33-
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
34-
35-
expect(result).toBe(true);
36-
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
37-
});
38-
39-
it('should return false when shouldShowPolicy returns false even if isPolicyExpenseChatEnabled is true', () => {
25+
it('should return false when shouldShowPolicy returns true and isPolicyExpenseChatEnabled is true', () => {
4026
const policy: Partial<Policy> = {
4127
id: 'policy123',
4228
isPolicyExpenseChatEnabled: true,
@@ -47,7 +33,6 @@ describe('QuickActionUtils', () => {
4733
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
4834

4935
expect(result).toBe(false);
50-
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
5136
});
5237

5338
it('should return false when shouldShowPolicy returns true but isPolicyExpenseChatEnabled is false', () => {
@@ -56,12 +41,11 @@ describe('QuickActionUtils', () => {
5641
isPolicyExpenseChatEnabled: false,
5742
};
5843

59-
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(true);
44+
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(false);
6045

6146
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
6247

6348
expect(result).toBe(false);
64-
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
6549
});
6650

6751
it('should return false when shouldShowPolicy returns true but isPolicyExpenseChatEnabled is undefined', () => {
@@ -75,7 +59,6 @@ describe('QuickActionUtils', () => {
7559
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
7660

7761
expect(result).toBe(false);
78-
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
7962
});
8063

8164
it('should return false when policy is undefined', () => {
@@ -84,7 +67,6 @@ describe('QuickActionUtils', () => {
8467
const result = isQuickActionAllowed(createReportAction, undefined, undefined);
8568

8669
expect(result).toBe(false);
87-
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(undefined, false, undefined);
8870
});
8971

9072
it('should return false when both conditions are false', () => {
@@ -98,7 +80,36 @@ describe('QuickActionUtils', () => {
9880
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
9981

10082
expect(result).toBe(false);
101-
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
83+
});
84+
});
85+
describe('Manager McTest restrictions', () => {
86+
const requestScanAction = {
87+
action: CONST.QUICK_ACTIONS.REQUEST_SCAN,
88+
isFirstQuickAction: false,
89+
};
90+
91+
// Given a report with Manager McTest
92+
const reportWithManagerMcTest: Report = {
93+
reportID: '1',
94+
participants: {
95+
[CONST.ACCOUNT_ID.MANAGER_MCTEST]: {
96+
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
97+
},
98+
},
99+
};
100+
101+
beforeEach(() => {
102+
jest.clearAllMocks();
103+
});
104+
105+
it('should return false when report contains Manager McTest', () => {
106+
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(false);
107+
108+
// When the report contains Manager McTest
109+
const result = isQuickActionAllowed(requestScanAction, reportWithManagerMcTest, undefined);
110+
111+
// Then it should return false
112+
expect(result).toBe(false);
102113
});
103114
});
104115
});

0 commit comments

Comments
 (0)