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

Modify MoneyRequestConfirmPage for Distance Request #25707

Merged
merged 116 commits into from
Sep 1, 2023

Conversation

hayata-suenaga
Copy link
Contributor

@hayata-suenaga hayata-suenaga commented Aug 22, 2023

@tgolen

Details

Display a map with the distance route on MoneyRequestConfirmPage.

Fixed Issues

$ #22710

Tests / QA

Creating a distance request from a workspace chat

Test 1: Check Distance Request is only available in Workspace chats and Global Create

Video walkthrough
Screen.Recording.2023-08-29.at.5.19.57.PM.mov

Distance Request should be only available for Workspace chats and Global Create. In non-workspace chats, the Distance Request tab should not be visible

  1. Go to a workspace chat. Click the "+" button next to the text composer and click "Request money." Confirm you DO see the Distance Request tab.
  2. Go to a non-workspace chat. Click the "+" button next to the text composer and click "Request money." Confirm you DO NOT see the Distance Request tab.
  3. Click the Global Create Floating Button and click "Request money." Confirm you DO see the Distance Request tab.

Test 2: Create a distance request from a Workspace chat

🔔 Test steps 20 ~ 24 are not ready. Waiting for other PR. The video walkthrough is for Steps 1 ~ 19

Video walkthrough
Screen.Recording.2023-08-29.at.4.46.06.PM.mov
  1. Go to a Workspace chat. If you don't have a workspace yet, create one.

  2. Click the "+" button in the text field.

  3. Click "Request money" on the popup

  4. Click the "Distance" tab on the next screen that appears

  5. Click the "Start" item in the list of waypoints

  6. On the text field in the next screen, type 88 Kearny Street. Select the first option.
    Screenshot 2023-08-21 at 1 26 47 PM

  7. Click the "Finish" item in the list of waypoints

  8. On the text field in the next screen, type "1 Telegraph Hill". Click the first option that appears.
    Screenshot 2023-08-24 at 5 17 28 PM

  9. Click the "Next" button

  10. Confirm that the next screen (Money Request Confirm Page) looks like the screenshot below. Check "Amount" is $0.92.
    Screenshot 2023-08-24 at 5 19 15 PM

  11. Click "Show more" and confirm the screen looks like below.
    Screenshot 2023-08-29 at 5 33 10 PM

  12. Check you're taken back to the previous (Distance Request) screen. Click "Next" button again.

  13. Click "Date". Check you can change and save the date.

  14. Click "Description". Check you can add and save the description.

  15. At this time, we won't check if "Amount" will work or not. Click "Request $0.92 button at the bottom.

  16. Confirm that the Right Hand Panel (where we were creating the distance request) is closed

  17. Confirm you're still in the same workspace chat and a new distance request is created.

  18. Click the distance request created.

  19. Confirm that you're taken to the distance request details page. Confirm information displayed is the same information you inputted.

  20. Go back to the workspace chat and create another distance request. Confirm that the map is reset to the initial state without any waypoints or route drawn.

  21. Click "Next" and this time, click "Amount"

  22. Try to click the dollar sign "$". Check that nothing happens when you click it (to confirm the currency is not editable)

  23. Edit the amount and save. Confirm the amount is updated on the confirmation page. Click "Request $<new amount>" at the bottom to create the new distance request.

  24. Check the newly created distance request has the correct amount to which you changed.

Test 3: Create a distance request through Global Create

Video walkthrough
global_create_test.mov
  1. Make sure you existing chats other than the test workspace.

  2. Click the Global Create button (the floating "+" button).

  3. Click "Request Money"

  4. Repeat the steps from steps 4 - 9 from the first test.

  5. Check the next screen appears looks like the screenshot below. On this screen, you can select to who/where you make distance request. Make sure that only workspace(s) appear as options. Make sure that no personal account appears as selections (step 1 was for this purpose).

    Screenshot 2023-08-24 at 5 40 02 PM
  6. Select a workspace and confirm that the next screen that appears looks like the screenshot from step 10 of the first test (Confirm page).

Offline tests

Video walkthrough
Screen.Recording.2023-08-29.at.10.08.25.PM.mov
  1. Go to the Distance Request page
  2. Go to the developer console and toggle the network to offline
  3. Check that a placeholder offline component takes place of the map
  4. Bring the network online and save two waypoints so that "Next" button can be clicked. Click the next button.
  5. Toggle the network to offline again. Check that the placeholder component takes place of the map

QA Steps

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

Please refer to the screen recordings for Tests #1 #2, and #3 above

Mobile Web - Chrome
Screen.Recording.2023-08-29.at.10.25.21.PM.mov
Mobile Web - Safari
Screen.Recording.2023-08-29.at.10.20.37.PM.mov
Desktop
Screen.Recording.2023-08-29.at.10.18.15.PM.mov
iOS
Screen.Recording.2023-08-29.at.10.35.16.PM.mov
Android

My development environment is not working for Android

@hayata-suenaga
Copy link
Contributor Author

hayata-suenaga commented Aug 22, 2023

UPDATE: was able to display the map on the confirmation page.

Screenshot 2023-08-22 at 12 21 12 PM

This afternoon, I gonna work on:

  • Calculate the request amount
  • Only render the map when the money request is a distance request
  • Call CreateDistanceRequest on save

Copy link
Contributor

@tgolen tgolen left a comment

Choose a reason for hiding this comment

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

This draft looks like it's still in a pretty early stage so I don't want to comment on too much. I did notice this though and it might be something to consider.

src/pages/iou/DistanceRequestPage.js Outdated Show resolved Hide resolved
@hayata-suenaga
Copy link
Contributor Author

UPDATE:

I was able to grab transactions and display waypoint markers on the map. I gonna commit and push the code

Screenshot 2023-08-22 at 7 28 56 PM

@hayata-suenaga
Copy link
Contributor Author

I'm going to take dinner break now but I gonna work on the following when I come back:

  • Passing policyID down to the MoneyRequestConfirmationList
  • Subscribing to the policy with withOnyx
  • Getting the custom unit rate from the policy with a selector

@hayata-suenaga
Copy link
Contributor Author

Update:

Working on this part of the design doc where I need to extract the mileage rate from the policy associated with the report (where the money/distance request is create) and the distance itself from the transaction.

We need these values to calculate the expense amount to be displayed on the confirmation page.

@hayata-suenaga hayata-suenaga self-assigned this Aug 24, 2023
@hayata-suenaga
Copy link
Contributor Author

UPDATE:

  • was able to display the distance route
  • was able to calculate the distance amount ($0.05 in the following example)
  • was able to create a new item (Distance) in the list
Screenshot 2023-08-23 at 5 21 53 PM

@hayata-suenaga
Copy link
Contributor Author

hayata-suenaga commented Aug 24, 2023

TODO

  • Create DistanceRequestUtils.js and move all util functions there
  • Reread the section in design doc and check if all requirements are met
  • Make the PR read for review

@OSBotify
Copy link
Contributor

OSBotify commented Sep 1, 2023

🚀 Deployed to staging by https://github.com/neil-marcellini in version: 1.3.62-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@neil-marcellini
Copy link
Contributor

Ok I went through almost all the bugs reported here and report them in Slack and created GH issues for them. If I missed any I'm sure we'll see them reported again eventually.

@OSBotify
Copy link
Contributor

OSBotify commented Sep 4, 2023

🚀 Deployed to production by https://github.com/mountiny in version: 1.3.62-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

}

const amount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate);
IOU.setMoneyRequestAmount(amount);
Copy link
Contributor

@cubuspl42 cubuspl42 Sep 11, 2023

Choose a reason for hiding this comment

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

@hayata-suenaga

Coming from #26946.

I'm trying to figure out this props.iouAmount === 0 -> setMoneyRequestAmount -> props.iouAmount !== 0 cycle to review the proposals properly.

Would it be fine to drop the props.iouAmount === 0 condition and do something like:

// useMemo if we consider this heavy
const distanceAmmount = props.isDistanceRequest ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate) : undefined;

const formattedAmount = distanceAmmount !== undefined ?
    CurrencyUtils.convertToDisplayString(distanceAmmount, currency) :
    CurrencyUtils.convertToDisplayString(props.iouAmount, props.iouCurrencyCode);

useEffect(() => {
    if (distanceAmmount !== undefined) {
        IOU.setMoneyRequestAmount(distanceAmmount);
    }
}, [distanceAmmount]);

...or would it mess with the original intention/semantics of the props.iouAmount === 0 check, in the way I'm missing?

Copy link
Contributor

Choose a reason for hiding this comment

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

(Continuing here)

@hayata-suenaga
Copy link
Contributor Author

I'm trying to figure out this props.iouAmount === 0 -> setMoneyRequestAmount -> props.iouAmount !== 0 cycle to review the proposals properly.

@cubuspl42 could you link the code please 🙇

Comment on lines +172 to +188
const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0;
const shouldCategoryEditable = !_.isEmpty(props.policyCategories) && !props.isDistanceRequest;

const formattedAmount = CurrencyUtils.convertToDisplayString(
shouldCalculateDistanceAmount ? DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate) : props.iouAmount,
props.isDistanceRequest ? currency : props.iouCurrencyCode,
);

useEffect(() => {
if (!shouldCalculateDistanceAmount) {
return;
}

const amount = DistanceRequestUtils.getDistanceRequestAmount(distance, unit, rate);
IOU.setMoneyRequestAmount(amount);
}, [shouldCalculateDistanceAmount, distance, rate, unit]);

Copy link
Contributor

@cubuspl42 cubuspl42 Sep 12, 2023

Choose a reason for hiding this comment

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

@hayata-suenaga Well, I was speaking in the context of the mentioned line and its direct surroundings, but specifically, I'm talking about this range of lines, focusing on checking if props.iouAmount equals 0 and the dependencies of the useEffect hook.

This code cause the bug I mentioned earlier and we're trying to figure out whether we can just drop the props.iouAmount === 0 check without causing a regression.

One option how this area could look like after the change was included in my previous message. Let's continue the discussion in this thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh now I see what's you're talking about

we actually need that conditional statement

when the user manually edit the distance amount, we want to keep that amount instead of overwriting it with the calculated amount

but I know see why this is causing the issue

can we just clear out the amount from Transaction object when navigating back to the participants page?

Copy link
Contributor

@cubuspl42 cubuspl42 Sep 12, 2023

Choose a reason for hiding this comment

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

can we just clear out the amount from Transaction object when navigating back to the participants page?

I'm not completely sure, I'll come back to you

Copy link
Contributor

Choose a reason for hiding this comment

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

@hayata-suenaga

when the user manually edit the distance amount, we want to keep that amount instead of overwriting it with the calculated amount

Users can't edit the distance amount manually (we prevented user clicking on the amount field), they only can edit the waypoint

Copy link
Contributor

Choose a reason for hiding this comment

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

@DylanDylann Is it a temporary measure, or can we (at least for now) take this for granted?

Copy link
Contributor

Choose a reason for hiding this comment

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

@hayata-suenaga

Do we have a GH issue to re-add the ability to edit the amount manually?

We're in a tricky situation here. Currently, the simplest way to fix #26946 is just dropping the === 0 check, taking advantage from the fact that the amount cannot be (currently) edited by the user.

If we assume that that amount can be edited (because the feature might be re-added), we'd probably have to add some new persistent state to distinguish manually edited value from the auto-calculated one, but wouldn't be able to test it properly.

There are multiple solutions to this problem, but I would prefer to do it this way: for now, let's remove the === 0 condition, fixing #26946. Then, comment on the GH issue to re-add the manual edition feature to take care not to introduce regression for #26946 (creating new persistent state, if needed).

If there's no issue for re-adding manual distance IOU amount edition, we can create it.

This way, we're be focusing on problems we have right now, but at the same time do our best not to introduce regressions. This will also do fine in a hypothetical case we actually never re-allow manual edition (but such case wouldn't surprise me).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rather prefer if you could handle it in your issue @cubuspl42 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

@hayata-suenaga But how would you suggest to test that it achieves the goal, if it's currently not possible to manually edit the amount?

Maybe we could introduce a beta for editing the distance request amount, so this can be tested locally via manual one-line edition in Permissions.js, while the QA could be opted in to that beta on the backend?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not totally following everything discussed here, but I am chiming in to say that I am working on a PR #26141 to let people edit the distance request, and it will allow users to edit the amount as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cubuspl42 you can hold your issue on the above PR if necessary

@@ -59,6 +59,7 @@ const defaultProps = {

function MoneyRequestConfirmPage(props) {
const {windowHeight} = useWindowDimensions();
const isDistanceRequest = props.selectedTab === CONST.TAB.DISTANCE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding this condition caused #26661. We should have considered adding a check which verified the iouType here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is a refactor on the URLs related to money requests so that we can embed the info on the kind of money requests being made inside the URL so we don't have to this kind of awkward conditional checks

@@ -42,7 +42,7 @@ class WorkspaceRateAndUnitPage extends React.Component {
getUnitItems() {
return [
{label: this.props.translate('workspace.reimburse.kilometers'), value: CONST.CUSTOM_UNITS.DISTANCE_UNIT_KILOMETERS},
{label: this.props.translate('workspace.reimburse.miles'), value: CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES},
{label: this.props.translate('common.miles'), value: CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES},
Copy link
Contributor

Choose a reason for hiding this comment

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

This change has introduced a regression fixed in this PR: #27640 - these two units translations are inconsistent in terms of capitalization

Comment on lines +82 to +91
<MapView
accessToken={mapboxToken}
mapPadding={CONST.MAP_PADDING}
pitchEnabled={false}
directionCoordinates={coordinates}
directionStyle={styles.mapDirection}
style={styles.mapView}
waypoints={waypointMarkers}
styleURL={CONST.MAPBOX_STYLE_URL}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

We could pass initialState prop with start waypoint to avoid locating wrong location on first render.
Issue: #26726

@@ -58,7 +62,7 @@ function MoneyRequestParticipantsPage(props) {
// ID in Onyx could change by initiating a new request in a separate browser tab or completing a request
if (prevMoneyRequestId.current !== props.iou.id) {
// The ID is cleared on completing a request. In that case, we will do nothing
if (props.iou.id) {
if (!isDistanceRequest && props.iou.id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have navigated the user back if it was a distance request having empty waypoints. This caused #27383

@@ -1370,6 +1370,9 @@ const CONST = {
MAKE_REQUEST_WITH_SIDE_EFFECTS: 'makeRequestWithSideEffects',
},

MAP_PADDING: 50,
Copy link
Contributor

Choose a reason for hiding this comment

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

This MAP_PADDING value caused the following issue:

Because the value was too high, on certain narrow layout devices (mobile) the value caused the app to crash when submitting a distance request. The issue was fixed by decreasing the value to 32 and removing / unifying the MAP_PADDING into using MAPBOX.PADDING variable instead. More details can be found in the issue / proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.