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

Allow receipt recovery if the upload fails #29790

Merged
merged 41 commits into from
Nov 22, 2023
Merged

Allow receipt recovery if the upload fails #29790

merged 41 commits into from
Nov 22, 2023

Conversation

Gonals
Copy link
Contributor

@Gonals Gonals commented Oct 17, 2023

Details

Fixed Issues

$ #28884
PROPOSAL:

Tests

  1. Open a chat in NewDot and click + -> Request Money -> Scan and upload a file that will fail in the backend. A CSV should do the trick.
  2. Open the Money Request report chat. After a second or two, the request should fail and you should see this message:
Screenshot 2023-10-17 at 5 22 42 PM
  1. Click on it and confirm you can download the file (Note that. refreshing or closing the app will make the file unavailable)
  • Verify that no errors appear in the JS console

Offline tests

No changes

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • 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
      • 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

Android: Native Screenshot 2023-10-18 at 4 44 54 PM
Android: mWeb Chrome Screenshot 2023-10-18 at 4 42 20 PM
iOS: Native
iOS: mWeb Safari Screenshot 2023-10-18 at 4 34 07 PM
MacOS: Chrome / Safari Screenshot 2023-10-17 at 5 22 52 PM
MacOS: Desktop Screenshot 2023-10-18 at 1 48 16 PM

@Gonals Gonals self-assigned this Oct 17, 2023
@Gonals Gonals requested a review from a team as a code owner October 17, 2023 16:01
@Gonals Gonals changed the title Allow receipt recovery if the upload fails [WIP] Allow receipt recovery if the upload fails Oct 17, 2023
@melvin-bot melvin-bot bot requested review from marcochavezf and removed request for a team October 17, 2023 16:01
@melvin-bot
Copy link

melvin-bot bot commented Oct 17, 2023

@marcochavezf Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 17, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0d010f9
Status: ✅  Deploy successful!
Preview URL: https://50255374.helpdot.pages.dev
Branch Preview URL: https://alberto-recoverreceipt.helpdot.pages.dev

View logs

@Gonals Gonals changed the title [WIP] Allow receipt recovery if the upload fails Allow receipt recovery if the upload fails Oct 18, 2023
@Gonals Gonals requested a review from 0xmiros October 18, 2023 14:32
@Gonals
Copy link
Contributor Author

Gonals commented Oct 18, 2023

I'm having some trouble uploading receipts on mobile, but this is ready for testing!

@Gonals
Copy link
Contributor Author

Gonals commented Oct 18, 2023

I'm having some trouble uploading receipts on mobile, but this is ready for testing!

Ok, just iOS native left, as my pods are missing the permissions module for reasons unknown 🤷

In any case, feel free to go ahead and test. This seems to work well across platforms!

@trjExpensify
Copy link
Contributor

Ah, @Gonals.. I just realised that there's a small design addition when dismissing the error that we landed on with replace receipt flow where we're also wanting to do similar to not lose the receipt. It's the "are you sure?" modal confirmation on dismissing the error to be extra sure, illustrated here.

@tienifr is working on a PR for that issue in the replace receipt flow to not lose the receipt there on replacing it. Not sure if he needs to wait until this is merged to re-use parts of it, and then maybe aslo include adding that additional modal in this flow as well actually?

CC: @hoangzinh

@Gonals
Copy link
Contributor Author

Gonals commented Oct 19, 2023

Ah, @Gonals.. I just realised that there's a small design addition when dismissing the error that we landed on with replace receipt flow where we're also wanting to do similar to not lose the receipt. It's the "are you sure?" modal confirmation on dismissing the error to be extra sure, illustrated here.

@tienifr is working on a PR for that issue in the replace receipt flow to not lose the receipt there on replacing it. Not sure if he needs to wait until this is merged to re-use parts of it, and then maybe aslo include adding that additional modal in this flow as well actually?

CC: @hoangzinh

The don't need to wait on this. This flow is error-based, while theirs is simply adding the link in the modal, so they don't really intersect.

Similarly, we can't really add the modal here. I guess we could add it before dismissing the error, but I think that would be overkill and not really very useful, given than closing the app or refreshing the page will make them lose the receipt anyways (nothing we can do about that. It is stored in the temporary memory)

* @param {Object} transaction
* @returns {Object}
*/
function getReceiptError(transaction) {
Copy link
Contributor

@nkuoch nkuoch Nov 21, 2023

Choose a reason for hiding this comment

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

The idea is to also use the same method for the 2 last blocks (line 1436 and 1461)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I'm having issues testing today (onyx is doing weird stuff). I'll try again tomorrow!

@@ -585,6 +585,9 @@ export default {
invalidSplit: 'La suma de las partes no equivale al monto total',
other: 'Error inesperado, por favor inténtalo más tarde',
genericCreateFailureMessage: 'Error inesperado solicitando dinero, Por favor, inténtalo más tarde',
receiptFailureMessage: 'El recibo no se subió. ',
saveFileMessage: 'Guarda el archivo ',
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update this word "Guarda" to "Download" as well for consistency.
cc: @marcochavezf for Spanish help

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'm from Spain! I decided to leave both as they are on purpose 😁

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok!

@@ -583,6 +583,9 @@ export default {
invalidSplit: 'La suma de las partes no equivale al monto total',
other: 'Error inesperado, por favor inténtalo más tarde',
genericCreateFailureMessage: 'Error inesperado solicitando dinero, Por favor, inténtalo más tarde',
receiptFailureMessage: 'El recibo no se subió. ',
saveFileMessage: 'Guarda el archivo ',
loseFileMessage: 'o descarta este error y piérdelo',
Copy link
Contributor

Choose a reason for hiding this comment

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

While updating above, please also apply this suggestion 🙂

@melvin-bot melvin-bot bot requested a review from thienlnam November 22, 2023 12:16
Copy link

melvin-bot bot commented Nov 22, 2023

@thienlnam Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@Gonals Gonals removed the request for review from thienlnam November 22, 2023 12:16
@nkuoch nkuoch merged commit 296fc65 into main Nov 22, 2023
21 checks passed
@nkuoch nkuoch deleted the alberto-recoverReceipt branch November 22, 2023 12:23
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

))}
{_.map(sortedMessages, (message, i) =>
isReceiptError(message) ? (
<PressableWithoutFeedback
Copy link
Contributor

@blazejkustra blazejkustra Nov 23, 2023

Choose a reason for hiding this comment

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

@Gonals I'm working on DotIndicatorMessage TS migration PR and while resolving conflicts I noticed this logic change:

isReceiptError(message) ? (
                        <PressableWithoutFeedback
...

👇 With these lines sortedMessages is an array of strings, so I don't see how isReceiptError will ever return true for the code above, therefore the whole logic with PressableWithoutFeedback is unnecessary in my opinion 🤔

    const sortedMessages = _.chain(props.messages)
        .keys()
        .sortBy()
        .map((key) => props.messages[key])
        // Using uniq here since some fields are wrapped by the same OfflineWithFeedback component (e.g. WorkspaceReimburseView)
        // and can potentially pass the same error.
        .uniq()
        .map((message) => Localize.translateIfPhraseKey(message))
        .value();

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried to follow the steps from the description but I get a different error:
image

Copy link
Contributor

@blazejkustra blazejkustra Nov 23, 2023

Choose a reason for hiding this comment

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

Ah actually it works but it is kind of hacky 😅

ReceiptError object is passed to this function as a 'message', the error is thrown inside try block but it is caught in the catch block and the whole object is returned instead of a string as function signature suggests. I think it would makes things more readable if we were to change the logic here/or use a different component for Receipt errors. cc @Gonals @nkuoch @0xmiroslav

/**
 * Return translated string for given error.
 */
function translateIfPhraseKey(message: string | [string, Record<string, unknown> & {isTranslated?: true}] | []): string {
    if (!message || (Array.isArray(message) && message.length === 0)) {
        return '';
    }

    try {
        // check if error message has a variable parameter
        const [phrase, variables] = Array.isArray(message) ? message : [message];

        // This condition checks if the error is already translated. For example, if there are multiple errors per input, we handle translation in ErrorUtils.addErrorMessage due to the inability to concatenate error keys.
        if (variables?.isTranslated) {
            return phrase;
        }

        return translateLocal(phrase as TranslationPaths, variables as never);
    } catch (error) {
        return Array.isArray(message) ? message[0] : message;
    }
}

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/nkuoch in version: 1.4.3-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/nkuoch in version: 1.4.3-0 🚀

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

@0xmiros
Copy link
Contributor

0xmiros commented Nov 23, 2023

I am not sure how QA team will test this as we prevent csv files uploading in advance.
@Gonals can you please update QA Step accordingly?
As these are supported formats:
'jpg', 'jpeg', 'gif', 'png', 'pdf', 'htm', 'html', 'text', 'rtf', 'doc', 'tif', 'tiff', 'msword', 'zip', 'xml', 'message'

@kavimuru
Copy link

@Gonals We are blocked as per @0xmiroslav comment. How should we proceed with this PR?

bandicam.2023-11-24.01-36-22-748.mp4

Comment on lines +101 to +108
<Text
key={i}
style={styles.offlineFeedback.text}
>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{Localize.translateLocal('iou.error.receiptFailureMessage')}</Text>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}>{Localize.translateLocal('iou.error.saveFileMessage')}</Text>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{Localize.translateLocal('iou.error.loseFileMessage')}</Text>
</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

@Gonals The error text next to red dot indicators is meant to be red to be consistent with other error messages in the app.

With your current change here, the error text will revert back to light-greyish green.

expensify-new-error-text-bug-introduced

I just worked on an issue fixing this and just luckily stumbled on the regression from the video of another issue I was looking at.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 1.4.3-11 🚀

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

style={styles.offlineFeedback.text}
>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting]}>{Localize.translateLocal('iou.error.receiptFailureMessage')}</Text>
<Text style={[styles.optionAlternateText, styles.textLabelSupporting, styles.link]}>{Localize.translateLocal('iou.error.saveFileMessage')}</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from this issue #39330, we should use either Pressable component or TextLink here, instead of wrapping the whole text inside a Pressable.

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

Successfully merging this pull request may close these issues.