Skip to content
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/SENTRY_LABEL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,7 @@ const SENTRY_LABEL = {
EDIT_REPORT_CREATE_REPORT: 'IOURequestStep-EditReportCreateReport',
EDIT_REPORT_AUTO_REPORT: 'IOURequestStep-EditReportAutoReport',
EDIT_REPORT_REMOVE_FROM_REPORT: 'IOURequestStep-EditReportRemoveFromReport',
EDIT_REPORT_NO_REPORT: 'IOURequestStep-EditReportNoReport',
},
TAB_SELECTOR: {
MANUAL_TAB: 'TabSelector-ManualTab',
Expand Down
10 changes: 10 additions & 0 deletions src/components/MoneyRequestConfirmationFields/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type ProviderProps = {
/** Whether the surface is in a policy-expense chat */
isPolicyExpenseChat?: boolean;

/** Whether the Report row is shown. Defaults to `isPolicyExpenseChat`. */
shouldShowReportField?: boolean;

/** Whether the discard prompt covers the form, which keeps the inline inputs read-only */
isDiscardModalVisible?: boolean;

Expand Down Expand Up @@ -83,6 +86,9 @@ type ProviderProps = {
/** Records the receipt whose inline tax amount input was emptied, or undefined once it holds a value, so submission can be blocked while it is left empty */
setEmptyTaxAmountTransactionID?: (transactionID: string | undefined) => void;

/** Switches the form to another expense type, e.g. to a track expense once the report list moves it off any report. Given by the screen that owns the form's route, which a field inside a tab can't reach with `useRoute` */
onIOUTypeChange?: (iouType: IOUType) => void;

/** Reports whether the inline amount field holds input the draft can't show as the user's: a sign with no digits, or a currency the user picked */
onUnsavedAmountInputChange?: (hasUnsavedInput: boolean) => void;

Expand All @@ -102,6 +108,7 @@ function Provider({
isEditingSplitBill = false,
canEnterScanFieldsManually = false,
isPolicyExpenseChat = false,
shouldShowReportField = isPolicyExpenseChat,
isDiscardModalVisible = false,
isScanRequest = false,
isDistanceRequest = false,
Expand All @@ -115,6 +122,7 @@ function Provider({
fieldViewRefs,
onSubmitForm,
setEmptyTaxAmountTransactionID,
onIOUTypeChange,
onUnsavedAmountInputChange,
children,
}: ProviderProps) {
Expand All @@ -130,6 +138,7 @@ function Provider({
isEditingSplitBill,
canEnterScanFieldsManually,
isPolicyExpenseChat,
shouldShowReportField,
isDiscardModalVisible,
isScanRequest,
isDistanceRequest,
Expand All @@ -143,6 +152,7 @@ function Provider({
fieldViewRefs,
onSubmitForm,
setEmptyTaxAmountTransactionID,
onIOUTypeChange,
onUnsavedAmountInputChange,
};
return <ConfirmationFieldsContext.Provider value={value}>{children}</ConfirmationFieldsContext.Provider>;
Expand Down
6 changes: 6 additions & 0 deletions src/components/MoneyRequestConfirmationFields/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type ConfirmationFieldsContextValue = {
/** Whether this surface offers manual entry of the amount / merchant / date. False for splits, test receipts and moved tracked expenses. */
canEnterScanFieldsManually: boolean;
isPolicyExpenseChat: boolean;
/** Whether the Report row is shown, which follows `isPolicyExpenseChat` unless the form says otherwise */
shouldShowReportField: boolean;

/** Whether the discard prompt covers the form, so the inline inputs go read-only and iOS can't raise a keyboard over it */
isDiscardModalVisible: boolean;

Expand All @@ -52,6 +55,9 @@ type ConfirmationFieldsContextValue = {
/** Records the receipt whose inline tax amount input was emptied, or undefined once it holds a value, so submission can be blocked while it is left empty (new manual expense flow). */
setEmptyTaxAmountTransactionID?: (transactionID: string | undefined) => void;

/** Switches the form to another expense type, e.g. to a track expense once the report list moves it off any report. Given by the screen that owns the form's route, which a field inside a tab can't reach with `useRoute` */
onIOUTypeChange?: (iouType: IOUType) => void;

/** Reports whether the inline amount field holds input the draft can't show as the user's: a sign with no digits, or a currency the user picked (new manual expense flow). */
onUnsavedAmountInputChange?: (hasUnsavedInput: boolean) => void;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function useConfirmationListDataWithPolicy({
payeePersonalDetails: payeePersonalDetailsProp,
isReadOnly = false,
isPolicyExpenseChat = false,
shouldShowReportField,
isEditingSplitBill,
expensesNumber = 0,
receiptOptions,
Expand All @@ -73,6 +74,7 @@ function useConfirmationListDataWithPolicy({
onConfirm,
onSendMoney,
onOpenParticipantPicker,
onIOUTypeChange,
onSwitchToTransaction,
showRemoveExpenseConfirmModal,
isPerDiemRequest = false,
Expand Down Expand Up @@ -360,13 +362,15 @@ function useConfirmationListDataWithPolicy({
didConfirm: !!didConfirm,
canEnterScanFieldsManually,
isPolicyExpenseChat,
shouldShowReportField,
isDiscardModalVisible,
isScanRequest,
isEditingSplitBill,
scrollFocusedInputIntoView,
fieldViewRefs,
onSubmitForm: confirm,
setEmptyTaxAmountTransactionID,
onIOUTypeChange,
onUnsavedAmountInputChange,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
sortOutstandingReportsBySelected,
} from '@libs/ReportUtils';

import useReportPickerChoices from '@pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerChoices';

import CONST from '@src/CONST';
import type {IOUAction, IOUType} from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -77,6 +79,8 @@ function ReportField({selectedParticipants, iouType, reportID, reportActionID, a
const participantReportID = transactionState?.participantReportID;
const isFromGlobalCreate = transactionState?.isFromGlobalCreate ?? false;
const isScanRequest = transactionState?.isScanRequest ?? false;
const isTimeRequest = transactionState?.isTimeRequest ?? false;
const isUnreportedManagedCardTransaction = transactionState?.isUnreportedManagedCardTransaction ?? false;

// Per-key report subscriptions instead of full COLLECTION.REPORT
const [transactionReportEntry] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionReportID}`);
Expand Down Expand Up @@ -145,10 +149,25 @@ function ReportField({selectedParticipants, iouType, reportID, reportActionID, a
// A tracked expense moved to a workspace can only join an open report, so the picker lists only those. Count the same reports here.
const outstandingReports = isMovingTrackedExpense ? allOutstandingReports.filter(isOpenExpenseReport) : allOutstandingReports;
const eligibleOutstandingReports = isCreatingExpense ? outstandingReports.filter((report) => canAddTransaction(report, rules)) : outstandingReports;
// When creating an expense in an individual report, the report field becomes read-only
// since the destination is already determined and there's no need to show a selectable list.
// Use the default rather than the picked report, so picking the only outstanding report keeps the field editable to switch back.
const shouldReportBeEditable = shouldReportFieldBeEditable(eligibleOutstandingReports, selectedReportID, isUnreported || !outstandingReportID) && !isMoneyRequestReport(reportID);
const hasOtherReport = shouldReportFieldBeEditable(eligibleOutstandingReports, selectedReportID, isUnreported || !outstandingReportID);
// The list also offers a new report when there is a workspace to make it on, and no report at all for an expense
// being created, so either is a choice too. The row asks through the hook the list uses, so it never opens an
// empty list, e.g. for someone with no workspace submitting a tracked expense.
const {canCreateReport, canLeaveUnreported} = useReportPickerChoices({
action,
iouType,
isPerDiemRequest,
isTimeRequest,
isUnreportedManagedCardTransaction,
expensePolicyID: policyID,
});
// Editing an expense that is already on a report can hide the new report option (someone else's expense, edited by
// a non-admin), so there the row needs another report to choose from. Creating from inside an expense report locks
// the row, since the expense can only go on that report.
const mayHideListOptions = action === CONST.IOU.ACTION.EDIT && !isUnreported;
const hasReportChoice = mayHideListOptions ? hasOtherReport : hasOtherReport || canCreateReport || canLeaveUnreported;
const shouldReportBeEditable = hasReportChoice && !isMoneyRequestReport(reportID);
// Editing a saved expense's report and moving a per diem expense both navigate on from the list (to the report, or to
// the destination step when the workspace changes), so those keep the full page.
const shouldOpenInDropdown = !!transactionID && shouldReportBeEditable && action !== CONST.IOU.ACTION.EDIT && !isPerDiemRequest;
Expand All @@ -157,7 +176,10 @@ function ReportField({selectedParticipants, iouType, reportID, reportActionID, a
if (!transactionID || !selectedReportID) {
return;
}
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.MONEY_REQUEST_STEP_REPORT.getRoute(action, iouType, transactionID, selectedReportID, reportActionID)));
// With no report to show yet, the page opens from the chat the expense is being created in, as the anchored list
// does, rather than from the placeholder ID.
const reportIDForPage = selectedReport ? selectedReportID : reportID || selectedReportID;
Navigation.navigate(createDynamicRoute(DYNAMIC_ROUTES.MONEY_REQUEST_STEP_REPORT.getRoute(action, iouType, transactionID, reportIDForPage, reportActionID)));
};

if (shouldUseDropdownRows) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type ReportFieldDropdownListProps = ReportFieldDropdownProps & {

/** The report list and the hooks that drive it, which pick through the same hook the full-page selector uses so both leave the expense in the same state */
function ReportFieldDropdownList({transactionID, onClose, onModalHide, ...popoverProps}: ReportFieldDropdownListProps) {
const {reportID, action, iouType} = useConfirmationFields();
const {reportID, action, iouType, onIOUTypeChange} = useConfirmationFields();

// An expense being created, or moved from a tracked expense, lives in its draft until it is saved.
const transactionCollection = shouldUseTransactionDraft(action) ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION;
Expand All @@ -40,6 +40,7 @@ function ReportFieldDropdownList({transactionID, onClose, onModalHide, ...popove
onNavigateAway: onClose,
// The container has no screen transition to wait for, and the row should show the new report as soon as it closes.
shouldWriteAfterTransition: false,
setFormIOUType: onIOUTypeChange,
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
isMerchantMissing,
isScanRequest,
isScanning,
isTimeRequest,
isUnreportedManagedCardTransaction,
willFieldBeAutomaticallyFilled,
} from '@libs/TransactionUtils';

Expand Down Expand Up @@ -357,6 +359,8 @@ type ReportFieldTransactionState = {
isFromGlobalCreate: boolean;
participantReportID: string | undefined;
isScanRequest: boolean;
isTimeRequest: boolean;
isUnreportedManagedCardTransaction: boolean;
};

const reportFieldTransactionStateSelector = (t: OnyxEntry<Transaction>): ReportFieldTransactionState | undefined => {
Expand All @@ -368,6 +372,8 @@ const reportFieldTransactionStateSelector = (t: OnyxEntry<Transaction>): ReportF
isFromGlobalCreate: !!t.isFromGlobalCreate,
participantReportID: t.participants?.at(0)?.reportID,
isScanRequest: isScanRequest(t),
isTimeRequest: isTimeRequest(t),
isUnreportedManagedCardTransaction: isUnreportedManagedCardTransaction(t),
};
};

Expand Down
9 changes: 9 additions & 0 deletions src/components/MoneyRequestConfirmationList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type MoneyRequestConfirmationListProps = {
/** Opens the participant picker owned by the page. */
onOpenParticipantPicker: () => void;

/** Switches the form to another expense type, e.g. to a track expense once the report list moves it off any report. Given by the screen that owns the form's route, which a field inside a tab can't reach with `useRoute` */
onIOUTypeChange?: (iouType: IOUType) => void;

/** The payment method the SettlementButton chose. */
onSendMoney?: (paymentMethod: PaymentMethodType | undefined) => Promise<void>;

Expand Down Expand Up @@ -83,6 +86,12 @@ type MoneyRequestConfirmationListProps = {
/** Whether the current report is a sub-report of an expense chat */
isPolicyExpenseChat?: boolean;

/**
* Whether the Report row is shown. Defaults to `isPolicyExpenseChat`. A form that has no recipient row sets it from
* the chat it was opened for, so the row stays once None moves the expense to the self DM.
*/
shouldShowReportField?: boolean;

/** Whether smartscan failed on this receipt. */
hasSmartScanFailed?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ function ConfirmationFieldList({
const theme = useTheme();
const {translate} = useLocalize();
const icons = useMemoizedLazyExpensifyIcons(['Sparkles', 'DownArrow']);
const {action, iouType, transactionID, isReadOnly, isPolicyExpenseChat, isDistanceRequest, isPerDiemRequest, isTimeRequest, isTypeInvoice} = useConfirmationFields();
const {action, iouType, transactionID, isReadOnly, isPolicyExpenseChat, shouldShowReportField, isDistanceRequest, isPerDiemRequest, isTimeRequest, isTypeInvoice} =
useConfirmationFields();
const {shouldUseDropdownRows} = useExpenseFormLayout();
const policyTagLists = getTagLists(policyTags);
const hasDependentTagLists = hasDependentTags(policy, policyTags);
Expand Down Expand Up @@ -118,7 +119,7 @@ function ConfirmationFieldList({
shouldShowAttendees: visibilityFlags.shouldShowAttendees,
shouldShowReimbursable: flags.shouldShowReimbursable,
shouldShowBillable: flags.shouldShowBillable,
isPolicyExpenseChat,
shouldShowReportField,
});
const shouldShowMoreButton = hasBelowShowMore(fieldVisibility);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type ComputeFieldVisibilityParams = {
shouldShowReimbursable: boolean;
/** Whether the billable toggle should be displayed */
shouldShowBillable: boolean;
/** Whether the surface is in a policy-expense chat (drives Report mount) */
isPolicyExpenseChat: boolean;
/** Whether the Report row is mounted, which it is for an expense that started in a workspace chat */
shouldShowReportField: boolean;
};

/**
Expand Down Expand Up @@ -108,7 +108,7 @@ function computeFieldVisibility({
shouldShowAttendees,
shouldShowReimbursable,
shouldShowBillable,
isPolicyExpenseChat,
shouldShowReportField,
}: ComputeFieldVisibilityParams): FieldVisibility {
const tagsRequired: TagEntry[] = [];
const tagsOptional: TagEntry[] = [];
Expand Down Expand Up @@ -137,7 +137,7 @@ function computeFieldVisibility({
tax: shouldShowTax,
attendees: shouldShowAttendees,
toggles: shouldShowReimbursable || shouldShowBillable,
report: isPolicyExpenseChat,
report: shouldShowReportField,
};
}

Expand Down
Loading
Loading