Expensify / App

Welcome to New Expensify: a complete re-imagination of financial collaboration, centered around chat. Help us build the next generation of Expensify by sharing feedback and contributing to the code.
https://new.expensify.com
MIT License
2.99k stars 2.5k forks source link

fix: IOU Scan - In dark mode, the damaged PDF - file is barely visible. #40607

Open Krishna2323 opened 4 weeks ago

Krishna2323 commented 4 weeks ago

Details

Fixed Issues

$ https://github.com/Expensify/App/issues/39356 PROPOSAL: https://github.com/Expensify/App/issues/39356#issuecomment-2029731489

Tests

  1. Open FAB mentu > submit expense > scan
  2. Upload corrupt pdf attached below > Select any participant
  3. Verify there is a placeholder is shown with receipt slash component on confirmation page ? Submit expense
  4. Verify transactions preview also shows receipt slash component
  5. Click on transactions preview and verify receipt slash component is also displayed on transaction preview
  6. Open transaction details page and verify receipt slash component in place of receipt place holder

Offline tests

  1. Open FAB mentu > submit expense > scan
  2. Upload corrupt pdf attached below > Select any participant
  3. Verify there is a placeholder is shown with receipt slash component on confirmation page ? Submit expense
  4. Verify transactions preview also shows receipt slash component
  5. Click on transactions preview and verify receipt slash component is also displayed on transaction preview
  6. Open transaction details page and verify receipt slash component in place of receipt place holder

QA Steps

  1. Open FAB mentu > submit expense > scan
  2. Upload corrupt pdf attached below > Select any participant
  3. Verify there is a placeholder is shown with receipt slash component on confirmation page ? Submit expense
  4. Verify transactions preview also shows receipt slash component
  5. Click on transactions preview and verify receipt slash component is also displayed on transaction preview
  6. Open transaction details page and verify receipt slash component in place of receipt place holder

PR Author Checklist

Screenshots/Videos

Android: Native https://github.com/Expensify/App/assets/85894871/a00a0769-6e56-4a9e-8fac-c7d8abbfd110
Android: mWeb Chrome https://github.com/Expensify/App/assets/85894871/a4dd89e3-4ec8-445e-a134-6174efbc771e
iOS: Native https://github.com/Expensify/App/assets/85894871/6207d5c5-20a6-4983-b358-918caaae763a
iOS: mWeb Safari https://github.com/Expensify/App/assets/85894871/d6ecb4f8-67e9-4055-9b56-2db83adeaaea
MacOS: Chrome / Safari https://github.com/Expensify/App/assets/85894871/02c98eb5-a5c1-425d-a9a8-f52336f0ae4a
MacOS: Desktop https://github.com/Expensify/App/assets/85894871/320ace27-7210-4c8c-b4c0-a8f89a37d29e
melvin-bot[bot] commented 4 weeks ago

@jayeshmangwani 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]

Krishna2323 commented 4 weeks ago

@jayeshmangwani, when selecting a corrupt pdf file on native devices we don't get error and empty white background is shown. I'm looking for a solution for that.

jayeshmangwani commented 3 weeks ago

@Krishna2323 When you push the changes for native devices, please ping me.

Krishna2323 commented 3 weeks ago

@jayeshmangwani, I have updated the code for native devices, can you pls check and let me know, I haven't updated the recordings for native yet.

Demo for for native devices:

https://github.com/Expensify/App/assets/85894871/11a1d222-d8fb-47d3-82c8-e40e1af20b28

jayeshmangwani commented 3 weeks ago

@Expensify/design Please confirm the styling of the Failed to load PDF file. text?

Screenshot 2024-04-22 at 9 39 17 PM Screenshot 2024-04-22 at 9 39 32 PM
shawnborton commented 3 weeks ago

I would think instead of showing text like we are, we'd show our default fallback receipt view, something like this that @dannymcclain had suggested previously: image

Though I think I would change out the icon to use some kind of broken image icon, something like this but in our brand style: CleanShot 2024-04-22 at 12 35 56@2x

dannymcclain commented 3 weeks ago

@shawnborton I thought in a different issue we had settled on not allowing someone to upload a corrupted image/PDF? We show the standard modal that says "Error uploading attachment..." This was the mock for that:

image

Am I misremembering something?

shawnborton commented 3 weeks ago

You are definitely right. So yeah, that begs the question, how did we trigger this particular "Failed to load PDF" scenario?

jayeshmangwani commented 3 weeks ago

@shawnborton @dannymcclain To reproduce this issue, I am following this steps:

  1. Go to workspace chat > + > Split Expense > Scan > Upload a corrupt pdf

https://github.com/Expensify/App/assets/35371050/1ca7f71b-8b01-4981-9923-150f29d21817

Corrupt pdf [corrupted.pdf](https://github.com/Expensify/App/files/15067877/corrupted.pdf)
Krishna2323 commented 3 weeks ago

@dannymcclain @shawnborton, Yep, you're correct here. I worked on preventing corrupted images from being uploaded, but that was specifically for images. There might be another GitHub issue addressing prevention of corrupt PDFs from being uploaded. PR.

Krishna2323 commented 3 weeks ago

Here is the issue for preventing corrupted pdf's from being uploaded.

shawnborton commented 3 weeks ago

Yeah, I feel like a much better solution is to prevent a corrupted PDF from being uploaded in the first place.

jayeshmangwani commented 3 weeks ago

@hayata-suenaga @shawnborton If we are going to prevent a corrupted PDF from being uploaded, then we can close this PR and close/hold the issue in favor of https://github.com/Expensify/App/issues/34032

shawnborton commented 3 weeks ago

That's where my head is at... it seems like we won't ever be able to get to this scenario once we prevent corrupted images/files from being uploaded.

trjExpensify commented 3 weeks ago

it seems like we won't ever be able to get to this scenario once we prevent corrupted images/files from being uploaded.

I don't think we know the image/file is corrupt purely on the client, so isn't it possible you'll run into this when uploading a corrupt file offline?

shawnborton commented 2 weeks ago

Hmm good question, who can confirm that?

If that's the case, I like doing something like my suggestion here.

dannymcclain commented 2 weeks ago

If that's the case, I like doing something like my suggestion https://github.com/Expensify/App/pull/40607#issuecomment-2070156624.

Yeah I agree. @shawnborton do you think any of these icons would work for that? (Receipt Slash and Document Slash are already in the system—Image Slash is one that I just made based off of the Image icon and Receipt Slash icon.)

image

shawnborton commented 2 weeks ago

Yeah I think any of these would be great! I think I like doing something super generic in case this is a pattern we'd repeat not only for PDF-specific receipts but for all receipts in general that are corrupt. So that being said, I lean towards the first option?

dannymcclain commented 2 weeks ago

Yeah first option makes sense to me—that way we could use it for any file type of receipt that borked.

hayata-suenaga commented 2 weeks ago

I don't think we know the image/file is corrupt purely on the client, so isn't it possible you'll run into this when uploading a corrupt file offline?

I'm not familiar with how we're handling the PDF upload on the client side, but we try to display a preview of the PDF before the user attempts to send it. If the PDF is corrupted, we know that when we try to display the preview.

@Krishna2323, could you confirm that you seem to be working on the issue to prevent the corrupt PDF from being uploaded?

Screenshot 2024-04-30 at 9 31 25 AM

Regardless, I think it's a good idea to still implement the fallback view if the attachment is corrupted though.

Krishna2323 commented 2 weeks ago

@hayata-suenaga, I've worked on preventing corrupt images from being uploaded, and it seems to be functioning well across all platforms. As for the PDF issue, it's slated to be addressed in this issue. The proposal selected to resolve the problem doesn't appear to offer a straightforward solution for detecting corrupt PDFs across all platforms. Therefore, I agree with your suggestion to proceed with implementing the fallback view. Additionally, I've noticed that some PDFs preview correctly on the confirmation list but then display an error message stating that the PDF can't be loaded.

You can try with this pdf: Bug6460367_1713968986208.class-9-maths-chapter-10-solutions-2024-02-08_22_17_00.194.pdf

This works fine until we submit the request and go to details page but as soon as we refresh it shows Failed to load PDF file.

Krishna2323 commented 1 week ago

Ok, so I guess, we agree on showing fallback for corrupted files, will start implementing the changes today and update.

hayata-suenaga commented 1 week ago

Ok, so I guess, we agree on showing fallback for corrupted files, will start implementing the changes today and update.

Yes sorry if that wan't clear 🙇 thank you for pushing the PR forward 👍

Krishna2323 commented 1 week ago

@dannymcclain, I don't think we have Receipt Slash in the app, can you pls share it.

Monosnap ReportActionItemCreated tsx — App 2024-05-07 20-59-54 Monosnap index tsx — App 2024-05-07 19-25-18
dannymcclain commented 1 week ago

I don't think we have Receipt Slash in the app, can you pls share it.

@Krishna2323 No prob!

Receipt Slash.svg.zip

Krishna2323 commented 1 week ago

Code changes are done. @dannymcclain @shawnborton, can we confirm what width and height size we should use for the ReceiptSlash icon?

With 72px:

Monosnap (149) New Expensify 2024-05-08 17-55-00

Receipt doc size: Monosnap (149) New Expensify 2024-05-08 17-52-44

shawnborton commented 1 week ago

Hmm I could have sworn we already have a pattern in place for receipt placeholders, like these: CleanShot 2024-05-08 at 08 34 07@2x

Can we match that size? From Figma, it looks like they are at 80x80.

Krishna2323 commented 1 week ago

@shawnborton @dannymcclain @hayata-suenaga @jayeshmangwani, while recording videos for recent changes, I found that we can prevent users from uploading corrupt PDFs, and it works on all platforms. There will be a minor difference in corrupt image detection and corrupt PDF detection: for images, we show the alert modal immediately after the user selects it, and for PDFs, we will show it on the confirmation page, just like we show the alert for protected PDFs on the confirmation page. I don't think that's a very major inconsistency, so I have already updated the code for that. The fallback is also implemented in case a corrupt PDF passes the check, but that will be in very rare cases.

https://github.com/Expensify/App/assets/85894871/716891b9-0e5d-4649-a612-cdda525ce25e

https://github.com/Expensify/App/assets/85894871/1f3564cf-46a5-4888-a09b-7c8907d15ef1

https://github.com/Expensify/App/assets/85894871/c0a85e3b-96cd-438a-bbb0-591537b852ee

Krishna2323 commented 1 week ago

@jayeshmangwani, you can start the review.

shawnborton commented 1 week ago

Two questions:

Why can't we detect the corrupted PDF immediately, the same way we do for images?

How did you get a camera view like this where the capture button is off to the right? Looks like we're missing a flash icon? CleanShot 2024-05-09 at 07 46 04@2x

dannymcclain commented 1 week ago

Why can't we detect the corrupted PDF immediately, the same way we do for images?

Also curious about this. It feels pretty weird to drop the user back at the contact selector when they acknowledge the warning. They don't need to pick a new contact, they need to upload a different file. So that feels pretty strange to me.

Krishna2323 commented 1 week ago

@dannymcclain @shawnborton, we can push the user to file selector page instead of participants selector but we can't detect the pdf immediately. For images we use react-native-image-size package which works on all platforms but we don't have any package to detect corrupt pdf's. We first need to render it with different libraries for native and web and if the render fails we get the error. You can try uploading a protected pdf, you won't get any alert until you reach the confirmation page.

shawnborton commented 1 week ago

Hmm yeah, I'm a bit stumped so I would be curious for what our engineering team thinks.

I think the reality is, we haven't had a single customer ever report this corrupted PDF flow. This was a super edge case flow reported by our QA team. So I'm hesitant to spin the wheels too much here, given that I think this is not going to be any kind of mainline flow that we should optimize for.

If what you are proposing is the best we can do with our current limitations, I think it's probably our best bet.

hayata-suenaga commented 1 week ago

@dannymcclain @shawnborton, we can push the user to file selector page instead of participants selector but we can't detect the pdf immediately. For images we use react-native-image-size package which works on all platforms but we don't have any package to detect corrupt pdf's. We first need to render it with different libraries for native and web and if the render fails we get the error. You can try uploading a protected pdf, you won't get any alert until you reach the confirmation page.

My knowledge of PDF flow is also very limited. But one question. We still display the corrupt PDF on the front end before uploading the PDF to the backend, right? If the file is corrupted, why the front end can display the file?

Krishna2323 commented 1 week ago

@hayata-suenaga, the library attempts to display the provided pdf, but when it fails, it throws an error and shows 'Failed to load pdf file' instead of the pdf on the frontend. Corrupt pdf isn't displayed on the frontend in any case, only the error message is shown. What I did is captured that thrown error and displayed the alert modal.

Krishna2323 commented 6 days ago

@jayeshmangwani, bump for review.

hayata-suenaga commented 5 days ago

bumped them on Slack

jayeshmangwani commented 5 days ago

@Krishna2323 Remove HOLD from the PR title and resolve the conflicts In local I am getting conflicts with the latest main branch

jayeshmangwani commented 4 days ago

resolve the conflicts In local I am getting conflicts with the latest main branch

@Krishna2323 bump for this comment

Krishna2323 commented 4 days ago

resolve the conflicts

@jayeshmangwani, on it.

Krishna2323 commented 4 days ago

@jayeshmangwani, conflicts resolved.