Skip to content

Commit

Permalink
Merge pull request #52081 from Expensify/neil-remove-p2p-distance-beta
Browse files Browse the repository at this point in the history
Remove P2P distance requests beta checks
  • Loading branch information
robertjchen authored Nov 7, 2024
2 parents 618aa40 + 692d250 commit ef76462
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 145 deletions.
8 changes: 2 additions & 6 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import {MouseProvider} from '@hooks/useMouseContext';
import usePermissions from '@hooks/usePermissions';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import blurActiveElement from '@libs/Accessibility/blurActiveElement';
Expand Down Expand Up @@ -195,7 +194,6 @@ function MoneyRequestConfirmationList({
const styles = useThemeStyles();
const {translate, toLocaleDigit} = useLocalize();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const {canUseP2PDistanceRequests} = usePermissions(iouType);

const isTypeRequest = iouType === CONST.IOU.TYPE.SUBMIT;
const isTypeSplit = iouType === CONST.IOU.TYPE.SPLIT;
Expand All @@ -214,9 +212,9 @@ function MoneyRequestConfirmationList({

const defaultRate = defaultMileageRate?.customUnitRateID ?? '';
const lastSelectedRate = lastSelectedDistanceRates?.[policy?.id ?? ''] ?? defaultRate;
const rateID = canUseP2PDistanceRequests ? lastSelectedRate : defaultRate;
const rateID = lastSelectedRate;
IOU.setCustomUnitRateID(transactionID, rateID);
}, [defaultMileageRate, customUnitRateID, lastSelectedDistanceRates, policy?.id, canUseP2PDistanceRequests, transactionID, isDistanceRequest]);
}, [defaultMileageRate, customUnitRateID, lastSelectedDistanceRates, policy?.id, transactionID, isDistanceRequest]);

const mileageRate = DistanceRequestUtils.getRate({transaction, policy, policyDraft});
const rate = mileageRate.rate;
Expand Down Expand Up @@ -880,7 +878,6 @@ function MoneyRequestConfirmationList({
const listFooterContent = (
<MoneyRequestConfirmationListFooter
action={action}
canUseP2PDistanceRequests={canUseP2PDistanceRequests}
currency={currency}
didConfirm={!!didConfirm}
distance={distance}
Expand All @@ -901,7 +898,6 @@ function MoneyRequestConfirmationList({
isEditingSplitBill={isEditingSplitBill}
isMerchantEmpty={isMerchantEmpty}
isMerchantRequired={isMerchantRequired}
isMovingTransactionFromTrackExpense={isMovingTransactionFromTrackExpense}
isPolicyExpenseChat={isPolicyExpenseChat}
isReadOnly={isReadOnly}
isTypeInvoice={isTypeInvoice}
Expand Down
32 changes: 2 additions & 30 deletions src/components/MoneyRequestConfirmationListFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ type MoneyRequestConfirmationListFooterProps = {
/** The action to perform */
action: IOUAction;

/** Flag indicating if P2P distance requests can be used */
canUseP2PDistanceRequests: boolean | undefined;

/** The currency of the transaction */
currency: string;

Expand Down Expand Up @@ -105,9 +102,6 @@ type MoneyRequestConfirmationListFooterProps = {
/** Flag indicating if the merchant is required */
isMerchantRequired: boolean | undefined;

/** Flag indicating if the transaction is moved from track expense */
isMovingTransactionFromTrackExpense: boolean;

/** Flag indicating if it is a policy expense chat */
isPolicyExpenseChat: boolean;

Expand Down Expand Up @@ -177,7 +171,6 @@ type MoneyRequestConfirmationListFooterProps = {

function MoneyRequestConfirmationListFooter({
action,
canUseP2PDistanceRequests,
currency,
didConfirm,
distance,
Expand All @@ -198,7 +191,6 @@ function MoneyRequestConfirmationListFooter({
isEditingSplitBill,
isMerchantEmpty,
isMerchantRequired,
isMovingTransactionFromTrackExpense,
isPolicyExpenseChat,
isReadOnly,
isTypeInvoice,
Expand Down Expand Up @@ -349,24 +341,6 @@ function MoneyRequestConfirmationListFooter({
shouldShow: true,
isSupplementary: false,
},
{
item: (
<MenuItemWithTopDescription
key={translate('common.distance')}
shouldShowRightIcon={!isReadOnly && !isMovingTransactionFromTrackExpense}
title={isMerchantEmpty ? '' : iouMerchant}
description={translate('common.distance')}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()))}
disabled={didConfirm}
// todo: handle edit for transaction while moving from track expense
interactive={!isReadOnly && !isMovingTransactionFromTrackExpense}
/>
),
shouldShow: isDistanceRequest && !canUseP2PDistanceRequests,
isSupplementary: false,
},
{
item: (
<MenuItemWithTopDescription
Expand All @@ -381,7 +355,7 @@ function MoneyRequestConfirmationListFooter({
interactive={!isReadOnly}
/>
),
shouldShow: isDistanceRequest && canUseP2PDistanceRequests,
shouldShow: isDistanceRequest,
isSupplementary: false,
},
{
Expand All @@ -398,7 +372,7 @@ function MoneyRequestConfirmationListFooter({
interactive={!!rate && !isReadOnly && isPolicyExpenseChat}
/>
),
shouldShow: isDistanceRequest && canUseP2PDistanceRequests,
shouldShow: isDistanceRequest,
isSupplementary: false,
},
{
Expand Down Expand Up @@ -692,7 +666,6 @@ export default memo(
MoneyRequestConfirmationListFooter,
(prevProps, nextProps) =>
lodashIsEqual(prevProps.action, nextProps.action) &&
prevProps.canUseP2PDistanceRequests === nextProps.canUseP2PDistanceRequests &&
prevProps.currency === nextProps.currency &&
prevProps.didConfirm === nextProps.didConfirm &&
prevProps.distance === nextProps.distance &&
Expand All @@ -711,7 +684,6 @@ export default memo(
prevProps.isEditingSplitBill === nextProps.isEditingSplitBill &&
prevProps.isMerchantEmpty === nextProps.isMerchantEmpty &&
prevProps.isMerchantRequired === nextProps.isMerchantRequired &&
prevProps.isMovingTransactionFromTrackExpense === nextProps.isMovingTransactionFromTrackExpense &&
prevProps.isPolicyExpenseChat === nextProps.isPolicyExpenseChat &&
prevProps.isReadOnly === nextProps.isReadOnly &&
prevProps.isTypeInvoice === nextProps.isTypeInvoice &&
Expand Down
25 changes: 1 addition & 24 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import ViolationMessages from '@components/ViolationMessages';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useViolations from '@hooks/useViolations';
Expand Down Expand Up @@ -102,7 +101,6 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals

const parentReportAction = parentReportActions?.[report?.parentReportActionID ?? '-1'];
const isTrackExpense = ReportUtils.isTrackExpenseReport(report);
const {canUseP2PDistanceRequests} = usePermissions(isTrackExpense ? CONST.IOU.TYPE.TRACK : undefined);
const moneyRequestReport = parentReport;
const linkedTransactionID = useMemo(() => {
const originalMessage = parentReportAction && ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction) : undefined;
Expand Down Expand Up @@ -307,7 +305,7 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
[transactionAmount, isSettled, isCancelled, isPolicyExpenseChat, isEmptyMerchant, transactionDate, readonly, hasErrors, hasViolations, translate, getViolationsForField],
);

const distanceRequestFields = canUseP2PDistanceRequests ? (
const distanceRequestFields = (
<>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
<MenuItemWithTopDescription
Expand Down Expand Up @@ -352,27 +350,6 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
/>
</OfflineWithFeedback>
</>
) : (
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
<MenuItemWithTopDescription
description={translate('common.distance')}
title={transactionMerchant}
interactive={canEditDistance}
shouldShowRightIcon={canEditDistance}
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_DISTANCE.getRoute(
CONST.IOU.ACTION.EDIT,
iouType,
transaction?.transactionID ?? '-1',
report?.reportID ?? '-1',
Navigation.getReportRHPActiveRoute(),
),
)
}
/>
</OfflineWithFeedback>
);

const isReceiptAllowed = !isPaidReport && !isInvoice;
Expand Down
7 changes: 3 additions & 4 deletions src/hooks/usePermissions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {useContext, useMemo} from 'react';
import {BetasContext} from '@components/OnyxProvider';
import Permissions from '@libs/Permissions';
import type {IOUType} from '@src/CONST';

type PermissionKey = keyof typeof Permissions;
type UsePermissions = Partial<Record<PermissionKey, boolean>>;
let permissionKey: PermissionKey;

export default function usePermissions(iouType: IOUType | undefined = undefined): UsePermissions {
export default function usePermissions(): UsePermissions {
const betas = useContext(BetasContext);
return useMemo(() => {
const permissions: UsePermissions = {};
Expand All @@ -16,10 +15,10 @@ export default function usePermissions(iouType: IOUType | undefined = undefined)
if (betas) {
const checkerFunction = Permissions[permissionKey];

permissions[permissionKey] = checkerFunction(betas, iouType);
permissions[permissionKey] = checkerFunction(betas);
}
}

return permissions;
}, [betas, iouType]);
}, [betas]);
}
4 changes: 2 additions & 2 deletions src/libs/DistanceRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function convertToDistanceInMeters(distance: number, unit: Unit): number {
/**
* Returns custom unit rate ID for the distance transaction
*/
function getCustomUnitRateID(reportID: string, shouldUseDefault?: boolean) {
function getCustomUnitRateID(reportID: string) {
const allReports = ReportConnection.getAllReports();
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`];
Expand All @@ -288,7 +288,7 @@ function getCustomUnitRateID(reportID: string, shouldUseDefault?: boolean) {
const distanceUnit = Object.values(policy?.customUnits ?? {}).find((unit) => unit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE);
const lastSelectedDistanceRateID = lastSelectedDistanceRates?.[policy?.id ?? '-1'] ?? '-1';
const lastSelectedDistanceRate = distanceUnit?.rates[lastSelectedDistanceRateID] ?? {};
if (lastSelectedDistanceRate.enabled && lastSelectedDistanceRateID && !shouldUseDefault) {
if (lastSelectedDistanceRate.enabled && lastSelectedDistanceRateID) {
customUnitRateID = lastSelectedDistanceRateID;
} else {
customUnitRateID = getDefaultMileageRate(policy)?.customUnitRateID ?? '-1';
Expand Down
7 changes: 0 additions & 7 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import type {IOUType} from '@src/CONST';
import type Beta from '@src/types/onyx/Beta';

function canUseAllBetas(betas: OnyxEntry<Beta[]>): boolean {
Expand All @@ -15,11 +14,6 @@ function canUseDupeDetection(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.DUPE_DETECTION) || canUseAllBetas(betas);
}

function canUseP2PDistanceRequests(betas: OnyxEntry<Beta[]>, iouType: IOUType | undefined): boolean {
// Allow using P2P distance request for TrackExpense outside of the beta, because that project doesn't want to be limited by the more cautious P2P distance beta
return !!betas?.includes(CONST.BETAS.P2P_DISTANCE_REQUESTS) || canUseAllBetas(betas) || iouType === CONST.IOU.TYPE.TRACK;
}

function canUseSpotnanaTravel(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.SPOTNANA_TRAVEL) || canUseAllBetas(betas);
}
Expand Down Expand Up @@ -52,7 +46,6 @@ export default {
canUseDefaultRooms,
canUseLinkPreviews,
canUseDupeDetection,
canUseP2PDistanceRequests,
canUseSpotnanaTravel,
canUseNetSuiteUSATax,
canUseCombinedTrackSubmit,
Expand Down
25 changes: 9 additions & 16 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
import Text from '@components/Text';
import UnreadActionIndicator from '@components/UnreadActionIndicator';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import usePrevious from '@hooks/usePrevious';
import useReportScrollManager from '@hooks/useReportScrollManager';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand All @@ -53,7 +52,6 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import SelectionScraper from '@libs/SelectionScraper';
import shouldRenderAddPaymentCard from '@libs/shouldRenderAppPaymentCard';
import * as TransactionUtils from '@libs/TransactionUtils';
import {ReactionListContext} from '@pages/home/ReportScreenContext';
import * as BankAccounts from '@userActions/BankAccounts';
import * as EmojiPickerAction from '@userActions/EmojiPickerAction';
Expand Down Expand Up @@ -198,7 +196,6 @@ function ReportActionItem({
const downloadedPreviews = useRef<string[]>([]);
const prevDraftMessage = usePrevious(draftMessage);
const [isUserValidated] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.validated});
const {canUseP2PDistanceRequests} = usePermissions();
// The app would crash due to subscribing to the entire report collection if parentReportID is an empty string. So we should have a fallback ID here.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID || -1}`);
Expand Down Expand Up @@ -421,18 +418,14 @@ function ReportActionItem({
if (ReportActionsUtils.isActionableTrackExpense(action)) {
const transactionID = ReportActionsUtils.getOriginalMessage(action)?.transactionID;
return [
...(!TransactionUtils.isDistanceRequest(TransactionUtils.getTransaction(transactionID ?? '-1')) || canUseP2PDistanceRequests
? [
{
text: 'actionableMentionTrackExpense.submit',
key: `${action.reportActionID}-actionableMentionTrackExpense-submit`,
onPress: () => {
ReportUtils.createDraftTransactionAndNavigateToParticipantSelector(transactionID ?? '0', reportID, CONST.IOU.ACTION.SUBMIT, action.reportActionID);
},
isMediumSized: true,
} as ActionableItem,
]
: []),
{
text: 'actionableMentionTrackExpense.submit',
key: `${action.reportActionID}-actionableMentionTrackExpense-submit`,
onPress: () => {
ReportUtils.createDraftTransactionAndNavigateToParticipantSelector(transactionID ?? '0', reportID, CONST.IOU.ACTION.SUBMIT, action.reportActionID);
},
isMediumSized: true,
},
{
text: 'actionableMentionTrackExpense.categorize',
key: `${action.reportActionID}-actionableMentionTrackExpense-categorize`,
Expand Down Expand Up @@ -505,7 +498,7 @@ function ReportActionItem({
onPress: () => Report.resolveActionableMentionWhisper(reportID, action, CONST.REPORT.ACTIONABLE_MENTION_WHISPER_RESOLUTION.NOTHING),
},
];
}, [action, isActionableWhisper, reportID, canUseP2PDistanceRequests]);
}, [action, isActionableWhisper, reportID]);

/**
* Get the content of ReportActionItem
Expand Down
23 changes: 8 additions & 15 deletions src/pages/iou/request/IOURequestStartPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function IOURequestStartPage({
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${route?.params.transactionID || -1}`);
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const {canUseP2PDistanceRequests, canUseCombinedTrackSubmit} = usePermissions(iouType);
const {canUseCombinedTrackSubmit} = usePermissions();

const tabTitles = {
[CONST.IOU.TYPE.REQUEST]: translate('iou.submitExpense'),
Expand All @@ -73,11 +73,6 @@ function IOURequestStartPage({
IOU.initMoneyRequest(reportID, policy, isFromGlobalCreate, transaction?.iouRequestType, transactionRequestType);
}, [transaction, policy, reportID, iouType, isFromGlobalCreate, transactionRequestType, isLoadingSelectedTab]);

const isExpenseChat = ReportUtils.isPolicyExpenseChat(report);
const isExpenseReport = ReportUtils.isExpenseReport(report);
const shouldDisplayDistanceRequest =
!!canUseCombinedTrackSubmit || !!canUseP2PDistanceRequests || isExpenseChat || isExpenseReport || (isFromGlobalCreate && iouType !== CONST.IOU.TYPE.SPLIT);

const navigateBack = () => {
Navigation.closeRHPFlow();
};
Expand Down Expand Up @@ -164,15 +159,13 @@ function IOURequestStartPage({
</TabScreenWithFocusTrapWrapper>
)}
</TopTab.Screen>
{shouldDisplayDistanceRequest && (
<TopTab.Screen name={CONST.TAB_REQUEST.DISTANCE}>
{() => (
<TabScreenWithFocusTrapWrapper>
<IOURequestStepDistance route={route} />
</TabScreenWithFocusTrapWrapper>
)}
</TopTab.Screen>
)}
<TopTab.Screen name={CONST.TAB_REQUEST.DISTANCE}>
{() => (
<TabScreenWithFocusTrapWrapper>
<IOURequestStepDistance route={route} />
</TabScreenWithFocusTrapWrapper>
)}
</TopTab.Screen>
</OnyxTabNavigator>
) : (
<FocusTrapContainerElement
Expand Down
Loading

0 comments on commit ef76462

Please sign in to comment.