Skip to content

Commit

Permalink
Merge branch 'Expensify:main' into hide-the-search-icon-on-report-RHP…
Browse files Browse the repository at this point in the history
…-header
  • Loading branch information
rayane-djouah authored Oct 17, 2024
2 parents 8fe5756 + ee384b0 commit 024b277
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ function IOURequestStepConfirmation({
const isSubmittingFromTrackExpense = action === CONST.IOU.ACTION.SUBMIT;
const isMovingTransactionFromTrackExpense = IOUUtils.isMovingTransactionFromTrackExpense(action);
const payeePersonalDetails = useMemo(() => {
if (personalDetails?.[transaction?.splitPayerAccountIDs?.at(0) ?? -1]) {
return personalDetails?.[transaction?.splitPayerAccountIDs?.at(0) ?? -1];
if (personalDetails?.[transaction?.splitPayerAccountIDs?.[0] ?? -1]) {
return personalDetails?.[transaction?.splitPayerAccountIDs?.[0] ?? -1];
}

const participant = transaction?.participants?.find((val) => val.accountID === (transaction?.splitPayerAccountIDs?.at(0) ?? -1));
const participant = transaction?.participants?.find((val) => val.accountID === (transaction?.splitPayerAccountIDs?.[0] ?? -1));

return {
login: participant?.login ?? '',
Expand Down
40 changes: 1 addition & 39 deletions src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import usePolicy from '@hooks/usePolicy';
import usePrevious from '@hooks/usePrevious';
import useThemeStyles from '@hooks/useThemeStyles';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import type {MileageRate} from '@libs/DistanceRequestUtils';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as IOUUtils from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import * as IOU from '@userActions/IOU';
Expand All @@ -38,7 +36,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {Waypoint, WaypointCollection} from '@src/types/onyx/Transaction';
import StepScreenWrapper from './StepScreenWrapper';
Expand Down Expand Up @@ -86,7 +83,6 @@ function IOURequestStepDistance({
const scrollViewRef = useRef<RNScrollView>(null);
const isLoadingRoute = transaction?.comment?.isLoading ?? false;
const isLoading = transaction?.isLoading ?? false;
const isSplitRequest = iouType === CONST.IOU.TYPE.SPLIT;
const hasRouteError = !!transaction?.errorFields?.route;
const [shouldShowAtLeastTwoDifferentWaypointsError, setShouldShowAtLeastTwoDifferentWaypointsError] = useState(false);
const isWaypointEmpty = (waypoint?: Waypoint) => {
Expand All @@ -108,39 +104,7 @@ function IOURequestStepDistance({
const isCreatingNewRequest = !(backTo || isEditing);
const [recentWaypoints, {status: recentWaypointsStatus}] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS);
const iouRequestType = TransactionUtils.getRequestType(transaction);
const customUnitRateID = TransactionUtils.getRateID(transaction) ?? '-1';

// Sets `amount` and `split` share data before moving to the next step to avoid briefly showing `0.00` as the split share for participants
const setDistanceRequestData = useCallback(
(participants: Participant[]) => {
// Get policy report based on transaction participants
const isPolicyExpenseChat = participants?.some((participant) => participant.isPolicyExpenseChat);
const selectedReportID = participants?.length === 1 ? participants.at(0)?.reportID ?? reportID : reportID;
const policyReport = participants.at(0) ? ReportUtils.getReport(selectedReportID) : report;

const IOUpolicyID = IOU.getIOURequestPolicyID(transaction, policyReport);
const IOUpolicy = PolicyUtils.getPolicy(report?.policyID ?? IOUpolicyID);
const policyCurrency = policy?.outputCurrency ?? PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD;

const mileageRates = DistanceRequestUtils.getMileageRates(IOUpolicy);
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(IOUpolicy);
const mileageRate: MileageRate = TransactionUtils.isCustomUnitRateIDForP2P(transaction)
? DistanceRequestUtils.getRateForP2P(policyCurrency)
: mileageRates?.[customUnitRateID] ?? defaultMileageRate;

const {unit, rate} = mileageRate ?? {};
const distance = TransactionUtils.getDistanceInMeters(transaction, unit);
const currency = mileageRate?.currency ?? policyCurrency;
const amount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate ?? 0);
IOU.setMoneyRequestAmount(transactionID, amount, currency);

const participantAccountIDs: number[] | undefined = participants?.map((participant) => Number(participant.accountID ?? -1));
if (isSplitRequest && amount && currency && !isPolicyExpenseChat) {
IOU.setSplitShares(transaction, amount, currency ?? '', participantAccountIDs ?? []);
}
},
[report, transaction, transactionID, isSplitRequest, policy?.outputCurrency, reportID, customUnitRateID],
);
const customUnitRateID = TransactionUtils.getRateID(transaction);

// For quick button actions, we'll skip the confirmation page unless the report is archived or this is a workspace
// request and the workspace requires a category or a tag
Expand Down Expand Up @@ -281,7 +245,6 @@ function IOURequestStepDistance({
const participantAccountID = participant?.accountID ?? -1;
return participantAccountID ? OptionsListUtils.getParticipantsOption(participant, personalDetails) : OptionsListUtils.getReportOption(participant);
});
setDistanceRequestData(participants);
if (shouldSkipConfirmation) {
if (iouType === CONST.IOU.TYPE.SPLIT) {
IOU.splitBill({
Expand Down Expand Up @@ -385,7 +348,6 @@ function IOURequestStepDistance({
iouRequestType,
reportNameValuePairs,
customUnitRateID,
setDistanceRequestData,
]);

const getError = () => {
Expand Down

0 comments on commit 024b277

Please sign in to comment.