Skip to content

[Hold for payment 2021-08-17] Handle redirects to Invalid PolicyIds in WorkspaceCard and WorkspacePeople screens #4350

Closed

Description

@mananjadhav

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


Action Performed:

  1. Go to URL, enter the workspace URL without any policyID
  2. It updates the URL as workspace/undefined/card
  3. Blank page with the card is shown
  4. Same gets reproduced by putting any random workspace policyId in the URL workspace/<randomId>/card, workspace/<randomId>/people

Expected Result:

  1. Should've redirected to the Home page
  2. Or should've opened the Settings Page with a Not Found design
redirect-to-home.mp4

Actual Result:

Empty Sidebar + List with WorkspacePeople Page
https://user-images.githubusercontent.com/3069065/127743007-cb235857-daaa-402f-bc1a-28f76e36b7fc.mp4

Empty Sidebar with WorkspaceCard Page
https://user-images.githubusercontent.com/3069065/127743012-c6cc58ae-50cf-4b0e-bfa1-ebaad0f9a5d3.mp4

Workaround:

Yes. No blocker impact.

Platform:

Where is this issue occurring?

  • Web
  • Mobile Web

Version Number:
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
Expensify/Expensify Issue URL:

View all open jobs on Upwork

Activity

  1. added
    AutoAssignerTriage
    Daily
    on Jul 31, 2021
  2. MelvinBot commented on Jul 31, 2021

    @MelvinBot
    Contributor

    Triggered auto assignment to @bfitzexpensify (AutoAssignerTriage), see https://stackoverflow.com/c/expensify/questions/4749 for more details.

  3. removed
    AutoAssignerTriage
    on Jul 31, 2021
  4. mananjadhav commented on Jul 31, 2021

    @mananjadhav
    CollaboratorAuthor

    Proposal

    There are two approaches that we have:

    1. Redirect to the Home Chat screen
    2. Create a default error page for Workspace and load the Settings menu to let the user choose workspace from

    Currently, WorkspaceCardPage doesn't take policy as one of the props. WorkspacePeoplePage already has policy page.

    Common Code in both approaches

    WorkspaceCardPage

    Add props:
    
    const propTypes = {
        ..., // existing values
        policy: PropTypes.shape({
            /** The policy name */
            name: PropTypes.string,
        }),
    }
    
    const defaultProps = {
        ..., // existing values
        policy: {
          name: '',
        }
    };
    
    function isValidPolicy(policy) {  // will be added to WorkspacePeoplePage or moved to some common utils.
      if(!policy || !policy.name || !policy.name.length) {
        return false;
      }
      return true;
    }
    
    
    

    Approach 1

    const WorkspaceCardPage = ({ // and the same block for WorkspacePeoplePage
        betas,
        user,
        translate,
        isSmallScreenWidth,
        reimbursementAccount,
        policy
    }) => {
    
      useEffect(() => {
        if(!isValidPolicy(policy)) {
          Navigation.navigate(ROUTES.REPORT);
          return;
        }
      }, []);
    
      .... //Rest of the block
    

    Approach 2

    Create a new page WorkspaceNotFound page.// Will need help with the design

    const WorkspaceNotFound = ({translations: {translate}}) => {
    
        useEffect(() => {
           if(!isValidPolicy(policy)) {   
              Navigation.navigate(ROUTES.SETTINGS);
              return;
           }
         }, []);
    
         return (
            <View>
               // Design comes here.
            </View>
         )
    }
    
  5. aman-atg commented on Jul 31, 2021

    @aman-atg
    Contributor

    Proposal

    Explaination

    • The problem lies with the WorkspaceSidebar component which is returning null when the policy object is empty
    • We can simply use Navigation.dismissModal(); to avoid this behaviour or redirect the user somewhere we want.
      if (_.isEmpty(policy)) {
      return null;
      }

      will be changed to
    useEffect(()=>{
        if (_.isEmpty(policy)) {
            Navigation.dismissModal();
            return null;
        }
    },[policy])

    @mananjadhav I think your approach is checking for something that's already being checked inside WorkspaceSidebar. Don't you think? I think the root cause of the problem is Sidebar's returning null.

  6. mananjadhav commented on Jul 31, 2021

    @mananjadhav
    CollaboratorAuthor

    @aman-atg That's right. I missed the check-in WorkspaceSidebar. A small change in your approach. Otherwise, it will throw an exception.

    useEffect(() => {
          if (_.isEmpty(policy)) {
          Navigation.dismissModal();
          return null;
        }
    
        }, []);
    
  7. aman-atg commented on Jul 31, 2021

    @aman-atg
    Contributor

    @mananjadhav Shouldn't we include policy inside the dependency array?

    Otherwise, it will throw an exception.

    It was already setup like this but can you please elaborate on this.

  8. mananjadhav commented on Jul 31, 2021

    @mananjadhav
    CollaboratorAuthor

    I am not aware if policy will get changed anywhere. If it does, then yeah we'll have to add it as a dependency. Empty brackets [], will act as a componentDidMount for class components.

    It was already set up like this but can you please elaborate on this.

    Earlier it was just returning null. Now we're calling Navigation.dismissModal. In the console tab of devtools you'll find the following error/warning.

    Warning: Cannot update a component (`ForwardRef(BaseNavigationContainer)`) while rendering a different component (`WorkspaceSidebar`). To locate the bad setState() call inside `WorkspaceSidebar`, follow the stack trace as describ
    
  9. aman-atg commented on Jul 31, 2021

    @aman-atg
    Contributor

    @mananjadhav Thanks for the clarification.

  10. removed their assignment
    on Aug 2, 2021
  11. 23 remaining items

  12. adelekennedy commented on Aug 6, 2021

    @adelekennedy
    Contributor

    re-assigning @arielgreen while I'm ooo next week

  13. timszot commented on Aug 6, 2021

    @timszot

    Allow user to create a new Workspace with either the same page or WorkspaceNotFound page

    @mananjadhav I think it makes sense to direct them to create a new Workspace in the case where no Workspace is setup yet. I don't think we need a new WorkspaceNotFound page, but can you explain in more details how you would accomplish this without a new WorkspaceNotFound page?

  14. mananjadhav commented on Aug 6, 2021

    @mananjadhav
    CollaboratorAuthor

    @timszot Quickest approach is,

    1. Show an error message (growl) that Worskspace doesn't exist
    2. Redirect to /workspace/new
     useEffect(() => {
        if(!isValidPolicy(policy)) {
          Navigation.navigate(ROUTES.WORKSPACE_NEW);
          return;
        }
      }, []);
    

    This the page it'll load
    image

    The second way to do this is to open the new workspace form in the WorkspaceCard itself. But this is a little extra effort and basically, users might get confused with two routes to create a new workspace.

  15. timszot commented on Aug 6, 2021

    @timszot

    Nice! I like that simple approach here. @arielgreen Let's hire @mananjadhav for this please 🙏

  16. arielgreen commented on Aug 6, 2021

    @arielgreen
    Contributor

    Done! @mananjadhav I also upped the price to include the bonus amount you receive for finding/proposing the issue.

  17. added
    Weekly
    and removed
    Daily
    Help Wanted
    on Aug 6, 2021
  18. mananjadhav commented on Aug 6, 2021

    @mananjadhav
    CollaboratorAuthor

    Thanks, @arielgreen.

  19. mananjadhav commented on Aug 6, 2021

    @mananjadhav
    CollaboratorAuthor

    PR submitted for review.

  20. timszot commented on Aug 11, 2021

    @timszot

    @arielgreen PR is merged for this as of yesterday

  21. changed the title [-]Handle redirects to Invalid PolicyIds in WorkspaceCard and WorkspacePeople screens[/-] [+][Hold for payment 2021-08-17] Handle redirects to Invalid PolicyIds in WorkspaceCard and WorkspacePeople screens[/+] on Aug 13, 2021
  22. arielgreen commented on Aug 17, 2021

    @arielgreen
    Contributor

    Paid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

EngineeringExternalWeekly

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions