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

Show a growl and redirect when navigating to a chat we can't access #4018

Merged
merged 12 commits into from
Jul 19, 2021
Merged

Show a growl and redirect when navigating to a chat we can't access #4018

merged 12 commits into from
Jul 19, 2021

Conversation

rdjuric
Copy link
Contributor

@rdjuric rdjuric commented Jul 13, 2021

Details

Modifies our fetchChatReportsByIDs action to receive a boolean flag shouldRedirectIfInacessible. With this flag set to true, the action will redirect to Concierge and display a Growl if it was asked to fetch a single report and that report was inacessible.

We call a report inacessible if our API answers with a jsonCode of 404 when we try to fetch it.

In our ReportActionsView, check if the current report has a reportID saved locally. If it doesn't, try to fetch the report with the shouldRedirectIfInacessible flag set to true.

Fixed Issues

$ #3810

Tests

QA Steps

  1. Try to access a report you don't have access to - like /r/75205749
  2. A growl indicating an error should shows up
  3. You should be redirected to the Concierge chat

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

web.mov

Mobile Web

mWeb.mp4

Desktop

iOS

Android

@rdjuric rdjuric marked this pull request as ready for review July 14, 2021 18:18
@rdjuric rdjuric requested a review from a team as a code owner July 14, 2021 18:18
@MelvinBot MelvinBot requested review from marcaaron and removed request for a team July 14, 2021 18:18
@rdjuric
Copy link
Contributor Author

rdjuric commented Jul 14, 2021

Modified the original proposal to match your comment more closely @marcaaron.

I'm using navigateToConciergeChat instead of navigating to ROUTES.HOME as the inaccessible report would still show up after navigating to to /.

I think that happens because the report was still saved under CURRENTLY_VIEWED_REPORTID. Navigating to Concierge looked better and more foolproof than modifying our logic for saving the last viewed report.

@rdjuric
Copy link
Contributor Author

rdjuric commented Jul 14, 2021

Updated to use the new GetReportSummaryList

@marcaaron
Copy link
Contributor

@rdjuric Ok that sounds like a good solution to me, thanks!

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

Just a few comments. Nice work so far 🎉


// If we receive a 404 response while fetching a single report, treat that report as inacessible.
if (jsonCode === 404 && chatList.length === 1) {
throw new Error('inacessible');
Copy link
Contributor

@marcaaron marcaaron Jul 14, 2021

Choose a reason for hiding this comment

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

Can we perhaps create a constant for this and maybe give it a slightly more descriptive error something like this?

const CONST = {
    ...,
    ERROR: {
        INACCESSIBLE_REPORT: 'Report not found',
    },
};

Copy link
Contributor

Choose a reason for hiding this comment

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

Then we can use CONST.ERROR.INACCESSIBLE_REPORT in these two locations.

})
.catch((err) => {
if (err.message === 'inacessible' && shouldRedirectIfInacessible) {
Log.info('[Report] Report data is inacessible.', true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's maybe get rid of this log since it will actually print to the server and we don't need it to do that in this case.

@rdjuric
Copy link
Contributor Author

rdjuric commented Jul 15, 2021

Thanks for the feedback! Updated @marcaaron.

@rdjuric rdjuric requested a review from marcaaron July 15, 2021 00:35
@rdjuric
Copy link
Contributor Author

rdjuric commented Jul 19, 2021

Can we merge this one @marcaaron?

Log.info('[Report] successfully fetched report data', true);
fetchedReports = reportSummaryList;

// If we receive a 404 response while fetching a single report, treat that report as inacessible.
if (jsonCode === 404 && chatList.length === 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. not sure checking the chatList is necessary on second thought
  2. we should be checking shouldRedirectIfInacessible when we throw this error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. If we're controlling the redirect via the shouldRedirectIfInacessible param, checking the chatList is a weird restriction.

*
* Fetches chat reports when provided a list of chat report IDs.
* If the shouldRedirectIfInacessible flag is set, we redirect to the Concierge chat
* when fetching a single chat that is inacessible.
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
* when fetching a single chat that is inacessible.
* when we find an inaccessible chat.

@@ -368,6 +375,13 @@ function fetchChatReportsByIDs(chatList) {
PersonalDetails.getFromReportParticipants(Object.values(simplifiedReports));

return _.map(fetchedReports, report => report.reportID);
})
.catch((err) => {
if (err.message === CONST.REPORT.ERROR.INACCESSIBLE_REPORT && shouldRedirectIfInacessible) {
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
if (err.message === CONST.REPORT.ERROR.INACCESSIBLE_REPORT && shouldRedirectIfInacessible) {
if (err.message === CONST.REPORT.ERROR.INACCESSIBLE_REPORT) {

Log.info('[Report] successfully fetched report data', true);
fetchedReports = reportSummaryList;

// If we receive a 404 response while fetching a single report, treat that report as inacessible.
if (jsonCode === 404 && chatList.length === 1) {
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
if (jsonCode === 404 && chatList.length === 1) {
if (jsonCode === 404 && shouldRedirectIfInacessible) {

@@ -107,6 +108,9 @@ class ReportActionsView extends React.Component {

componentDidMount() {
AppState.addEventListener('change', this.onVisibilityChange);
if (!this.props.report.reportID) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like there's a special significance to this not existing. Can we add a comment above to maybe explain why this does not exist and why it's being called with this parameter? Maybe something like

If the reportID is not found then we have either not loaded this chat or the user is unable to access it. We will attempt to fetch it and redirect if still not accessible.

@rdjuric rdjuric requested a review from marcaaron July 19, 2021 21:13
@rdjuric
Copy link
Contributor Author

rdjuric commented Jul 19, 2021

Updates made @marcaaron

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

LGTM

@marcaaron
Copy link
Contributor

Nice ! Thanks @rdjuric

@marcaaron marcaaron merged commit 4749488 into Expensify:main Jul 19, 2021
@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.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging in version: 1.0.79-5🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production in version: 1.0.80-2🚀

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

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.

3 participants