Skip to content

Commit

Permalink
Merge pull request #54076 from Expensify/revert-paultsimura/fix/46897…
Browse files Browse the repository at this point in the history
…-distance-accountant

(cherry picked from commit f48bc89)

(CP triggered by luacmartins)
  • Loading branch information
cead22 authored and OSBotify committed Dec 12, 2024
1 parent 71ea086 commit 8f1f8c6
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 183 deletions.
53 changes: 6 additions & 47 deletions src/components/MoneyRequestConfirmationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ function MoneyRequestConfirmationList({
}

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

const mileageRate = DistanceRequestUtils.getRate({transaction, policy, policyDraft});
Expand Down Expand Up @@ -277,18 +278,6 @@ function MoneyRequestConfirmationList({
const [didConfirm, setDidConfirm] = useState(isConfirmed);
const [didConfirmSplit, setDidConfirmSplit] = useState(false);

// Clear the form error if it's set to one among the list passed as an argument
const clearFormErrors = useCallback(
(errors: string[]) => {
if (!errors.includes(formError)) {
return;
}

setFormError('');
},
[formError, setFormError],
);

const shouldDisplayFieldError: boolean = useMemo(() => {
if (!isEditingSplitBill) {
return false;
Expand Down Expand Up @@ -330,33 +319,6 @@ function MoneyRequestConfirmationList({
}, [isFocused, transaction, shouldDisplayFieldError, hasSmartScanFailed, didConfirmSplit]);

const routeError = Object.values(transaction?.errorFields?.route ?? {}).at(0);

useEffect(() => {
// We want this effect to run only when the transaction is moving from Self DM to a workspace chat
if (!isDistanceRequest || !isMovingTransactionFromTrackExpense || !isPolicyExpenseChat) {
return;
}

const errorKey = 'iou.error.invalidRate';
const policyRates = DistanceRequestUtils.getMileageRates(policy);

// If the selected rate belongs to the policy, clear the error
if (Object.keys(policyRates).includes(customUnitRateID)) {
clearFormErrors([errorKey]);
return;
}

// If there is a distance rate in the policy that matches the rate and unit of the currently selected mileage rate, select it automatically
const matchingRate = Object.values(policyRates).find((policyRate) => policyRate.rate === mileageRate.rate && policyRate.unit === mileageRate.unit);
if (matchingRate?.customUnitRateID) {
IOU.setCustomUnitRateID(transactionID, matchingRate.customUnitRateID);
return;
}

// If none of the above conditions are met, display the rate error
setFormError(errorKey);
}, [isDistanceRequest, isPolicyExpenseChat, transactionID, mileageRate, customUnitRateID, policy, isMovingTransactionFromTrackExpense, setFormError, clearFormErrors]);

const isFirstUpdatedDistanceAmount = useRef(false);

useEffect(() => {
Expand Down Expand Up @@ -507,8 +469,8 @@ function MoneyRequestConfirmationList({
return;
}

clearFormErrors(['iou.error.invalidSplit', 'iou.error.invalidSplitParticipants', 'iou.error.invalidSplitYourself']);
}, [isFocused, transaction, isTypeSplit, transaction?.splitShares, currentUserPersonalDetails.accountID, iouAmount, iouCurrencyCode, setFormError, translate, clearFormErrors]);
setFormError('');
}, [isFocused, transaction, isTypeSplit, transaction?.splitShares, currentUserPersonalDetails.accountID, iouAmount, iouCurrencyCode, setFormError, translate]);

useEffect(() => {
if (!isTypeSplit || !transaction?.splitShares) {
Expand Down Expand Up @@ -675,9 +637,7 @@ function MoneyRequestConfirmationList({
}, [isTypeSplit, translate, payeePersonalDetails, getSplitSectionHeader, splitParticipants, selectedParticipants]);

useEffect(() => {
if (!isDistanceRequest || (isMovingTransactionFromTrackExpense && !isPolicyExpenseChat)) {
// We don't want to recalculate the distance merchant when moving a transaction from Track Expense to a 1:1 chat, because the distance rate will be the same default P2P rate.
// When moving to a policy chat (e.g. sharing with an accountant), we should recalculate the distance merchant with the policy's rate.
if (!isDistanceRequest || isMovingTransactionFromTrackExpense) {
return;
}

Expand All @@ -700,7 +660,6 @@ function MoneyRequestConfirmationList({
translate,
toLocaleDigit,
isDistanceRequest,
isPolicyExpenseChat,
transaction,
transactionID,
action,
Expand Down
2 changes: 0 additions & 2 deletions src/components/MoneyRequestConfirmationListFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ function MoneyRequestConfirmationListFooter({
const taxRateTitle = TransactionUtils.getTaxName(policy, transaction);
// Determine if the merchant error should be displayed
const shouldDisplayMerchantError = isMerchantRequired && (shouldDisplayFieldError || formError === 'iou.error.invalidMerchant') && isMerchantEmpty;
const shouldDisplayDistanceRateError = formError === 'iou.error.invalidRate';
// The empty receipt component should only show for IOU Requests of a paid policy ("Team" or "Corporate")
const shouldShowReceiptEmptyState = iouType === CONST.IOU.TYPE.SUBMIT && PolicyUtils.isPaidGroupPolicy(policy);
const {
Expand Down Expand Up @@ -370,7 +369,6 @@ function MoneyRequestConfirmationListFooter({
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_DISTANCE_RATE.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams()))}
brickRoadIndicator={shouldDisplayDistanceRateError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
disabled={didConfirm}
interactive={!!rate && !isReadOnly && isPolicyExpenseChat}
/>
Expand Down
3 changes: 0 additions & 3 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ import type {
MarkedReimbursedParams,
MarkReimbursedFromIntegrationParams,
MissingPropertyParams,
MovedFromSelfDMParams,
NoLongerHaveAccessParams,
NotAllowedExtensionParams,
NotYouParams,
Expand Down Expand Up @@ -980,7 +979,6 @@ const translations = {
threadExpenseReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `${formattedAmount} ${comment ? `for ${comment}` : 'expense'}`,
threadTrackReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `Tracking ${formattedAmount} ${comment ? `for ${comment}` : ''}`,
threadPaySomeoneReportName: ({formattedAmount, comment}: ThreadSentMoneyReportNameParams) => `${formattedAmount} sent${comment ? ` for ${comment}` : ''}`,
movedFromSelfDM: ({workspaceName, reportName}: MovedFromSelfDMParams) => `moved expense from self DM to ${workspaceName ?? `chat with ${reportName}`}`,
tagSelection: 'Select a tag to better organize your spend.',
categorySelection: 'Select a category to better organize your spend.',
error: {
Expand Down Expand Up @@ -1010,7 +1008,6 @@ const translations = {
splitExpenseMultipleParticipantsErrorMessage: 'An expense cannot be split between a workspace and other members. Please update your selection.',
invalidMerchant: 'Please enter a correct merchant.',
atLeastOneAttendee: 'At least one attendee must be selected',
invalidRate: 'Rate not valid for this workspace. Please select an available rate from the workspace.',
},
waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `started settling up. Payment is on hold until ${submitterDisplayName} enables their wallet.`,
enableWallet: 'Enable wallet',
Expand Down
3 changes: 0 additions & 3 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ import type {
MarkedReimbursedParams,
MarkReimbursedFromIntegrationParams,
MissingPropertyParams,
MovedFromSelfDMParams,
NoLongerHaveAccessParams,
NotAllowedExtensionParams,
NotYouParams,
Expand Down Expand Up @@ -978,7 +977,6 @@ const translations = {
threadExpenseReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `${comment ? `${formattedAmount} para ${comment}` : `Gasto de ${formattedAmount}`}`,
threadTrackReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `Seguimiento ${formattedAmount} ${comment ? `para ${comment}` : ''}`,
threadPaySomeoneReportName: ({formattedAmount, comment}: ThreadSentMoneyReportNameParams) => `${formattedAmount} enviado${comment ? ` para ${comment}` : ''}`,
movedFromSelfDM: ({workspaceName, reportName}: MovedFromSelfDMParams) => `movió el gasto desde su propio mensaje directo a ${workspaceName ?? `un chat con ${reportName}`}`,
tagSelection: 'Selecciona una etiqueta para organizar mejor tus gastos.',
categorySelection: 'Selecciona una categoría para organizar mejor tus gastos.',
error: {
Expand Down Expand Up @@ -1008,7 +1006,6 @@ const translations = {
splitExpenseMultipleParticipantsErrorMessage: 'Solo puedes dividir un gasto entre un único espacio de trabajo o con miembros individuales. Por favor, actualiza tu selección.',
invalidMerchant: 'Por favor, introduce un comerciante correcto.',
atLeastOneAttendee: 'Debe seleccionarse al menos un asistente',
invalidRate: 'Tasa no válida para este espacio de trabajo. Por favor, selecciona una tasa disponible en el espacio de trabajo.',
},
waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `inició el pago, pero no se procesará hasta que ${submitterDisplayName} active su billetera`,
enableWallet: 'Habilitar billetera',
Expand Down
5 changes: 1 addition & 4 deletions src/languages/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ type ThreadRequestReportNameParams = {formattedAmount: string; comment: string};

type ThreadSentMoneyReportNameParams = {formattedAmount: string; comment: string};

type MovedFromSelfDMParams = {workspaceName?: string; reportName?: string};

type SizeExceededParams = {maxUploadSizeInMB: number};

type ResolutionConstraintsParams = {minHeightInPx: number; minWidthInPx: number; maxHeightInPx: number; maxWidthInPx: number};
Expand Down Expand Up @@ -669,7 +667,7 @@ export type {
LoggedInAsParams,
ManagerApprovedAmountParams,
ManagerApprovedParams,
MovedFromSelfDMParams,
SignUpNewFaceCodeParams,
NoLongerHaveAccessParams,
NotAllowedExtensionParams,
NotYouParams,
Expand Down Expand Up @@ -703,7 +701,6 @@ export type {
SetTheRequestParams,
SettleExpensifyCardParams,
SettledAfterAddedBankAccountParams,
SignUpNewFaceCodeParams,
SizeExceededParams,
SplitAmountParams,
StepCounterParams,
Expand Down
6 changes: 0 additions & 6 deletions src/libs/API/parameters/CategorizeTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ type CategorizeTrackedExpenseParams = {
taxCode: string;
taxAmount: number;
billable?: boolean;
waypoints?: string;
customUnitRateID?: string;
policyExpenseChatReportID?: string;
policyExpenseCreatedReportActionID?: string;
adminsChatReportID?: string;
adminsCreatedReportActionID?: string;
};

export default CategorizeTrackedExpenseParams;
6 changes: 0 additions & 6 deletions src/libs/API/parameters/ShareTrackedExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ type ShareTrackedExpenseParams = {
taxCode: string;
taxAmount: number;
billable?: boolean;
waypoints?: string;
customUnitRateID?: string;
policyExpenseChatReportID?: string;
policyExpenseCreatedReportActionID?: string;
adminsChatReportID?: string;
adminsCreatedReportActionID?: string;
};

export default ShareTrackedExpenseParams;
22 changes: 0 additions & 22 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import isEmpty from 'lodash/isEmpty';
import Onyx from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
Expand All @@ -10,8 +9,6 @@ import * as Localize from './Localize';
import Log from './Log';
import * as PolicyUtils from './PolicyUtils';
import * as ReportActionsUtils from './ReportActionsUtils';
// eslint-disable-next-line import/no-cycle
import {buildReportNameFromParticipantNames, getPolicyExpenseChatName, getPolicyName, getRootParentReport, isPolicyExpenseChat} from './ReportUtils';
import * as TransactionUtils from './TransactionUtils';

let allPolicyTags: OnyxCollection<PolicyTagLists> = {};
Expand Down Expand Up @@ -135,20 +132,6 @@ function getForDistanceRequest(newMerchant: string, oldMerchant: string, newAmou
});
}

function getForExpenseMovedFromSelfDM(destinationReportID: string) {
const destinationReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${destinationReportID}`];
const rootParentReport = getRootParentReport(destinationReport);

// The "Move report" flow only supports moving expenses to a policy expense chat or a 1:1 DM.
const reportName = isPolicyExpenseChat(rootParentReport) ? getPolicyExpenseChatName(rootParentReport) : buildReportNameFromParticipantNames({report: rootParentReport});
const policyName = getPolicyName(rootParentReport, true);

return Localize.translateLocal('iou.movedFromSelfDM', {
reportName,
workspaceName: !isEmpty(policyName) ? policyName : undefined,
});
}

/**
* Get the report action message when expense has been modified.
*
Expand All @@ -159,14 +142,9 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
if (!ReportActionsUtils.isModifiedExpenseAction(reportAction)) {
return '';
}

const reportActionOriginalMessage = ReportActionsUtils.getOriginalMessage(reportAction);
const policyID = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]?.policyID ?? '-1';

if (reportActionOriginalMessage?.movedToReportID) {
return getForExpenseMovedFromSelfDM(reportActionOriginalMessage.movedToReportID);
}

const removalFragments: string[] = [];
const setFragments: string[] = [];
const changeFragments: string[] = [];
Expand Down
29 changes: 10 additions & 19 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
import Log from './Log';
import {isEmailPublicDomain} from './LoginUtils';
// eslint-disable-next-line import/no-cycle
import ModifiedExpenseMessage from './ModifiedExpenseMessage';
import linkingConfig from './Navigation/linkingConfig';
import Navigation from './Navigation/Navigation';
Expand Down Expand Up @@ -3916,21 +3915,6 @@ const reportNameCache = new Map<string, {lastVisibleActionCreated: string; repor
*/
const getCacheKey = (report: OnyxEntry<Report>): string => `${report?.reportID}-${report?.lastVisibleActionCreated}-${report?.reportName}`;

/**
* Get the title for a report using only participant names. This may be used for 1:1 DMs and other non-categorized chats.
*/
function buildReportNameFromParticipantNames({report, personalDetails}: {report: OnyxEntry<Report>; personalDetails?: Partial<PersonalDetailsList>}) {
const participantsWithoutCurrentUser: number[] = [];
Object.keys(report?.participants ?? {}).forEach((accountID) => {
const accID = Number(accountID);
if (accID !== currentUserAccountID && participantsWithoutCurrentUser.length < 5) {
participantsWithoutCurrentUser.push(accID);
}
});
const isMultipleParticipantReport = participantsWithoutCurrentUser.length > 1;
return participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport, true, false, personalDetails)).join(', ');
}

/**
* Get the title for a report.
*/
Expand Down Expand Up @@ -4094,7 +4078,16 @@ function getReportName(
}

// Not a room or PolicyExpenseChat, generate title from first 5 other participants
formattedName = buildReportNameFromParticipantNames({report, personalDetails});
const participantsWithoutCurrentUser: number[] = [];
Object.keys(report?.participants ?? {}).forEach((accountID) => {
const accID = Number(accountID);
if (accID !== currentUserAccountID && participantsWithoutCurrentUser.length < 5) {
participantsWithoutCurrentUser.push(accID);
}
});
const isMultipleParticipantReport = participantsWithoutCurrentUser.length > 1;
const participantNames = participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport, true, false, personalDetails)).join(', ');
formattedName = participantNames;

if (reportID) {
reportNameCache.set(cacheKey, {lastVisibleActionCreated: report?.lastVisibleActionCreated ?? '', reportName: formattedName});
Expand Down Expand Up @@ -8530,7 +8523,6 @@ export {
buildOptimisticWorkspaceChats,
buildOptimisticCardAssignedReportAction,
buildParticipantsFromAccountIDs,
buildReportNameFromParticipantNames,
buildTransactionThread,
canAccessReport,
isReportNotFound,
Expand Down Expand Up @@ -8618,7 +8610,6 @@ export {
getPersonalDetailsForAccountID,
getPolicyDescriptionText,
getPolicyExpenseChat,
getPolicyExpenseChatName,
getPolicyName,
getPolicyType,
getReimbursementDeQueuedActionMessage,
Expand Down
Loading

0 comments on commit 8f1f8c6

Please sign in to comment.