Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - QAB- QAB navigates to last opened expense type rather than summited expense #53945

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
54 changes: 54 additions & 0 deletions src/libs/actions/QuickActionNavigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {generateReportID} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import type {QuickActionName} from '@src/types/onyx/QuickAction';
import type QuickAction from '@src/types/onyx/QuickAction';
import * as IOU from './IOU';
import * as Task from './Task';

function getQuickActionRequestType(action: QuickActionName | undefined): IOU.IOURequestType | undefined {
if (!action) {
return;
}

let requestType;
if ([CONST.QUICK_ACTIONS.REQUEST_MANUAL, CONST.QUICK_ACTIONS.SPLIT_MANUAL, CONST.QUICK_ACTIONS.TRACK_MANUAL].some((a) => a === action)) {
requestType = CONST.IOU.REQUEST_TYPE.MANUAL;
} else if ([CONST.QUICK_ACTIONS.REQUEST_SCAN, CONST.QUICK_ACTIONS.SPLIT_SCAN, CONST.QUICK_ACTIONS.TRACK_SCAN].some((a) => a === action)) {
requestType = CONST.IOU.REQUEST_TYPE.SCAN;
} else if ([CONST.QUICK_ACTIONS.REQUEST_DISTANCE, CONST.QUICK_ACTIONS.SPLIT_DISTANCE, CONST.QUICK_ACTIONS.TRACK_DISTANCE].some((a) => a === action)) {
requestType = CONST.IOU.REQUEST_TYPE.DISTANCE;
}

return requestType;
}

function navigateToQuickAction(isValidReport: boolean, quickActionReportID: string, qAction: QuickAction, selectOption: (onSelected: () => void, shouldRestrictAction: boolean) => void) {
const reportID = isValidReport ? quickActionReportID : generateReportID();
const requestType = getQuickActionRequestType(qAction?.action);

switch (qAction?.action) {
case CONST.QUICK_ACTIONS.REQUEST_MANUAL:
case CONST.QUICK_ACTIONS.REQUEST_SCAN:
case CONST.QUICK_ACTIONS.REQUEST_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, reportID, requestType, true), true);
return;
case CONST.QUICK_ACTIONS.SPLIT_MANUAL:
case CONST.QUICK_ACTIONS.SPLIT_SCAN:
case CONST.QUICK_ACTIONS.SPLIT_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SPLIT, reportID, requestType, true), true);
return;
case CONST.QUICK_ACTIONS.SEND_MONEY:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.PAY, reportID, undefined, true), false);
return;
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
selectOption(() => Task.startOutCreateTaskQuickAction(isValidReport ? reportID : '', qAction.targetAccountID ?? -1), false);
break;
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
case CONST.QUICK_ACTIONS.TRACK_SCAN:
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, reportID, requestType, true), false);
break;
default:
}
}
export {navigateToQuickAction, getQuickActionRequestType};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as QuickActionNavigation from '@libs/actions/QuickActionNavigation';
import getIconForAction from '@libs/getIconForAction';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute';
Expand Down Expand Up @@ -272,35 +273,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
[quickActionReport?.policyID],
);

const navigateToQuickAction = useCallback(() => {
const quickActionReportID = isValidReport ? quickActionReport?.reportID ?? '-1' : ReportUtils.generateReportID();

switch (quickAction?.action) {
case CONST.QUICK_ACTIONS.REQUEST_MANUAL:
case CONST.QUICK_ACTIONS.REQUEST_SCAN:
case CONST.QUICK_ACTIONS.REQUEST_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID, undefined, true), true);
return;
case CONST.QUICK_ACTIONS.SPLIT_MANUAL:
case CONST.QUICK_ACTIONS.SPLIT_SCAN:
case CONST.QUICK_ACTIONS.SPLIT_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SPLIT, quickActionReportID, undefined, true), true);
return;
case CONST.QUICK_ACTIONS.SEND_MONEY:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.PAY, quickActionReportID, undefined, true), false);
return;
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
selectOption(() => Task.startOutCreateTaskQuickAction(isValidReport ? quickActionReportID : '', quickAction.targetAccountID ?? -1), false);
break;
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
case CONST.QUICK_ACTIONS.TRACK_SCAN:
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, quickActionReportID, undefined, true), false);
break;
default:
}
}, [isValidReport, quickAction?.action, quickAction?.targetAccountID, quickActionReport?.reportID, selectOption]);

/**
* Check if LHN status changed from active to inactive.
* Used to close already opened FAB menu when open any other pages (i.e. Press Command + K on web).
Expand Down Expand Up @@ -421,7 +393,8 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
icon: getQuickActionIcon(quickAction?.action),
text: quickActionTitle,
description: !hideQABSubtitle ? ReportUtils.getReportName(quickActionReport) ?? translate('quickAction.updateDestination') : '',
onSelected: () => interceptAnonymousUser(() => navigateToQuickAction()),
onSelected: () =>
interceptAnonymousUser(() => QuickActionNavigation.navigateToQuickAction(isValidReport, quickActionReport?.reportID ?? '-1', quickAction, selectOption)),
shouldShowSubscriptRightAvatar: ReportUtils.isPolicyExpenseChat(quickActionReport),
},
];
Expand Down Expand Up @@ -454,13 +427,12 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
styles.quickActionTooltipWrapper,
renderProductTrainingTooltip,
hideProductTrainingTooltip,
quickAction?.action,
quickAction,
policyChatForActivePolicy,
quickActionTitle,
hideQABSubtitle,
quickActionReport,
shouldShowProductTrainingTooltip,
navigateToQuickAction,
selectOption,
isValidReport,
quickActionPolicy,
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/QuickActionNavigationTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as IOU from '@libs/actions/IOU';
import * as QuickActionNavigate from '@libs/actions/QuickActionNavigation';
import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';

jest.mock('@libs/actions/IOU', () => ({
startMoneyRequest: jest.fn(),
}));

describe('IOU Utils', () => {
describe('navigateToQuickAction', () => {
it('should startMoneyRequest with the proper params', () => {
const reportID = ReportUtils.generateReportID();
QuickActionNavigate.navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.REQUEST_MANUAL}, (onSelected: () => void) => {
onSelected();
});
expect(IOU.startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.SUBMIT, reportID, CONST.IOU.REQUEST_TYPE.MANUAL, true);
QuickActionNavigate.navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.SPLIT_SCAN}, (onSelected: () => void) => {
onSelected();
});
expect(IOU.startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.SPLIT, reportID, CONST.IOU.REQUEST_TYPE.SCAN, true);
QuickActionNavigate.navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.TRACK_DISTANCE}, (onSelected: () => void) => {
onSelected();
});
expect(IOU.startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.TRACK, reportID, CONST.IOU.REQUEST_TYPE.DISTANCE, true);
});
});
});
Loading