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

Add ability to Take/Upload Receipts #23046

Merged
merged 104 commits into from
Aug 2, 2023
Merged

Add ability to Take/Upload Receipts #23046

merged 104 commits into from
Aug 2, 2023

Conversation

AndrewGable
Copy link
Contributor

@AndrewGable AndrewGable commented Jul 17, 2023

Details

We're bringing Expensify's receipt scan feature to NewDot! Below is the feature spec:

On the Big Number Pad (BNP) page of the Request money flow, a new Receipt option is added to the segmented control.

  • We will create a new component, TabSelector, that will be used to switch between the Cash and Receipt options (Distance too, down the line).
  • We will create another component, TabSelectorItem, for each of the options. It will take:
    • A Title for the item
    • An optional Icon
    • A callback function
  • We will create a new component MoneyRequestSelectorPage which will render amount, receipt, or distance components based on the selector. We will place the new TabSelector in MoneyRequestSelectorPage styled as shown in the mockups. On click, we will change a value in the state (requestType) to reflect the selection. Depending on requestType, we will display either the IOUAmountPage component, like we do now, or the new ReceiptSelector component we will create.
  • Selecting the receipt option will trigger two different behaviors, depending on whether the user is on a mobile platform or not. To do so, a new cross-platform component will be created: ReceiptSelector, which will have its index.js to handle desktop behavior, and index.native.js to handle mobile behavior.
  • The Request money segmented control defaults to Cash, though a member’s last choice is “sticky” globally across their account. This means that if a member switches to Receipt and submits a request, we’ll default to the camera next time they tap Request money anywhere they can create a request.
  • Selecting “Receipt” will automatically open the camera in-app so the user can take a picture of the receipt. In order to do so, we will be using the current go-to library for this, react-native-vision-camera (which also happens to be developed and maintained by one of our partners, Margelo!), which will allow us to simply add a <Camera> component inside index.native.js.
  • If the user has not given the app camera permissions, we’ll display a new, simple component, <DeniedCameraPermissions>, with a message indicating the user they need to allow permissions to use the camera (Expensify can't take photos without access to your camera.) and an Allow Access button that will trigger the permissions prompt.
  • On Web/Desktop, we show explanatory text on how to upload a receipt: “Drag a receipt onto this page, forward a receipt to receipts@expensify.com, or choose a file to upload below.” Choose file is also an option. We can add desktop webcam support later if we deem it important, though it’s out of scope.
  • Clicking Choose file will open the OS file picker as a centered modal, just like we already do for Add attachment in NewDot. We’ll open the File Selector like we do for attachments, allowing only the valid extensions and max size (24mb).
  • If a member drags a receipt to anywhere in the rightDocked side modal, the page is animated to provide visual feedback that they can now let go to initiate the file upload. We’ll, once again, mimic attachments behavior. As shown there, we’ll change the display based on the onDragEnter event, and we’ll also add an eventlistener for the drop action and, on drop, we will make sure the dropped file has a valid extension and size. Otherwise, we will show an error message.
  • In mWeb, an input of type “file” like this one will automatically prompt the user to choose the source of the file (Gallery, documents, camera).


251674071-0269b7ec-7ac5-41c4-836c-bc28c1f34784

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/295238

Tests

Web/mWeb/Desktop

Test 1
  1. Via global create menu click Request Money
  2. Verify your first time opening the right hand menu, the Manual tab is selected
  3. Click on the Scan tab
  4. Click on the Choose file button
  5. Upload a .png/.jpg image
  6. Verify you are taken to a user selector page
  7. Verify once you select a user, you see the receipt and the Request button
Test 2
  1. Via global create menu click Request Money
  2. Verify your second time opening the right hand menu, the previous tab was selected
  3. Click on the Scan tab
  4. Click on the Choose file button
  5. Upload a html, DOCX, or SVG file
  6. Verify you are taken to a user selector page
  7. Verify once you select a user, you see the receipt placeholder for the correct file type and the Request button
Test 3
  1. Via global create menu click Request Money
  2. Verify your second time opening the right hand menu, the previous tab was selected
  3. Click on the Scan tab
  4. Drag and drop a .png/.jpg image
  5. Verify the drag and drop functionality works for the whole right hand menu
  6. Verify you are taken to a user selector page
  7. Verify once you select a user, you see the receipt and the Request button
  8. Verify the same for DOCX, SVG and HTML files
Test 4, 5, 6
  1. Verify test 1, 2, 3 via the chat page except you will not see the selecting user page and it will default to the user who you are chatting with.

Android/iOS

Test 7
  1. Via global create menu click Request Money
  2. Verify your first time opening the right hand menu, the Manual tab is selected
  3. Click on the Scan tab
  4. Verify the first thing you see is the permissions page
  5. Take a photo
  6. Verify you are taken to a user selector page
  7. Verify once you select a user, you see the receipt and the Request button
Test 8
  1. Via global create menu click Request Money
  2. Verify your second time opening the right hand menu, the previous tab value is selected
  3. Click on the Scan tab
  4. Click on the the flash
  5. Take a photo and verify the flash is turned on
  6. Verify you are taken to a user selector page
  7. Verify once you select a user, you see the receipt and the Request button
Test 9
  1. Via global create menu click Request Money
  2. Verify your second time opening the right hand menu, the previous tab value is selected
  3. Click on the Scan tab
  4. Click on the the gallery icon on the left
  5. Select a photo from your gallery
  6. Verify you are taken to a user selector page
  7. Verify once you select a user, you see the receipt and the Request button
Test 10, 11, 12
  1. Repeat tests 7, 8, 9 via the chat page except you will not see the selecting user page and it will default to the user who you are chatting with.

Offline tests

All tests should work offline, however, we are going to be saving the images to disk in a future follow up PR.

QA Steps

Tests 1-12 above should be run by QA

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
      • 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
    • 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 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 Screenshot 2023-07-21 at 4 21 22 PM Screenshot 2023-07-21 at 4 21 22 PM
Screen.Recording.2023-07-21.at.2.28.37.PM.mov
Mobile Web - Chrome Screenshot 2023-07-21 at 4 53 33 PM Screenshot 2023-07-21 at 4 53 51 PM
Mobile Web - Safari

IMG_BFA7E9860A8D-1

IMG_EC25676F9352-1

Desktop Screenshot 2023-07-21 at 4 29 21 PM Screenshot 2023-07-21 at 4 29 18 PM
iOS

IMG_4517

IMG_4516

Android Screenshot 2023-07-21 at 4 50 19 PM Screenshot 2023-07-21 at 4 50 16 PM

@AndrewGable

This comment was marked as outdated.

@AndrewGable
Copy link
Contributor Author

I'll send a PR today for that change 👍

@OSBotify
Copy link
Contributor

OSBotify commented Aug 3, 2023

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.3.50-0 🚀

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

dragReceiptBeforeEmail: 'Drag a receipt onto this page, forward a receipt to ',
dragReceiptAfterEmail: ' or choose a file to upload below.',
chooseReceipt: 'Choose a receipt to upload or forward a receipt to ',
chooseFile: 'Choose File',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
chooseFile: 'Choose File',
chooseFile: 'Choose file',

This is already in checklist:

  • 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.

@OSBotify
Copy link
Contributor

OSBotify commented Aug 7, 2023

🚀 Deployed to production by https://github.com/puneetlath in version: 1.3.50-3 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Aug 7, 2023

🚀 Deployed to staging by https://github.com/luacmartins in version: 1.3.51-0 🚀

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

<TopTab.Screen
name={CONST.TAB.MANUAL}
component={MoneyRequestAmount}
initialParams={{reportID, iouType}}
Copy link
Member

Choose a reason for hiding this comment

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

Hi all, in this PR we broke the functionality where you set currency in the request param.

eg: /request/new?currency=CHF

#23636

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, it looks like this is resolved now?

@OSBotify
Copy link
Contributor

OSBotify commented Aug 9, 2023

🚀 Deployed to production by https://github.com/Julesssss in version: 1.3.51-2 🚀

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

@mananjadhav
Copy link
Collaborator

We added the ReceiptSelector component in this PR, but the permissions handling wasn't done properly for Android. This was now handled here.


const validateReceipt = (file) => {
const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(file, 'name', ''));
if (_.contains(CONST.API_ATTACHMENT_VALIDATIONS.UNALLOWED_EXTENSIONS, fileExtension.toLowerCase())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@AndrewGable Hi! While migrating this file to TS I noticed that CONST.API_ATTACHMENT_VALIDATIONS.UNALLOWED_EXTENSIONS is used here, but it's not defined in CONST.ts. Could you provide a list of unallowed extensions so I can add it to the migration PR?

const validateReceipt = (file) => {
const {fileExtension} = FileUtils.splitExtensionFromFileName(lodashGet(file, 'name', ''));
if (_.contains(CONST.API_ATTACHMENT_VALIDATIONS.UNALLOWED_EXTENSIONS, fileExtension.toLowerCase())) {
Receipt.setUploadReceiptError(true, Localize.translateLocal('attachmentPicker.wrongFileType'), Localize.translateLocal('attachmentPicker.notAllowedExtension'));
Copy link
Contributor

Choose a reason for hiding this comment

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

It could have been better to define only key here and translate in render level so that it updates dynamically when user language changes on another device.
Issue: #25865

@sobitneupane
Copy link
Contributor

This case was missed while adding the ability to drag and drop while uploading Receipt.

Issue: Desktop - Drag & drop container does not add opacity to entire height of the drawer

Steps to reproduce:

  • Go to the money request page in Desktop App.
  • Select Scan tab
  • Drag file to this tab
  • Notice the green opacity does not cover entire height of drawer

// except ID is now required, and it gets a `selectedTab` from Onyx
function OnyxTabNavigator({id, selectedTab, children, ...rest}) {
return (
<TopTab.Navigator
Copy link
Contributor

Choose a reason for hiding this comment

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

We have encountered a minor issue in #26994. Without explicitly setting the keyboardDismissMode, the navigator might interfere with the keyboard, resulting in unintended keyboard dismissal and input blurring particularly when switching tabs and interacting with input fields.

height={CONST.RECEIPT.ICON_SIZE}
/>
</View>
<Text style={[styles.textReceiptUpload]}>{translate('receipt.upload')}</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 #27551
This was causing the tabs to swipe when selecting the text, since the cursor was outside the text area and it was triggering tab navigation (swipe gesture)
We resolved this by using panHandlers on the parent View (onPanResponderTerminationRequest: false, don't allow something else (tab navigation in our case) to take over gestures) and extending text area to take full parent width

medium
success
text={translate('receipt.chooseFile')}
style={[styles.p9]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Basically, Button is based on PressableWithFeedback component, so we don't need to wrap it again here. It makes our custom style cause a bug here #26993


const camera = useRef(null);
const [flash, setFlash] = useState(false);
const [permissions, setPermissions] = useState('authorized');
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 #26499, we switch to react-native-permissions to check camera permissions.

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.