App icon indicating copy to clipboard operation
App copied to clipboard

[$500] [HOLD 36985] [P2P Distance] Create UpdateMoneyRequestRate in App

Open neil-marcellini opened this issue 1 year ago • 17 comments

Create UpdateMoneyRequestRate following this plan. Please be sure to read and understand the relevant sections of the entire plan as well.

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01fde353d38f5fdf1b
  • Upwork Job ID: 1760136022052638720
  • Last Price Increase: 2024-02-21
  • Automatic offers:
    • paultsimura | Contributor | 0

neil-marcellini avatar Feb 21 '24 02:02 neil-marcellini

Job added to Upwork: https://www.upwork.com/jobs/~01fde353d38f5fdf1b

melvin-bot[bot] avatar Feb 21 '24 02:02 melvin-bot[bot]

Triggered auto assignment to Contributor-plus team member for initial proposal review - @mananjadhav (External)

melvin-bot[bot] avatar Feb 21 '24 02:02 melvin-bot[bot]

Triggered auto assignment to @stephanieelliott (NewFeature), see https://stackoverflowteams.com/c/expensify/questions/14418#:~:text=BugZero%20process%20steps%20for%20feature%20requests for more details.

melvin-bot[bot] avatar Feb 21 '24 02:02 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

Once the Distance and Rate are added as separate fields of a Distance request (not stored in a merchant as currently), we want to introduce the possibility to edit the rate once the request is created.

What is the root cause of that problem?

This is a new feature request

What changes do you think we should make in order to solve the problem?

This should be done after the Rate field is added to the Money Requests.

First, we should add the EditRequestRatePage similar to other pages that modify IOU fields (IOURequestStepDescription/IOURequestStepTag) using the WorkspaceRatePage as a UI example.

We need to add the function that will call the BE UpdateMoneyRequestRate API when the page form is submitted. It should use the corresponding parameters that the Endpoint requires, as well as build optimistic data.

What alternative solutions did you explore? (Optional)

paultsimura avatar Feb 21 '24 09:02 paultsimura

Commenting to help with the review.

koko57 avatar Feb 22 '24 12:02 koko57

@paultsimura's proposal looks good. Sounds like we will hold on #36985, so updating the title for that.

neil-marcellini avatar Feb 22 '24 16:02 neil-marcellini

📣 @paultsimura 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻 Keep in mind: Code of Conduct | Contributing 📖

melvin-bot[bot] avatar Feb 22 '24 16:02 melvin-bot[bot]

Still on HOLD

neil-marcellini avatar Mar 04 '24 20:03 neil-marcellini

Still held on https://github.com/Expensify/App/issues/36985,

stephanieelliott avatar Mar 12 '24 23:03 stephanieelliott

Still held, but there has been recent progress on https://github.com/Expensify/App/issues/36985,

stephanieelliott avatar Mar 19 '24 01:03 stephanieelliott

Still held on https://github.com/Expensify/App/issues/36985, EOW ETA for PR

stephanieelliott avatar Mar 28 '24 22:03 stephanieelliott

Still held, blocking PR us under active review

stephanieelliott avatar Apr 04 '24 23:04 stephanieelliott

Hey @paultsimura what do you think about getting started on this soon, branching off of the PR that's currently in progress [App] Feat/36985 create new rate field?

neil-marcellini avatar Apr 08 '24 18:04 neil-marcellini

Thanks for the tag @neil-marcellini, I'll start tomorrow 🫡

paultsimura avatar Apr 08 '24 20:04 paultsimura

@neil-marcellini just to confirm:

  1. Since for P2P distance requests we are using the default const rate values, the "edit rate" functionality should be enabled only for workspace distance requests?
  2. Is it OK to use the field name simply rate (e.g. in the editing route: /edit/request/rate/{id} and in const: EDIT_REQUEST_FIELD.RATE), or should we lean to specifying that it's a mileageRate?
  3. What should the MODIFIEDEXPENSE say in case of the modified rate (considering a rate can have a custom name & the rate itself)?

paultsimura avatar Apr 10 '24 10:04 paultsimura

  1. Since for P2P distance requests we are using the default const rate values, the "edit rate" functionality should be enabled only for workspace distance requests?

Yes

2. Is it OK to use the field name simply rate (e.g. in the editing route: /edit/request/rate/{id} and in const: EDIT_REQUEST_FIELD.RATE), or should we lean to specifying that it's a mileageRate?

I prefer mileageRate or distanceRate because we have other rates, such as tax.

3. What should the MODIFIEDEXPENSE say in case of the modified rate (considering a rate can have a custom name & the rate itself)?

To make this easy for me to answer, here is the backend logic in PHP. I'm sure it's ok to share since we should probably implement the same thing in App for the optimistic data.

Backed logic for distance modified expense message
    private function getNewDotCommentForDistanceRequest(string $newMerchant, string $oldMerchant, string $newAmount, string $oldAmount): string
    {
        // The format of the merchant in a distance request from NewDot comes in the format:
        // <quantity> <unit> @ <formatted rate with currency> / <unit>
        // Example: 1 mile @ $5 / mi
        // For more examples, see ModifiedExpenseTest.php's testGetNewDotComment
        $distanceMerchantRegex = '/^[0-9.]+ \w+ @ (-|-\()?(\p{Sc}|\w){1,3} ?[0-9.]+\)? \/ \w+$/';
        $changedField = 'distance';

        // If the new & old merchants match the new distance request format, check if the distance or rate changed.
        // Otherwise, just display that the distance changed.
        if (preg_match($distanceMerchantRegex, $newMerchant) && preg_match($distanceMerchantRegex, $oldMerchant)) {
            // Extract distance and rate from merchant. These values are separated by ' @ '.
            $oldValues = explode('@', $oldMerchant);
            $oldDistance = trim($oldValues[0] ?? '');
            $oldRate = trim($oldValues[1] ?? '');
            $newValues = explode('@', $newMerchant);
            $newDistance = trim($newValues[0] ?? '');
            $newRate = trim($newValues[1] ?? '');

            // Determine if this action is for a rate modification.
            if ($oldDistance === $newDistance && $oldRate !== $newRate) {
                $changedField = 'rate';
            }
        } else {
            Log::hmmm("Distance request merchant doesn't match NewDot format. Defaulting to showing as distance changed.", ['newMerchant' => $newMerchant, 'oldMerchant' => $oldMerchant]);
        }
        if (!strlen($oldMerchant)) {
            return "set the $changedField to $newMerchant, which set the amount to $newAmount";
        }
        return "changed the $changedField to $newMerchant (previously $oldMerchant), which updated the amount to $newAmount (previously $oldAmount)";
    }

neil-marcellini avatar Apr 12 '24 15:04 neil-marcellini

@neil-marcellini maybe it makes sense then to rename the API operation to UpdateMoneyRequestDistanceRate instead of just UpdateMoneyRequestRate?

paultsimura avatar Apr 13 '24 12:04 paultsimura

PR is under review

stephanieelliott avatar Apr 18 '24 13:04 stephanieelliott

@paultsimura the new rate field PR has been merged. Agata is working on some follow ups, but that should be done soon [CP Staging] Feat/36985 create new rate field followups. What's your ETA to raise the PR for this? Would you please link it here as soon as it's ready? I usually like to review before the C+ approves.

neil-marcellini avatar Apr 22 '24 23:04 neil-marcellini

Triggered auto assignment to @miljakljajic (NewFeature), see https://stackoverflowteams.com/c/expensify/questions/14418#:~:text=BugZero%20process%20steps%20for%20feature%20requests for more details. Please add this Feature request to a GH project, as outlined in the SO.

melvin-bot[bot] avatar Apr 23 '24 03:04 melvin-bot[bot]

Reapplying the New Feature label to get another BZ member on this while I am OOO til May 2. Thanks @miljakljajic -- to catch you up on where we are, we are waiting for @paultsimura to raise a PR. I'll grab this back from you when I return!

stephanieelliott avatar Apr 23 '24 03:04 stephanieelliott

@neil-marcellini from what I see, the BE part is not ready yet. What is the plan with it? I don't think putting a PR out for review before the endpoint is ready is a good idea as it'll definitely lead to discrepancies in optimistic data and cause follow-ups.

paultsimura avatar Apr 23 '24 05:04 paultsimura

Ok yeah good point. I forgot how slowly that's coming along on the backend 😅. I'll let you know when it's ready, and I'll put it on HOLD for now.

neil-marcellini avatar Apr 23 '24 15:04 neil-marcellini

Thank you. Just an FYI, I'll be OOO April 26 - May 13, so if the BE part gets resolved in that timeframe and the PR becomes urgent – feel free to reassign.

paultsimura avatar Apr 23 '24 18:04 paultsimura

On hold still

neil-marcellini avatar May 01 '24 19:05 neil-marcellini

I'm back from OOO, thanks for watching this while I was out @miljakljajic!

stephanieelliott avatar May 02 '24 16:05 stephanieelliott

Still held on #36969

stephanieelliott avatar May 09 '24 17:05 stephanieelliott

Still held on https://github.com/Expensify/App/issues/36969, the PR blocking that one is actively being worked on.

stephanieelliott avatar May 17 '24 19:05 stephanieelliott

Yep, not overdue

neil-marcellini avatar May 21 '24 19:05 neil-marcellini

Still holding on https://github.com/Expensify/App/issues/36969

stephanieelliott avatar May 29 '24 07:05 stephanieelliott