Skip to content

Create report simplified actions follow ups #61760

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

Merged
Show file tree
Hide file tree
Changes from 12 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
5 changes: 5 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ const CONST = {
},
REPORT_PREVIEW_ACTIONS: {
VIEW: 'view',
ADD_EXPENSE: 'addExpense',
REVIEW: 'review',
SUBMIT: 'submit',
APPROVE: 'approve',
Expand All @@ -1231,6 +1232,10 @@ const CONST = {
VIEW_DETAILS: 'viewDetails',
DELETE: 'delete',
},
ADD_EXPENSE_OPTIONS: {
CREATE_NEW_EXPENSE: 'createNewExpense',
ADD_UNREPORTED_EXPENSE: 'addUnreportedExpense',
},
ACTIONS: {
LIMIT: 50,
// OldDot Actions render getMessage from Web-Expensify/lib/Report/Action PHP files via getMessageOfOldDotReportAction in ReportActionsUtils.ts
Expand Down
38 changes: 22 additions & 16 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,9 @@ const ROUTES = {
},
},
MONEY_REQUEST_CREATE: {
route: ':action/:iouType/start/:transactionID/:reportID',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `${action as string}/${iouType as string}/start/${transactionID}/${reportID}` as const,
route: ':action/:iouType/start/:transactionID/:reportID/:backToReport?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backToReport?: string) =>
`${action as string}/${iouType as string}/start/${transactionID}/${reportID}/${backToReport ?? ''}` as const,
},
MONEY_REQUEST_STEP_SEND_FROM: {
route: 'create/:iouType/from/:transactionID/:reportID',
Expand All @@ -612,13 +613,15 @@ const ROUTES = {
getUrlWithBackToParam(`create/${iouType as string}/company-info/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_CONFIRMATION: {
route: ':action/:iouType/confirmation/:transactionID/:reportID',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string | undefined, participantsAutoAssigned?: boolean) =>
`${action as string}/${iouType as string}/confirmation/${transactionID}/${reportID}${participantsAutoAssigned ? '?participantsAutoAssigned=true' : ''}` as const,
route: ':action/:iouType/confirmation/:transactionID/:reportID/:backToReport?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string | undefined, backToReport?: string, participantsAutoAssigned?: boolean) =>
`${action as string}/${iouType as string}/confirmation/${transactionID}/${reportID}/${backToReport ?? ''}${
participantsAutoAssigned ? '?participantsAutoAssigned=true' : ''
}` as const,
},
MONEY_REQUEST_STEP_AMOUNT: {
route: ':action/:iouType/amount/:transactionID/:reportID/:pageIndex?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string | undefined, reportID: string | undefined, pageIndex: string, backTo = '') => {
route: ':action/:iouType/amount/:transactionID/:reportID/:pageIndex?/:backToReport?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string | undefined, reportID: string | undefined, pageIndex: string, backToReport?: string, backTo = '') => {
Comment on lines +630 to +631
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add it to the getUrlWithBackToParam?

if (!transactionID || !reportID) {
Log.warn('Invalid transactionID or reportID is used to build the MONEY_REQUEST_STEP_AMOUNT route');
}
Expand Down Expand Up @@ -890,21 +893,24 @@ const ROUTES = {
getRoute: (iouType: IOUType, iouRequestType: IOURequestType) => `start/${iouType as string}/${iouRequestType as string}` as const,
},
MONEY_REQUEST_CREATE_TAB_DISTANCE: {
route: ':action/:iouType/start/:transactionID/:reportID/distance',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `create/${iouType as string}/start/${transactionID}/${reportID}/distance` as const,
route: ':action/:iouType/start/:transactionID/:reportID/distance/:backToReport?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backToReport?: string) =>
`create/${iouType as string}/start/${transactionID}/${reportID}/distance/${backToReport}` as const,
},
MONEY_REQUEST_CREATE_TAB_MANUAL: {
route: ':action/:iouType/start/:transactionID/:reportID/manual',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) =>
`${action as string}/${iouType as string}/start/${transactionID}/${reportID}/manual` as const,
route: ':action/:iouType/start/:transactionID/:reportID/manual/:backToReport?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backToReport?: string) =>
`${action as string}/${iouType as string}/start/${transactionID}/${reportID}/manual/${backToReport}` as const,
},
MONEY_REQUEST_CREATE_TAB_SCAN: {
route: ':action/:iouType/start/:transactionID/:reportID/scan',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `create/${iouType as string}/start/${transactionID}/${reportID}/scan` as const,
route: ':action/:iouType/start/:transactionID/:reportID/scan/:backToReport?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backToReport?: string) =>
`create/${iouType as string}/start/${transactionID}/${reportID}/scan/${backToReport}` as const,
},
MONEY_REQUEST_CREATE_TAB_PER_DIEM: {
route: ':action/:iouType/start/:transactionID/:reportID/per-diem',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string) => `create/${iouType as string}/start/${transactionID}/${reportID}/per-diem` as const,
route: ':action/:iouType/start/:transactionID/:reportID/per-diem/:backToReport?',
getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backToReport?: string) =>
`create/${iouType as string}/start/${transactionID}/${reportID}/per-diem/${backToReport}` as const,
},

MONEY_REQUEST_STATE_SELECTOR: {
Expand Down
2 changes: 2 additions & 0 deletions src/components/ButtonWithDropdownMenu/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {RefObject} from 'react';
import type {GestureResponderEvent, StyleProp, View, ViewStyle} from 'react-native';
import type {ValueOf} from 'type-fest';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import type CONST from '@src/CONST';
import type AnchorAlignment from '@src/types/utils/AnchorAlignment';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
Expand Down Expand Up @@ -35,6 +36,7 @@ type DropdownOption<TValueType> = {
shouldCloseModalOnSelect?: boolean;
displayInDefaultIconColor?: boolean;
shouldPreserveSelectionAfterHideModal?: boolean;
subMenuItems?: PopoverMenuItem[];
};

type ButtonWithDropdownMenuProps<TValueType> = {
Expand Down
43 changes: 33 additions & 10 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsAction
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {turnOffMobileSelectionMode} from '@libs/actions/MobileSelectionMode';
import {exportReportToCSV, exportToIntegration, markAsManuallyExported} from '@libs/actions/Report';
import {exportReportToCSV, exportToIntegration, markAsManuallyExported, openUnreportedExpense} from '@libs/actions/Report';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import {getThreadReportIDsForTransactions} from '@libs/MoneyRequestReportUtils';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -396,6 +396,31 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
}
}, [connectedIntegration, exportModalStatus, moneyRequestReport?.reportID]);

const addExpenseDropdownOptions: Array<DropdownOption<ValueOf<typeof CONST.REPORT.ADD_EXPENSE_OPTIONS>>> = useMemo(
() => [
{
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.CREATE_NEW_EXPENSE,
text: translate('iou.createNewExpense'),
icon: Expensicons.Plus,
onSelected: () => {
if (!moneyRequestReport?.reportID) {
return;
}
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, moneyRequestReport?.reportID);
},
},
{
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.ADD_UNREPORTED_EXPENSE,
text: translate('iou.addUnreportedExpense'),
icon: Expensicons.ReceiptPlus,
onSelected: () => {
openUnreportedExpense(moneyRequestReport?.reportID);
},
},
],
[moneyRequestReport?.reportID, translate],
);

const primaryActionsImplementation = {
[CONST.REPORT.PRIMARY_ACTIONS.SUBMIT]: (
<Button
Expand Down Expand Up @@ -493,15 +518,12 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
/>
),
[CONST.REPORT.PRIMARY_ACTIONS.ADD_EXPENSE]: (
<Button
success
text={translate('iou.addExpense')}
onPress={() => {
if (!moneyRequestReport?.reportID) {
return;
}
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, moneyRequestReport?.reportID);
}}
<ButtonWithDropdownMenu
onPress={() => {}}
shouldAlwaysShowDropdownMenu
customText={translate('iou.addExpense')}
options={addExpenseDropdownOptions}
isSplitButton={false}
/>
),
};
Expand Down Expand Up @@ -651,6 +673,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
text: translate('iou.addExpense'),
icon: Expensicons.Plus,
value: CONST.REPORT.SECONDARY_ACTIONS.ADD_EXPENSE,
subMenuItems: addExpenseDropdownOptions,
onSelected: () => {
if (!moneyRequestReport?.reportID) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Animated, {useAnimatedStyle, useSharedValue, withDelay, withSpring, withT
import type {LayoutRectangle} from 'react-native/Libraries/Types/CoreEventTypes';
import Button from '@components/Button';
import {getButtonRole} from '@components/Button/utils';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
import DelegateNoAccessModal from '@components/DelegateNoAccessModal';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
Expand All @@ -27,6 +28,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {openUnreportedExpense} from '@libs/actions/Report';
import ControlSelection from '@libs/ControlSelection';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
import {getTotalAmountForIOUReportPreviewButton} from '@libs/MoneyRequestReportUtils';
Expand All @@ -35,7 +37,6 @@ import Performance from '@libs/Performance';
import {getConnectedIntegration} from '@libs/PolicyUtils';
import {getOriginalMessage, isActionOfType} from '@libs/ReportActionsUtils';
import getReportPreviewAction from '@libs/ReportPreviewActionUtils';
import {isAddExpenseAction} from '@libs/ReportPrimaryActionUtils';
import {
areAllRequestsBeingSmartScanned as areAllRequestsBeingSmartScannedReportUtils,
getBankAccountRoute,
Expand Down Expand Up @@ -461,6 +462,31 @@ function MoneyRequestReportPreviewContent({
return getReportPreviewAction(violations, iouReport, policy, transactions, isIouReportArchived, reportActions);
}, [isPaidAnimationRunning, violations, iouReport, policy, transactions, isIouReportArchived, reportActions]);

const addExpenseDropdownOptions = useMemo(
() => [
{
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.CREATE_NEW_EXPENSE,
text: translate('iou.createNewExpense'),
icon: Expensicons.Plus,
onSelected: () => {
if (!iouReport?.reportID) {
return;
}
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, iouReport?.reportID, undefined, false, chatReportID);
},
},
{
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.ADD_UNREPORTED_EXPENSE,
text: translate('iou.addUnreportedExpense'),
icon: Expensicons.ReceiptPlus,
onSelected: () => {
openUnreportedExpense(iouReport?.reportID);
},
},
],
[chatReportID, iouReport?.reportID, translate],
);

const reportPreviewActions = {
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT]: (
<Button
Expand Down Expand Up @@ -537,38 +563,16 @@ function MoneyRequestReportPreviewContent({
}}
/>
),
};

const emptyReportPreviewAction = useMemo(() => {
if (!iouReport) {
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW;
}

if (isAddExpenseAction(iouReport, transactions ?? [])) {
return CONST.REPORT.PRIMARY_ACTIONS.ADD_EXPENSE;
}

return CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW;
}, [iouReport, transactions]);

const emptyReportPreviewActions = {
[CONST.REPORT.PRIMARY_ACTIONS.ADD_EXPENSE]: (
<Button
success
text={translate('iou.addExpense')}
onPress={() => {
if (!iouReportID) {
return;
}
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, iouReportID);
}}
/>
),
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW]: (
<Button
text={translate('common.view')}
onPress={() => {
openReportFromPreview();
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE]: (
<ButtonWithDropdownMenu
onPress={() => {}}
shouldAlwaysShowDropdownMenu
customText={translate('iou.addExpense')}
options={addExpenseDropdownOptions}
isSplitButton={false}
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
/>
),
Expand Down Expand Up @@ -702,7 +706,7 @@ function MoneyRequestReportPreviewContent({
ListFooterComponent={<View style={styles.pl2} />}
ListHeaderComponent={<View style={styles.pr2} />}
/>
{shouldShowEmptyPlaceholder && <EmptyMoneyRequestReportPreview emptyReportPreviewAction={emptyReportPreviewActions[emptyReportPreviewAction]} />}
{shouldShowEmptyPlaceholder && <EmptyMoneyRequestReportPreview emptyReportPreviewAction={reportPreviewActions[reportPreviewAction]} />}
</View>
{shouldUseNarrowLayout && transactions.length > 1 && (
<View style={[styles.flexRow, styles.alignSelfCenter, styles.gap2]}>
Expand Down
42 changes: 41 additions & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {useOnyx} from 'react-native-onyx';
import Animated, {useAnimatedStyle, useSharedValue, withDelay, withSpring, withTiming} from 'react-native-reanimated';
import Button from '@components/Button';
import {getButtonRole} from '@components/Button/utils';
import ButtonWithDropdownMenu from '@components/ButtonWithDropdownMenu';
import DelegateNoAccessModal from '@components/DelegateNoAccessModal';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
Expand All @@ -28,6 +29,7 @@ import useReportWithTransactionsAndViolations from '@hooks/useReportWithTransact
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useTransactionViolations from '@hooks/useTransactionViolations';
import {openUnreportedExpense} from '@libs/actions/Report';
import ControlSelection from '@libs/ControlSelection';
import {convertToDisplayString} from '@libs/CurrencyUtils';
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
Expand Down Expand Up @@ -85,7 +87,7 @@ import {
import {contextMenuRef} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import variables from '@styles/variables';
import {approveMoneyRequest, canIOUBePaid as canIOUBePaidIOUActions, payInvoice, payMoneyRequest, submitReport} from '@userActions/IOU';
import {approveMoneyRequest, canIOUBePaid as canIOUBePaidIOUActions, payInvoice, payMoneyRequest, startMoneyRequest, submitReport} from '@userActions/IOU';
import Timing from '@userActions/Timing';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
Expand Down Expand Up @@ -509,6 +511,31 @@ function ReportPreview({
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(iouReportID, undefined, undefined, undefined, undefined, Navigation.getActiveRoute()));
}, [iouReportID]);

const addExpenseDropdownOptions = useMemo(
() => [
{
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.CREATE_NEW_EXPENSE,
text: translate('iou.createNewExpense'),
icon: Expensicons.Plus,
onSelected: () => {
if (!iouReport?.reportID) {
return;
}
startMoneyRequest(CONST.IOU.TYPE.SUBMIT, iouReport?.reportID, undefined, false, chatReportID);
},
},
{
value: CONST.REPORT.ADD_EXPENSE_OPTIONS.ADD_UNREPORTED_EXPENSE,
text: translate('iou.addUnreportedExpense'),
icon: Expensicons.ReceiptPlus,
onSelected: () => {
openUnreportedExpense(iouReport?.reportID);
},
},
],
[chatReportID, iouReport?.reportID, translate],
);

const reportPreviewAction = useMemo(() => {
// It's necessary to allow payment animation to finish before button is changed
if (isPaidAnimationRunning) {
Expand Down Expand Up @@ -590,6 +617,19 @@ function ReportPreview({
}}
/>
),
[CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE]: (
<ButtonWithDropdownMenu
onPress={() => {}}
shouldAlwaysShowDropdownMenu
customText={translate('iou.addExpense')}
options={addExpenseDropdownOptions}
isSplitButton={false}
anchorAlignment={{
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
/>
),
};

return (
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ const translations = {
unheldExpense: 'unheld this expense',
moveUnreportedExpense: 'Move unreported expense',
addUnreportedExpense: 'Add unreported expense',
createNewExpense: 'Create new expense',
selectUnreportedExpense: 'Select at least one expense to add to the report.',
emptyStateUnreportedExpenseTitle: 'No unreported expenses',
emptyStateUnreportedExpenseSubtitle: 'Looks like you don’t have any unreported expenses. Try creating one below.',
Expand Down
Loading
Loading