Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [P2P Distance] Split - Participants amount displayed 0.00 briefly on confirmation screen. #47370

Merged
merged 22 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cbc9815
fix: [P2P Distance] Split - Participants amount displayed 0.00 briefl…
Krishna2323 Aug 14, 2024
0d5d809
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Aug 16, 2024
377be13
minor fixes.
Krishna2323 Aug 16, 2024
932a839
minor update.
Krishna2323 Aug 16, 2024
99f37b3
remove extra dependency.
Krishna2323 Aug 16, 2024
5e894bd
add suggested changes.
Krishna2323 Aug 18, 2024
30e13cc
define type for mileageRate.
Krishna2323 Aug 18, 2024
e9992b9
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Sep 2, 2024
b343447
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Sep 9, 2024
1d7dab0
remove redundant code.
Krishna2323 Sep 9, 2024
be91889
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Sep 12, 2024
b2fcb63
revert useEffect to update the amount.
Krishna2323 Sep 15, 2024
fc1fe00
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Sep 15, 2024
82e288d
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Sep 24, 2024
f7e386d
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Oct 1, 2024
b5293d1
move the logic to update amount for split in IOURequestStepDistance.
Krishna2323 Oct 2, 2024
35af9ce
fix: empty participants issue.
Krishna2323 Oct 2, 2024
98ca6ac
remove console log.
Krishna2323 Oct 2, 2024
3caf979
fix: lint issues.
Krishna2323 Oct 2, 2024
2558819
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Oct 5, 2024
dfad015
Merge branch 'Expensify:main' into krishna2323/issue/47100
Krishna2323 Oct 15, 2024
22ada28
minor updates.
Krishna2323 Oct 15, 2024
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
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 @@ -87,11 +87,11 @@ function IOURequestStepConfirmation({
const isSubmittingFromTrackExpense = action === CONST.IOU.ACTION.SUBMIT;
const isMovingTransactionFromTrackExpense = IOUUtils.isMovingTransactionFromTrackExpense(action);
const payeePersonalDetails = useMemo(() => {
if (personalDetails?.[transaction?.splitPayerAccountIDs?.[0] ?? -1]) {
return personalDetails?.[transaction?.splitPayerAccountIDs?.[0] ?? -1];
if (personalDetails?.[transaction?.splitPayerAccountIDs?.at(0) ?? -1]) {
return personalDetails?.[transaction?.splitPayerAccountIDs?.at(0) ?? -1];
}

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

return {
login: participant?.login ?? '',
Expand Down
40 changes: 39 additions & 1 deletion src/pages/iou/request/step/IOURequestStepDistance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
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 @@ -36,6 +38,7 @@
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 @@ -83,6 +86,7 @@
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 @@ -104,7 +108,39 @@
const isCreatingNewRequest = !(backTo || isEditing);
const [recentWaypoints, {status: recentWaypointsStatus}] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS);
const iouRequestType = TransactionUtils.getRequestType(transaction);
const customUnitRateID = TransactionUtils.getRateID(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[0]?.reportID ?? reportID : reportID;

Check failure on line 118 in src/pages/iou/request/step/IOURequestStepDistance.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer using the `.at()` method for array element access

Check failure on line 118 in src/pages/iou/request/step/IOURequestStepDistance.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Prefer using the `.at()` method for array element access
const policyReport = participants?.[0] ? ReportUtils.getReport(selectedReportID) : report;

Check failure on line 119 in src/pages/iou/request/step/IOURequestStepDistance.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Prefer using the `.at()` method for array element access

Check failure on line 119 in src/pages/iou/request/step/IOURequestStepDistance.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Prefer using the `.at()` method for array element access

const policyID2 = IOU.getIOURequestPolicyID(transaction, policyReport);
const policy2 = PolicyUtils.getPolicy(report?.policyID ?? policyID2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is policy2? Please rename it.

const policyCurrency = policy?.outputCurrency ?? PolicyUtils.getPersonalPolicy()?.outputCurrency ?? CONST.CURRENCY.USD;

const mileageRates = DistanceRequestUtils.getMileageRates(policy2);
const defaultMileageRate = DistanceRequestUtils.getDefaultMileageRate(policy2);
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],
);

// 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 @@ -245,6 +281,7 @@
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 @@ -348,6 +385,7 @@
iouRequestType,
reportNameValuePairs,
customUnitRateID,
setDistanceRequestData,
]);

const getError = () => {
Expand Down
Loading