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

[$250] Distance rate- WS owner can create multiple distance rate with same amount #51769

Open
2 of 8 tasks
lanitochka17 opened this issue Oct 30, 2024 · 28 comments
Open
2 of 8 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Oct 30, 2024

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.0.55-9
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Email or phone of affected tester (no customers): testpayment935+523@gmail.com
Issue reported by: Applause - Internal Team

Action Performed:

Preconditions
Navigate to http://www.staging.new.expensify.com/

  1. Create a new Workspace
  2. Navigate to workspace editor
  3. Navigate to "More features"
  4. Enable the distance rates toggle
    Steps
  5. Navigate to distance rates
  6. Click on "Add rate"
  7. Enter any rate that includes a decimal (e.g 2.2) and save
  8. Enter the same rate as step 3 and save

Expected Result:

Error shows as the rate is already exist

Actual Result:

WS owner can create multiple distance rate with same amount

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Bug6650641_1730320405551.Screen_Recording_20241030_223334.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021854599760824128596
  • Upwork Job ID: 1854599760824128596
  • Last Price Increase: 2024-11-07
  • Automatic offers:
    • DylanDylann | Reviewer | 105060475
    • Krishna2323 | Contributor | 105060479
Issue OwnerCurrent Issue Owner: @DylanDylann
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Oct 30, 2024
Copy link

melvin-bot bot commented Oct 30, 2024

Triggered auto assignment to @strepanier03 (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

@lanitochka17
Copy link
Author

@strepanier03 FYI I haven't added the External label as I wasn't 100% sure about this issue. Please take a look and add the label if you agree it's a bug and can be handled by external contributors

@Krishna2323
Copy link
Contributor

Krishna2323 commented Oct 30, 2024

Edited by proposal-police: This proposal was edited at 2024-10-30 21:07:32 UTC.

Proposal


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

Distance rate- WS owner can create multiple distance rate with same amount

What is the root cause of that problem?

  • In validateRateValue, we aren't checking for existing rate of the same amount.
    function validateRateValue(values: FormOnyxValues<RateValueForm>, currency: string, toLocaleDigit: (arg: string) => string): FormInputErrors<RateValueForm> {
    const errors: FormInputErrors<RateValueForm> = {};
    const parsedRate = MoneyRequestUtils.replaceAllDigits(values.rate, toLocaleDigit);
    const decimalSeparator = toLocaleDigit('.');
    // Allow one more decimal place for accuracy
    const rateValueRegex = RegExp(String.raw`^-?\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{0,${CONST.MAX_TAX_RATE_DECIMAL_PLACES}})?$`, 'i');
    if (!rateValueRegex.test(parsedRate) || parsedRate === '') {
    errors.rate = Localize.translateLocal('common.error.invalidRateError');
    } else if (NumberUtils.parseFloatAnyLocale(parsedRate) <= 0) {
    errors.rate = Localize.translateLocal('common.error.lowRateError');
    }
    return errors;
    }

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


  • In validateRateValue, we should start accepting customUnitRates.
  • Check for existing rate in customUnitRates of the same amount and return an error.
    const rateValueRegex = RegExp(String.raw`^-?\d{0,8}([${getPermittedDecimalSeparator(decimalSeparator)}]\d{0,${CONST.MAX_TAX_RATE_DECIMAL_PLACES}})?$`, 'i');
    const ratesList = Object.values(customUnitRates);
    if (ratesList.some((r) => r.rate === convertToBackendAmount(Number(parsedRate)))) {
        errors.rate = Localize.translateLocal('common.error.invalidRateError');
    } else if (!rateValueRegex.test(parsedRate) || parsedRate === '') {
        errors.rate = Localize.translateLocal('common.error.invalidRateError');
    } else if (NumberUtils.parseFloatAnyLocale(parsedRate) <= 0) {
        errors.rate = Localize.translateLocal('common.error.lowRateError');
    }
    return errors;
  • Pass customUnitRates to validateRateValue from CreateDistanceRatePage & PolicyDistanceRateEditPage.
    const customUnitRates: Record<string, Rate> = useMemo(() => customUnit?.rates ?? {}, [customUnit]);
    
    const validate = useCallback(
        (values: FormOnyxValues<typeof ONYXKEYS.FORMS.POLICY_CREATE_DISTANCE_RATE_FORM>) => {
            return validateRateValue(values, currency, toLocaleDigit, customUnitRates);
        },
        [currency, toLocaleDigit, customUnitRates],
    );
  • We should create new error translation for duplicate rate.

What alternative solutions did you explore? (Optional)

Result

@melvin-bot melvin-bot bot added the Overdue label Nov 4, 2024
Copy link

melvin-bot bot commented Nov 5, 2024

@strepanier03 Huh... This is 4 days overdue. Who can take care of this?

@strepanier03
Copy link
Contributor

We chatted about this internally, and we want to block duplicate rates since the rate is the name and it's not possible to differentiate. We also block categories and tags of the same name so we'd want this similar to that.

@melvin-bot melvin-bot bot removed the Overdue label Nov 7, 2024
@strepanier03 strepanier03 added the External Added to denote the issue can be worked on by a contributor label Nov 7, 2024
@melvin-bot melvin-bot bot changed the title Distance rate- WS owner can create multiple distance rate with same amount [$250] Distance rate- WS owner can create multiple distance rate with same amount Nov 7, 2024
Copy link

melvin-bot bot commented Nov 7, 2024

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 7, 2024
Copy link

melvin-bot bot commented Nov 7, 2024

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

@strepanier03
Copy link
Contributor

Working on determining the project now.

@strepanier03
Copy link
Contributor

We are unlikely to make any changes to this other than blocking the duplicate rate, but we will in the future most likely.

@strepanier03

This comment was marked as outdated.

@strepanier03 strepanier03 changed the title [$250] Distance rate- WS owner can create multiple distance rate with same amount [HOLD] [$250] Distance rate- WS owner can create multiple distance rate with same amount Nov 7, 2024
@strepanier03
Copy link
Contributor

Okay, we are good to move forward, here is the outcome.

  • we should not be allowing duplicate rates in the same workspace
  • separately (and less important IMO but still worth fixing) we should not show any rate names in the rate selection screen

Let's focus on not allowing duplicate rates within the same workspace in this GH and the other issue will be handled separately.

@DylanDylann
Copy link
Contributor

@Krishna2323's proposal looks good to me

🎀 👀 🎀 C+ Reviewed

Copy link

melvin-bot bot commented Nov 11, 2024

Triggered auto assignment to @bondydaa, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@DylanDylann
Copy link
Contributor

@bondydaa Friendly bump

@DylanDylann
Copy link
Contributor

@strepanier03 It seems @bondydaa is OOO

Screenshot 2024-11-14 at 11 54 57

@DylanDylann
Copy link
Contributor

@strepanier03 as mentioned here, @bondydaa is left and we need a new engineer to process this one. Could you help to unassign @bondydaa?

@bondydaa bondydaa removed their assignment Nov 18, 2024
@muttmuure muttmuure moved this to Bugs and Follow Up Issues in [#whatsnext] #expense Nov 19, 2024
@DylanDylann
Copy link
Contributor

DylanDylann commented Nov 20, 2024

@Krishna2323's proposal looks good to me

🎀 👀 🎀 C+ Reviewed

Copy link

melvin-bot bot commented Nov 20, 2024

Triggered auto assignment to @danieldoglas, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@DylanDylann
Copy link
Contributor

Bump @danieldoglas on above comment

Copy link

melvin-bot bot commented Nov 25, 2024

@danieldoglas, @strepanier03, @DylanDylann Whoops! This issue is 2 days overdue. Let's get this updated quick!

@melvin-bot melvin-bot bot added the Overdue label Nov 25, 2024
@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 25, 2024
Copy link

melvin-bot bot commented Nov 25, 2024

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

Offer link
Upwork job

@danieldoglas
Copy link
Contributor

Assigned

Copy link

melvin-bot bot commented Nov 25, 2024

📣 @Krishna2323 🎉 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 melvin-bot bot removed the Overdue label Nov 25, 2024
@danieldoglas danieldoglas changed the title [HOLD] [$250] Distance rate- WS owner can create multiple distance rate with same amount [$250] Distance rate- WS owner can create multiple distance rate with same amount Nov 25, 2024
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Nov 26, 2024
@Krishna2323
Copy link
Contributor

Krishna2323 commented Nov 26, 2024

@danieldoglas, one thing to confirm:

  • what should be the error message for duplicate rate?

    • I added A rate with value ${rate} already exists. for now because it matches the dupe category error message: A category with this name already exists.
  • Translations:

    • en: A rate with value ${rate} already exists.
    • es: Ya existe una tasa con el valor ${rate}.

@DylanDylann, PR is ready for review.

@DylanDylann
Copy link
Contributor

cc @Expensify/design for above comment

@dubielzyk-expensify
Copy link
Contributor

I like that. cc @jamesdeanexpensify for 👀 on the copy

@dannymcclain
Copy link
Contributor

Yup I like that too but will let James confirm!

@jamesdeanexpensify
Copy link
Contributor

I like that too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
Status: Bugs and Follow Up Issues
Development

No branches or pull requests

9 participants