-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Manual Distance Flow] - Add distance rate edits #69589
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
Changes from all commits
059f89b
5a2d2a9
e938447
3b01055
028d3fb
54b8f4e
c30e175
ec5f535
e1621be
b92dd60
05afa01
67c5640
cbd3110
07913db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4306,7 +4306,6 @@ function getUpdateMoneyRequestParams( | |
| key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, | ||
| value: { | ||
| ...updatedTransaction, | ||
| pendingFields, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please quickly explain why this was removed? I guess it's probably handled elsewhere already?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was removed because it was overriding the pending fields returned from the |
||
| errorFields: null, | ||
| }, | ||
| }); | ||
|
|
@@ -4869,7 +4868,8 @@ function updateMoneyRequestTaxRate({transactionID, optimisticReportActionID, tax | |
| type UpdateMoneyRequestDistanceParams = { | ||
| transactionID: string | undefined; | ||
| transactionThreadReportID: string | undefined; | ||
| waypoints: WaypointCollection; | ||
| waypoints?: WaypointCollection; | ||
| distance?: number; | ||
| routes?: Routes; | ||
| policy?: OnyxEntry<OnyxTypes.Policy>; | ||
| policyTagList?: OnyxEntry<OnyxTypes.PolicyTagLists>; | ||
|
|
@@ -4882,15 +4882,17 @@ function updateMoneyRequestDistance({ | |
| transactionID, | ||
| transactionThreadReportID, | ||
| waypoints, | ||
| distance, | ||
| routes = undefined, | ||
| policy = {} as OnyxTypes.Policy, | ||
| policyTagList = {}, | ||
| policyCategories = {}, | ||
| transactionBackup, | ||
| }: UpdateMoneyRequestDistanceParams) { | ||
| const transactionChanges: TransactionChanges = { | ||
| waypoints: sanitizeRecentWaypoints(waypoints), | ||
| ...(waypoints && {waypoints: sanitizeRecentWaypoints(waypoints)}), | ||
| routes, | ||
| ...(distance && {distance}), | ||
| }; | ||
| const transactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`] ?? null; | ||
| const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReport?.parentReportID}`] ?? null; | ||
|
|
@@ -4902,12 +4904,14 @@ function updateMoneyRequestDistance({ | |
| } | ||
| const {params, onyxData} = data; | ||
|
|
||
| const recentServerValidatedWaypoints = getRecentWaypoints().filter((item) => !item.pendingAction); | ||
| onyxData?.failureData?.push({ | ||
| onyxMethod: Onyx.METHOD.SET, | ||
| key: `${ONYXKEYS.NVP_RECENT_WAYPOINTS}`, | ||
| value: recentServerValidatedWaypoints, | ||
| }); | ||
| if (!distance) { | ||
| const recentServerValidatedWaypoints = getRecentWaypoints().filter((item) => !item.pendingAction); | ||
| onyxData?.failureData?.push({ | ||
| onyxMethod: Onyx.METHOD.SET, | ||
| key: `${ONYXKEYS.NVP_RECENT_WAYPOINTS}`, | ||
| value: recentServerValidatedWaypoints, | ||
| }); | ||
| } | ||
|
|
||
| if (transactionBackup) { | ||
| const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,11 @@ import { | |
| setMoneyRequestParticipantsFromReport, | ||
| setMoneyRequestPendingFields, | ||
| trackExpense, | ||
| updateMoneyRequestDistance, | ||
| } from '@libs/actions/IOU'; | ||
| import {canUseTouchScreen} from '@libs/DeviceCapabilities'; | ||
| import DistanceRequestUtils from '@libs/DistanceRequestUtils'; | ||
| import {navigateToParticipantPage} from '@libs/IOUUtils'; | ||
| import {navigateToParticipantPage, shouldUseTransactionDraft} from '@libs/IOUUtils'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {roundToTwoDecimalPlaces} from '@libs/NumberUtils'; | ||
| import {getParticipantsOption, getReportOption} from '@libs/OptionsListUtils'; | ||
|
|
@@ -80,9 +81,10 @@ function IOURequestStepDistanceManual({ | |
| const [reportAttributesDerived] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {canBeMissing: true, selector: (val) => val?.reports}); | ||
|
|
||
| const isEditing = action === CONST.IOU.ACTION.EDIT; | ||
| const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; | ||
| const isCreatingNewRequest = !(backTo || isEditing); | ||
|
|
||
| const isTransactionDraft = shouldUseTransactionDraft(action, iouType); | ||
|
|
||
| const customUnitRateID = getRateID(transaction); | ||
| const unit = DistanceRequestUtils.getRate({transaction, policy}).unit; | ||
| const distance = transaction?.comment?.customUnit?.quantity ? roundToTwoDecimalPlaces(transaction.comment.customUnit.quantity) : undefined; | ||
|
|
@@ -95,12 +97,12 @@ function IOURequestStepDistanceManual({ | |
| }, [distance]); | ||
|
|
||
| const shouldSkipConfirmation: boolean = useMemo(() => { | ||
| if (isSplitBill || !skipConfirmation || !report?.reportID) { | ||
| if (!skipConfirmation || !report?.reportID) { | ||
| return false; | ||
| } | ||
|
|
||
| return !(isArchivedReport(reportNameValuePairs) || isPolicyExpenseChatUtils(report)); | ||
| }, [report, isSplitBill, skipConfirmation, reportNameValuePairs]); | ||
| }, [report, skipConfirmation, reportNameValuePairs]); | ||
|
|
||
| useFocusEffect( | ||
| useCallback(() => { | ||
|
|
@@ -120,14 +122,11 @@ function IOURequestStepDistanceManual({ | |
|
|
||
| const buttonText = useMemo(() => { | ||
| if (shouldSkipConfirmation) { | ||
| if (iouType === CONST.IOU.TYPE.SPLIT) { | ||
| return translate('iou.split'); | ||
| } | ||
| return translate('iou.createExpense'); | ||
| } | ||
|
|
||
| return isCreatingNewRequest ? translate('common.next') : translate('common.save'); | ||
| }, [shouldSkipConfirmation, translate, isCreatingNewRequest, iouType]); | ||
| }, [shouldSkipConfirmation, translate, isCreatingNewRequest]); | ||
|
|
||
| const navigateToConfirmationPage = useCallback(() => { | ||
| switch (iouType) { | ||
|
|
@@ -142,7 +141,22 @@ function IOURequestStepDistanceManual({ | |
| const navigateToNextPage = useCallback( | ||
| (amount: string) => { | ||
| const distanceAsFloat = roundToTwoDecimalPlaces(parseFloat(amount)); | ||
| setMoneyRequestDistance(transactionID, distanceAsFloat, isCreatingNewRequest); | ||
| setMoneyRequestDistance(transactionID, distanceAsFloat, isTransactionDraft); | ||
|
|
||
| if (action === CONST.IOU.ACTION.EDIT) { | ||
| if (distance !== distanceAsFloat) { | ||
|
Comment on lines
+146
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB Combine to one if statement with an && expression. |
||
| updateMoneyRequestDistance({ | ||
| transactionID: transaction?.transactionID, | ||
| transactionThreadReportID: reportID, | ||
| distance: distanceAsFloat, | ||
| // Not required for manual distance request | ||
| transactionBackup: undefined, | ||
|
neil-marcellini marked this conversation as resolved.
|
||
| policy, | ||
| }); | ||
| } | ||
| Navigation.goBack(backTo); | ||
| return; | ||
| } | ||
|
|
||
| if (backTo) { | ||
| Navigation.goBack(backTo); | ||
|
|
@@ -253,7 +267,7 @@ function IOURequestStepDistanceManual({ | |
| currentUserPersonalDetails.login, | ||
| currentUserPersonalDetails.accountID, | ||
| reportNameValuePairs, | ||
| isCreatingNewRequest, | ||
| isTransactionDraft, | ||
| activePolicy, | ||
| shouldSkipConfirmation, | ||
| personalDetails, | ||
|
|
@@ -263,6 +277,8 @@ function IOURequestStepDistanceManual({ | |
| customUnitRateID, | ||
| translate, | ||
| navigateToConfirmationPage, | ||
| action, | ||
| distance, | ||
| ], | ||
| ); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these changes?