Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion src/components/AddressSearch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type AddressSearchProps = ForwardedFSClassProps & {
onInputChange?: (value: string | number | Address | StreetValue, key?: string) => void;

/** A callback function when an address has been auto-selected */
onPress?: (props: OnPressProps) => void;
onPress?: (props: OnPressProps) => void | Promise<void>;

/** Customize the TextInput container */
containerStyles?: StyleProp<ViewStyle>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {WithRequiredSentryLabel} from '@src/types/utils/SentryLabel';
type ConfirmationPageButtonProps = WithRequiredSentryLabel &
Pick<ButtonProps, 'isDisabled' | 'isLoading'> & {
text: string;
onPress?: () => void;
onPress?: () => void | Promise<void>;
};

type ConfirmationPageButtonBaseProps = ConfirmationPageButtonProps &
Expand Down
2 changes: 1 addition & 1 deletion src/components/DestinationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import SelectionListWithSections from './SelectionList/SelectionListWithSections
type DestinationPickerProps = {
policyID: string;
selectedDestination?: string;
onSubmit: (item: ListItem & {currency: string}) => void;
onSubmit: (item: ListItem & {currency: string}) => void | Promise<void>;
ref?: ForwardedRef<SelectionListWithSectionsHandle>;
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ type FormProps<TFormID extends OnyxFormKey = OnyxFormKey> = ForwardedFSClassProp
/** Controls the submit button's visibility */
isSubmitButtonVisible?: boolean;

onSubmit: (values: FormOnyxValues<TFormID>) => void;
onSubmit: (values: FormOnyxValues<TFormID>) => void | Promise<void>;

/** Should the button be enabled when offline */
enabledWhenOffline?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type BaseSelectionListProps<TItem extends ListItem> = {
/** Component rendering each row. `NoInfer` keeps the row component from widening `TItem`, which is inferred from `data`/`sections` */
ListItem: ListItemComponent<NoInfer<TItem>>;
initiallyFocusedItemKey?: string;
onSelectRow: (item: TItem) => void;
onSelectRow: (item: TItem) => void | Promise<void>;
canSelectMultiple?: boolean;
footerContent?: React.ReactNode;

Expand Down
2 changes: 1 addition & 1 deletion src/components/WorkspaceConfirmationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type WorkspaceConfirmationFormProps = {
*/
policyOwnerEmail?: string;

onSubmit: (params: WorkspaceConfirmationSubmitFunctionParams) => void;
onSubmit: (params: WorkspaceConfirmationSubmitFunctionParams) => void | Promise<void>;

/** Go back function */
onBackButtonPress?: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/MoneyRequestAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type MoneyRequestAmountFormProps = Omit<MoneyRequestAmountInputProps, 'shouldSho
policyID?: string;

/** Fired when submit button pressed, saves the given amount and navigates to the next page */
onSubmitButtonPress: (currentMoney: CurrentMoney) => void;
onSubmitButtonPress: (currentMoney: CurrentMoney) => void | Promise<void>;

/** Fired when the visible amount sign differs from its initial value */
onSignDirtyChange?: (isSignDirty: boolean) => void;
Expand Down
19 changes: 12 additions & 7 deletions src/pages/iou/request/step/DynamicIOURequestStepDestination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import type {OnyxEntry} from 'react-native-onyx';

import React, {useEffect, useImperativeHandle, useRef} from 'react';
import {View} from 'react-native';
import Onyx from 'react-native-onyx';

import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNotFound';
import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
Expand Down Expand Up @@ -90,9 +91,6 @@ function DynamicIOURequestStepDestination({
const isEditPage = name === SCREENS.MONEY_REQUEST.DYNAMIC_STEP_DESTINATION_EDIT;
const editBackPath = useDynamicBackPath(DYNAMIC_ROUTES.MONEY_REQUEST_STEP_DESTINATION_EDIT.path);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const reportPolicyID = getIOURequestPolicyID(transaction, report);
const policyID = reportPolicyID === CONST.POLICY.ID_FAKE ? getPolicyByCustomUnitID(transaction, allPolicies)?.id : reportPolicyID;
const [policy, policyMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${explicitPolicyID ?? policyID}`);
Expand Down Expand Up @@ -131,10 +129,17 @@ function DynamicIOURequestStepDestination({
Navigation.goBack();
};

const updateDestination = (destination: ListItem & {currency: string}) => {
if (openedFromStartPage && policy && shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
const updateDestination = async (destination: ListItem & {currency: string}) => {
if (openedFromStartPage && policy) {
const [userBillingGracePeriodEnds, ownerBillingGracePeriodEnd, amountOwed] = await Onyx.multiGet([
ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END,
ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END,
ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED,
]);
if (shouldRestrictUserBillableActions(policy, ownerBillingGracePeriodEnd, userBillingGracePeriodEnds, amountOwed, accountID)) {
Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(policy.id));
return;
}
}

if (isEmptyObject(customUnit)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import type {OnyxEntry} from 'react-native-onyx';

import {useFocusEffect} from '@react-navigation/native';
import React, {useEffect, useRef, useState} from 'react';
import Onyx from 'react-native-onyx';

import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';

Expand Down Expand Up @@ -108,32 +109,15 @@ function DynamicIOURequestStepDistanceManual({

const [selectedTab] = useOnyx(`${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.DISTANCE_REQUEST_TYPE}`);
const distanceOriginalPolicy = useDistanceRateOriginalPolicy(transaction?.comment?.customUnit?.customUnitRateID);
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy?.id}`);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policy?.id}`);
const [personalDetails] = useAllPersonalDetails();
const [amountOwed] = useOnyx(ONYXKEYS.NVP_PRIVATE_AMOUNT_OWED);
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
const [skipConfirmation] = useOnyx(`${ONYXKEYS.COLLECTION.SKIP_CONFIRMATION}${transactionID}`);
const [lastSelectedDistanceRates] = useOnyx(ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES);
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
const [quickAction] = useOnyx(ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE);
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`);
const [iouReportOwnerLogin] = useAllPersonalDetails(personalDetailsLoginSelector(parentReport?.ownerAccountID));
const [reportPolicyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`);
const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {
selector: validTransactionDraftIDsSelector,
});
const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
selector: hasSeenTourSelector,
});
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const [conciergeChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${conciergeReportID}`);
const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`);
const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS);
const [rules] = useOnyx(ONYXKEYS.COLLECTION.RULE);
const reportIDToCheck = isMoneyRequestReportReportUtils(report) ? report?.chatReportID : report?.reportID;
const [reportDraft] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${reportIDToCheck}`);
const textInput = useRef<BaseTextInputRef | null>(null);
Expand All @@ -149,7 +133,6 @@ function DynamicIOURequestStepDistanceManual({
const currentUserEmailParam = currentUserPersonalDetails.login ?? '';
const delegateAccountID = useDelegateAccountID();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const isTrackIntentUser = isTrackOnboardingChoice(introSelected?.choice);

const shouldUseDefaultExpensePolicy = shouldUseDefaultExpensePolicyUtil(
iouType,
Expand Down Expand Up @@ -247,12 +230,13 @@ function DynamicIOURequestStepDistanceManual({
translate,
});

const navigateToNextPage = (amount: string) => {
const navigateToNextPage = async (amount: string) => {
const distanceAsFloat = roundToTwoDecimalPlaces(parseFloat(amount));

if (action === CONST.IOU.ACTION.EDIT) {
// In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value
if (isEditingSplit && transaction) {
const splitDraftTransaction = await Onyx.get(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`);
setDraftSplitTransaction(
transaction.transactionID,
splitDraftTransaction ?? transaction,
Expand All @@ -272,6 +256,14 @@ function DynamicIOURequestStepDistanceManual({
const shouldUpdateTransaction = isDistanceChanged || isDistanceUnitChanged;

if (shouldUpdateTransaction) {
const [rules, policyCategories, policyTags, reportPolicyTags, introSelected, recentWaypoints] = await Onyx.multiGet([
ONYXKEYS.COLLECTION.RULE,
`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy?.id}`,
`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policy?.id}`,
`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`,
ONYXKEYS.NVP_INTRO_SELECTED,
ONYXKEYS.NVP_RECENT_WAYPOINTS,
]);
updateMoneyRequestDistance({
isVendorMatchingBetaEnabled,
transaction,
Expand All @@ -291,7 +283,7 @@ function DynamicIOURequestStepDistanceManual({
recentWaypoints,
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
isTrackIntentUser: isTrackOnboardingChoice(introSelected?.choice),
personalPolicyOutputCurrency: personalPolicy?.outputCurrency,
violations: transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction?.transactionID}`],
getCurrencyDecimals,
Expand All @@ -303,6 +295,20 @@ function DynamicIOURequestStepDistanceManual({
return;
}

const [lastSelectedDistanceRates, quickAction, policyRecentlyUsedCurrencies, recentWaypoints, rules, introSelected, transactionDrafts, onboarding, conciergeChat] =
await Onyx.multiGet([
ONYXKEYS.NVP_LAST_SELECTED_DISTANCE_RATES,
ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE,
ONYXKEYS.RECENTLY_USED_CURRENCIES,
ONYXKEYS.NVP_RECENT_WAYPOINTS,
ONYXKEYS.COLLECTION.RULE,
ONYXKEYS.NVP_INTRO_SELECTED,
ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
ONYXKEYS.NVP_ONBOARDING,
`${ONYXKEYS.COLLECTION.REPORT}${conciergeReportID}`,
]);
const isTrackIntentUser = isTrackOnboardingChoice(introSelected?.choice);

setMoneyRequestDistance(transactionID, distanceAsFloat, isTransactionDraft, unit);

const optimisticTransactionID = rand64();
Expand Down Expand Up @@ -344,12 +350,12 @@ function DynamicIOURequestStepDistanceManual({
recentWaypoints,
unit,
personalOutputCurrency: personalPolicy?.outputCurrency,
isSelfTourViewed: !!isSelfTourViewed,
isSelfTourViewed: hasSeenTourSelector(onboarding),
amountOwed,
userBillingGracePeriodEnds,
ownerBillingGracePeriodEnd,
conciergeChat,
draftTransactionIDs,
draftTransactionIDs: validTransactionDraftIDsSelector(transactionDrafts),
optimisticTransactionID,
optimisticChatReportID,
isTrackIntentUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {loginSelector} from '@selectors/PersonalDetails';
import {policyTypeSelector} from '@selectors/Policy';
import lodashIsEmpty from 'lodash/isEmpty';
import React, {useState} from 'react';
import Onyx from 'react-native-onyx';

import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';

Expand All @@ -75,18 +76,13 @@ function DynamicIOURequestStepDistanceRate({
const [reportPolicyType] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {
selector: policyTypeSelector,
});
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`);
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(report?.parentReportID)}`);
const [iouReportOwnerLogin] = usePersonalDetail(parentReport?.ownerAccountID, loginSelector);
const [reportPolicyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`);

const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const personalPolicy = usePersonalPolicy();
const [currentTransactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${getNonEmptyStringOnyxID(transaction?.transactionID)}`);
const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector});
const [rules] = useOnyx(ONYXKEYS.COLLECTION.RULE);

const {policy: policyForTransaction} = usePolicyForTransaction({transaction, reportPolicyID: report?.policyID, action, iouType, policyDraft});
const {policyForMovingExpenses} = usePolicyForMovingExpenses();
Expand Down Expand Up @@ -184,7 +180,7 @@ function DynamicIOURequestStepDistanceRate({
const pinnedRateID = useInitialSelection(initiallySelectedRateID, {resetOnFocus: true});
const orderedOptions = moveInitialSelectionToTop(options, pinnedRateID ? [pinnedRateID] : []);

function selectDistanceRate(customUnitRateID: string) {
async function selectDistanceRate(customUnitRateID: string) {
// Validate that the new rate combined with the existing distance doesn't exceed the backend limit.
// This check runs before any state updates so that an invalid rate doesn't modify tax or rate state.
const newRate = rates[customUnitRateID]?.rate ?? 0;
Expand All @@ -211,6 +207,7 @@ function DynamicIOURequestStepDistanceRate({
let taxRateExternalID;
let taxValue;
if (shouldShowTax) {
const rules = await Onyx.get(ONYXKEYS.COLLECTION.RULE);
const distanceRateTaxUpdates = getDistanceRateTaxUpdates(policy, currentTransaction, customUnitRateID, rules, getCurrencyDecimals, currentUnit);
taxAmount = distanceRateTaxUpdates.taxAmount;
taxRateExternalID = distanceRateTaxUpdates.taxCode;
Expand Down Expand Up @@ -240,6 +237,13 @@ function DynamicIOURequestStepDistanceRate({
}

if (isEditing && transaction?.transactionID) {
const [rules, policyCategories, policyTags, reportPolicyTags, introSelected] = await Onyx.multiGet([
ONYXKEYS.COLLECTION.RULE,
`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report?.policyID}`,
`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report?.policyID}`,
`${ONYXKEYS.COLLECTION.POLICY_TAGS}${getNonEmptyStringOnyxID(parentReport?.policyID)}`,
ONYXKEYS.NVP_INTRO_SELECTED,
]);
// Persist preference so the default stays in sync across the workspace (the same way as in the setMoneyRequestDistanceRate)
setLastSelectedDistanceRate(policy, customUnitRateID);
updateMoneyRequestDistanceRate({
Expand All @@ -262,7 +266,7 @@ function DynamicIOURequestStepDistanceRate({
isOffline,
currentTransactionViolations,
reportPolicyTags,
isTrackIntentUser,
isTrackIntentUser: isTrackIntentUserSelector(introSelected),
personalPolicyOutputCurrency: personalPolicy?.outputCurrency,
getCurrencyDecimals,
getCurrencySymbol,
Expand Down
Loading
Loading