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: update QAB titles for money request, track actions and perdiem #56324

Open
wants to merge 14 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
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ const CONST = {
REQUEST_MANUAL: 'requestManual',
REQUEST_SCAN: 'requestScan',
REQUEST_DISTANCE: 'requestDistance',
PER_DIEM: 'perDiem',
SPLIT_MANUAL: 'splitManual',
SPLIT_SCAN: 'splitScan',
SPLIT_DISTANCE: 'splitDistance',
Expand Down
6 changes: 2 additions & 4 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,17 +842,15 @@ const translations = {
},
quickAction: {
scanReceipt: 'Scan receipt',
recordDistance: 'Record distance',
recordDistance: 'Track distance',
requestMoney: 'Create expense',
perDiem: 'Create per diem',
splitBill: 'Split expense',
splitScan: 'Split receipt',
splitDistance: 'Split distance',
paySomeone: ({name}: PaySomeoneParams = {}) => `Pay ${name ?? 'someone'}`,
assignTask: 'Assign task',
header: 'Quick action',
trackManual: 'Create expense',
trackScan: 'Scan receipt',
trackDistance: 'Track distance',
noLongerHaveReportAccess: 'You no longer have access to your previous quick action destination. Pick a new one below.',
updateDestination: 'Update destination',
},
Expand Down
6 changes: 2 additions & 4 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,17 +837,15 @@ const translations = {
},
quickAction: {
scanReceipt: 'Escanear recibo',
recordDistance: 'Grabar distancia',
recordDistance: 'Crear gasto por desplazamiento',
requestMoney: 'Crear gasto',
perDiem: 'Crear viático',
splitBill: 'Dividir gasto',
splitScan: 'Dividir recibo',
splitDistance: 'Dividir distancia',
paySomeone: ({name}: PaySomeoneParams = {}) => `Pagar a ${name ?? 'alguien'}`,
assignTask: 'Assignar tarea',
header: 'Acción rápida',
trackManual: 'Crear gasto',
trackScan: 'Escanear recibo',
trackDistance: 'Crear gasto por desplazamiento',
noLongerHaveReportAccess: 'Ya no tienes acceso al destino previo de esta acción rápida. Escoge uno nuevo a continuación.',
updateDestination: 'Actualiza el destino',
},
Expand Down
12 changes: 10 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,15 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
const clearedPendingFields = Object.fromEntries(Object.keys(transaction.pendingFields ?? {}).map((key) => [key, null]));
const optimisticData: OnyxUpdate[] = [];
const successData: OnyxUpdate[] = [];
let newQuickAction: ValueOf<typeof CONST.QUICK_ACTIONS> = isScanRequest ? CONST.QUICK_ACTIONS.REQUEST_SCAN : CONST.QUICK_ACTIONS.REQUEST_MANUAL;
let newQuickAction: ValueOf<typeof CONST.QUICK_ACTIONS>;
if (isScanRequest) {
newQuickAction = CONST.QUICK_ACTIONS.REQUEST_SCAN;
} else if (isPerDiemRequest) {
newQuickAction = CONST.QUICK_ACTIONS.PER_DIEM;
} else {
newQuickAction = CONST.QUICK_ACTIONS.REQUEST_MANUAL;
}

if (isDistanceRequestTransactionUtils(transaction)) {
newQuickAction = CONST.QUICK_ACTIONS.REQUEST_DISTANCE;
}
Expand Down Expand Up @@ -1380,7 +1388,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
},
];

if (!isOneOnOneSplit && !isPerDiemRequest) {
if (!isOneOnOneSplit) {
optimisticData.push({
onyxMethod: Onyx.METHOD.SET,
key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE,
Expand Down
20 changes: 12 additions & 8 deletions src/libs/actions/QuickActionNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ 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';
import type {IOURequestType} from './IOU';
import {startMoneyRequest} from './IOU';
import {startOutCreateTaskQuickAction} from './Task';

function getQuickActionRequestType(action: QuickActionName | undefined): IOU.IOURequestType | undefined {
function getQuickActionRequestType(action: QuickActionName | undefined): IOURequestType | undefined {
if (!action) {
return;
}
Expand All @@ -17,6 +18,8 @@ function getQuickActionRequestType(action: QuickActionName | undefined): IOU.IOU
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;
} else if (action === CONST.QUICK_ACTIONS.PER_DIEM) {
requestType = CONST.IOU.REQUEST_TYPE.PER_DIEM;
}

return requestType;
Expand All @@ -30,23 +33,24 @@ function navigateToQuickAction(isValidReport: boolean, quickActionReportID: stri
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);
case CONST.QUICK_ACTIONS.PER_DIEM:
selectOption(() => 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);
selectOption(() => 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);
selectOption(() => startMoneyRequest(CONST.IOU.TYPE.PAY, reportID, undefined, true), false);
return;
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
selectOption(() => Task.startOutCreateTaskQuickAction(isValidReport ? reportID : '', quickAction.targetAccountID ?? CONST.DEFAULT_NUMBER_ID), false);
selectOption(() => startOutCreateTaskQuickAction(isValidReport ? reportID : '', quickAction.targetAccountID ?? CONST.DEFAULT_NUMBER_ID), 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);
selectOption(() => startMoneyRequest(CONST.IOU.TYPE.TRACK, reportID, requestType, true), false);
break;
default:
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const getQuickActionIcon = (action: QuickActionName): React.FC<SvgProps> => {
return Expensicons.ReceiptScan;
case CONST.QUICK_ACTIONS.REQUEST_DISTANCE:
return Expensicons.Car;
case CONST.QUICK_ACTIONS.PER_DIEM:
return Expensicons.CalendarSolid;
case CONST.QUICK_ACTIONS.SPLIT_MANUAL:
case CONST.QUICK_ACTIONS.SPLIT_SCAN:
case CONST.QUICK_ACTIONS.SPLIT_DISTANCE:
Expand All @@ -117,6 +119,7 @@ const getIouType = (action: QuickActionName) => {
case CONST.QUICK_ACTIONS.REQUEST_MANUAL:
case CONST.QUICK_ACTIONS.REQUEST_SCAN:
case CONST.QUICK_ACTIONS.REQUEST_DISTANCE:
case CONST.QUICK_ACTIONS.PER_DIEM:
return CONST.IOU.TYPE.SUBMIT;
case CONST.QUICK_ACTIONS.SPLIT_MANUAL:
case CONST.QUICK_ACTIONS.SPLIT_SCAN:
Expand All @@ -136,23 +139,22 @@ const getIouType = (action: QuickActionName) => {
const getQuickActionTitle = (action: QuickActionName): TranslationPaths => {
switch (action) {
case CONST.QUICK_ACTIONS.REQUEST_MANUAL:
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
return 'quickAction.requestMoney';
case CONST.QUICK_ACTIONS.REQUEST_SCAN:
case CONST.QUICK_ACTIONS.TRACK_SCAN:
return 'quickAction.scanReceipt';
case CONST.QUICK_ACTIONS.REQUEST_DISTANCE:
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
return 'quickAction.recordDistance';
case CONST.QUICK_ACTIONS.PER_DIEM:
return 'quickAction.perDiem';
case CONST.QUICK_ACTIONS.SPLIT_MANUAL:
return 'quickAction.splitBill';
case CONST.QUICK_ACTIONS.SPLIT_SCAN:
return 'quickAction.splitScan';
case CONST.QUICK_ACTIONS.SPLIT_DISTANCE:
return 'quickAction.splitDistance';
case CONST.QUICK_ACTIONS.TRACK_MANUAL:
return 'quickAction.trackManual';
case CONST.QUICK_ACTIONS.TRACK_SCAN:
return 'quickAction.trackScan';
case CONST.QUICK_ACTIONS.TRACK_DISTANCE:
return 'quickAction.trackDistance';
case CONST.QUICK_ACTIONS.SEND_MONEY:
return 'quickAction.paySomeone';
case CONST.QUICK_ACTIONS.ASSIGN_TASK:
Expand Down Expand Up @@ -387,6 +389,9 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
if (!!iouType && !canCreateRequest(quickActionReport, quickActionPolicy, iouType)) {
return [];
}
if (quickAction?.action === CONST.QUICK_ACTIONS.PER_DIEM && !quickActionPolicy?.arePerDiemRatesEnabled) {
return [];
}
const onSelected = () => {
interceptAnonymousUser(() => {
hideProductTrainingTooltip();
Expand Down
29 changes: 19 additions & 10 deletions tests/unit/QuickActionNavigationTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as IOU from '@libs/actions/IOU';
import * as QuickActionNavigate from '@libs/actions/QuickActionNavigation';
import * as ReportUtils from '@libs/ReportUtils';
import {startMoneyRequest} from '@libs/actions/IOU';
import {navigateToQuickAction} from '@libs/actions/QuickActionNavigation';
import {generateReportID} from '@libs/ReportUtils';
import CONST from '@src/CONST';

jest.mock('@libs/actions/IOU', () => ({
Expand All @@ -10,33 +10,42 @@ jest.mock('@libs/actions/IOU', () => ({
describe('IOU Utils', () => {
// Given navigateToQuickAction is called with quick action argument when clicking on quick action button from Global create menu
describe('navigateToQuickAction', () => {
const reportID = ReportUtils.generateReportID();
const reportID = generateReportID();

it('should be navigated to Manual Submit Expense', () => {
// When the quick action is REQUEST_MANUAL
QuickActionNavigate.navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.REQUEST_MANUAL}, (onSelected: () => void) => {
navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.REQUEST_MANUAL}, (onSelected: () => void) => {
onSelected();
});
// Then we should start manual submit request flow
expect(IOU.startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.SUBMIT, reportID, CONST.IOU.REQUEST_TYPE.MANUAL, true);
expect(startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.SUBMIT, reportID, CONST.IOU.REQUEST_TYPE.MANUAL, true);
});

it('should be navigated to Scan receipt Split Expense', () => {
// When the quick action is SPLIT_SCAN
QuickActionNavigate.navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.SPLIT_SCAN}, (onSelected: () => void) => {
navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.SPLIT_SCAN}, (onSelected: () => void) => {
onSelected();
});
// Then we should start scan split request flow
expect(IOU.startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.SPLIT, reportID, CONST.IOU.REQUEST_TYPE.SCAN, true);
expect(startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.SPLIT, reportID, CONST.IOU.REQUEST_TYPE.SCAN, true);
});

it('should be navigated to Track distance Expense', () => {
// When the quick action is TRACK_DISTANCE
QuickActionNavigate.navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.TRACK_DISTANCE}, (onSelected: () => void) => {
navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.TRACK_DISTANCE}, (onSelected: () => void) => {
onSelected();
});
// Then we should start distance track request flow
expect(IOU.startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.TRACK, reportID, CONST.IOU.REQUEST_TYPE.DISTANCE, true);
expect(startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.TRACK, reportID, CONST.IOU.REQUEST_TYPE.DISTANCE, true);
});

it('should be navigated to Per Diem Expense', () => {
// When the quick action is PER_DIEM
navigateToQuickAction(true, reportID, {action: CONST.QUICK_ACTIONS.PER_DIEM}, (onSelected: () => void) => {
onSelected();
});
// Then we should start per diem request flow
expect(startMoneyRequest).toHaveBeenCalledWith(CONST.IOU.TYPE.SUBMIT, reportID, CONST.IOU.REQUEST_TYPE.PER_DIEM, true);
});
});
});