Skip to content

Commit 98e1b02

Browse files
Merge pull request Expensify#71005 from dominictb/feat/70827
feat: add track distance option to add expense menu
2 parents 9ef6ebf + 32892eb commit 98e1b02

5 files changed

Lines changed: 59 additions & 5 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@ const CONST = {
11621162
ADD_EXPENSE_OPTIONS: {
11631163
CREATE_NEW_EXPENSE: 'createNewExpense',
11641164
ADD_UNREPORTED_EXPENSE: 'addUnreportedExpense',
1165+
TRACK_DISTANCE_EXPENSE: 'trackDistanceExpense',
11651166
},
11661167
ACTIONS: {
11671168
LIMIT: 50,

src/components/EmptyStateComponent/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ type EmptyStateButton = {
1717
icon?: IconAsset;
1818
isDisabled?: boolean;
1919
style?: StyleProp<ViewStyle>;
20-
dropDownOptions?: Array<DropdownOption<ValueOf<{readonly CREATE_NEW_EXPENSE: 'createNewExpense'; readonly ADD_UNREPORTED_EXPENSE: 'addUnreportedExpense'}>>>;
20+
dropDownOptions?: Array<
21+
DropdownOption<
22+
ValueOf<{readonly CREATE_NEW_EXPENSE: 'createNewExpense'; readonly TRACK_DISTANCE_EXPENSE: 'trackDistanceExpense'; readonly ADD_UNREPORTED_EXPENSE: 'addUnreportedExpense'}>
23+
>
24+
>;
2125
};
2226

2327
type SharedProps<T> = {

src/components/MoneyReportHeader.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import {
9595
payMoneyRequest,
9696
reopenReport,
9797
retractReport,
98+
startDistanceRequest,
9899
startMoneyRequest,
99100
submitReport,
100101
unapproveExpenseReport,
@@ -194,6 +195,7 @@ function MoneyReportHeader({
194195
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
195196
const [integrationsExportTemplates] = useOnyx(ONYXKEYS.NVP_INTEGRATION_SERVER_EXPORT_TEMPLATES, {canBeMissing: true});
196197
const [csvExportLayouts] = useOnyx(ONYXKEYS.NVP_CSV_EXPORT_LAYOUTS, {canBeMissing: true});
198+
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE, {canBeMissing: true});
197199
const exportTemplates = useMemo(() => getExportTemplates(integrationsExportTemplates ?? [], csvExportLayouts ?? {}, policy), [integrationsExportTemplates, csvExportLayouts, policy]);
198200

199201
const requestParentReportAction = useMemo(() => {
@@ -624,6 +626,21 @@ function MoneyReportHeader({
624626
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, moneyRequestReport?.reportID);
625627
},
626628
},
629+
{
630+
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.TRACK_DISTANCE_EXPENSE,
631+
text: translate('iou.trackDistance'),
632+
icon: Expensicons.Location,
633+
onSelected: () => {
634+
if (!moneyRequestReport?.reportID) {
635+
return;
636+
}
637+
if (policy && shouldRestrictUserBillableActions(policy.id)) {
638+
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
639+
return;
640+
}
641+
startDistanceRequest(CONST.IOU.TYPE.SUBMIT, moneyRequestReport.reportID, lastDistanceExpenseType);
642+
},
643+
},
627644
{
628645
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.ADD_UNREPORTED_EXPENSE,
629646
text: translate('iou.addUnreportedExpense'),
@@ -637,7 +654,7 @@ function MoneyReportHeader({
637654
},
638655
},
639656
],
640-
[moneyRequestReport?.reportID, policy, translate],
657+
[moneyRequestReport?.reportID, policy, lastDistanceExpenseType, translate],
641658
);
642659

643660
const exportSubmenuOptions: Record<string, DropdownOption<string>> = useMemo(() => {

src/components/MoneyRequestReportView/SearchMoneyRequestReportEmptyState.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
99
import {canAddTransaction, isArchivedReport} from '@libs/ReportUtils';
1010
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
1111
import Navigation from '@navigation/Navigation';
12-
import {startMoneyRequest} from '@userActions/IOU';
12+
import {startDistanceRequest, startMoneyRequest} from '@userActions/IOU';
1313
import {openUnreportedExpense} from '@userActions/Report';
1414
import CONST from '@src/CONST';
1515
import ONYXKEYS from '@src/ONYXKEYS';
@@ -22,6 +22,7 @@ function SearchMoneyRequestReportEmptyState({report, policy}: {report: OnyxTypes
2222
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`, {canBeMissing: true});
2323
const {translate} = useLocalize();
2424
const styles = useThemeStyles();
25+
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE, {canBeMissing: true});
2526
const reportId = report.reportID;
2627
const isReportArchived = isArchivedReport(reportNameValuePairs);
2728
const canAddTransactionToReport = canAddTransaction(report, isReportArchived);
@@ -41,6 +42,21 @@ function SearchMoneyRequestReportEmptyState({report, policy}: {report: OnyxTypes
4142
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, reportId);
4243
},
4344
},
45+
{
46+
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.TRACK_DISTANCE_EXPENSE,
47+
text: translate('iou.trackDistance'),
48+
icon: Expensicons.Location,
49+
onSelected: () => {
50+
if (!reportId) {
51+
return;
52+
}
53+
if (policy && shouldRestrictUserBillableActions(policy.id)) {
54+
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
55+
return;
56+
}
57+
startDistanceRequest(CONST.IOU.TYPE.SUBMIT, reportId, lastDistanceExpenseType);
58+
},
59+
},
4460
{
4561
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.ADD_UNREPORTED_EXPENSE,
4662
text: translate('iou.addUnreportedExpense'),

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
7171
import {hasPendingUI, isCardTransaction, isPending} from '@libs/TransactionUtils';
7272
import colors from '@styles/theme/colors';
7373
import variables from '@styles/variables';
74-
import {approveMoneyRequest, canIOUBePaid as canIOUBePaidIOUActions, payInvoice, payMoneyRequest, startMoneyRequest, submitReport} from '@userActions/IOU';
74+
import {approveMoneyRequest, canIOUBePaid as canIOUBePaidIOUActions, payInvoice, payMoneyRequest, startDistanceRequest, startMoneyRequest, submitReport} from '@userActions/IOU';
7575
import Timing from '@userActions/Timing';
7676
import CONST from '@src/CONST';
7777
import type {TranslationPaths} from '@src/languages/types';
@@ -114,6 +114,7 @@ function MoneyRequestReportPreviewContent({
114114
}: MoneyRequestReportPreviewContentProps) {
115115
const [chatReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReportID}`, {canBeMissing: true, allowStaleData: true});
116116
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
117+
const [lastDistanceExpenseType] = useOnyx(ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE, {canBeMissing: true});
117118
const shouldShowLoading = !chatReportMetadata?.hasOnceLoadedReportActions && transactions.length === 0 && !chatReportMetadata?.isOptimisticReport;
118119
// `hasOnceLoadedReportActions` becomes true before transactions populate fully,
119120
// so we defer the loading state update to ensure transactions are loaded
@@ -487,6 +488,21 @@ function MoneyRequestReportPreviewContent({
487488
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, iouReport?.reportID, undefined, false, chatReportID);
488489
},
489490
},
491+
{
492+
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.TRACK_DISTANCE_EXPENSE,
493+
text: translate('iou.trackDistance'),
494+
icon: Expensicons.Location,
495+
onSelected: () => {
496+
if (!iouReport?.reportID) {
497+
return;
498+
}
499+
if (policy && shouldRestrictUserBillableActions(policy.id)) {
500+
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
501+
return;
502+
}
503+
startDistanceRequest(CONST.IOU.TYPE.SUBMIT, iouReport.reportID, lastDistanceExpenseType);
504+
},
505+
},
490506
{
491507
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.ADD_UNREPORTED_EXPENSE,
492508
text: translate('iou.addUnreportedExpense'),
@@ -500,7 +516,7 @@ function MoneyRequestReportPreviewContent({
500516
},
501517
},
502518
],
503-
[chatReportID, iouReport?.parentReportID, iouReport?.reportID, policy, translate],
519+
[chatReportID, iouReport?.parentReportID, iouReport?.reportID, policy, lastDistanceExpenseType, translate],
504520
);
505521

506522
const isReportDeleted = action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;

0 commit comments

Comments
 (0)