Skip to content

Fix login and onboarding flows#2390

Merged
zomars merged 7 commits intocalcom:mainfrom
afzalsayed96:main
Apr 6, 2022
Merged

Fix login and onboarding flows#2390
zomars merged 7 commits intocalcom:mainfrom
afzalsayed96:main

Conversation

@afzalsayed96
Copy link
Copy Markdown
Contributor

What does this PR do?

When you sign up you can notice a slight jitter in the UI with invalid state while redirecting to /get-started route.

Screen.Recording.2022-04-05.at.11.41.35.PM.mov

Similarly when you navigate to a protected page such as /event-types without being logged in you can see a glimpse of the invalid state

Screen.Recording.2022-04-06.at.12.06.06.AM.mov

The root cause of this issue is how useRedirectToLoginIfUnauthenticated and useRedirectToOnboardingIfNeeded hooks are implemented. They both employ useEffect hook to redirect. However, useEffect is run after a render is completed. Hence, we see a glimpse of invalid state as the loading of session/me query finishes but useEffect is yet to run.

The solution is for unauth redirection is simply to check for session value and only then render protected UI. And similarly for onboarding user redirect, it's imperative to check both the result & loading state of me query before rendering anything.

With the above changes, we make sure that protected UI is only shown after consulting the appropriate loading states and the data itself and we get a clean jitter-free transition.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

Unsure

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 5, 2022

@afzalsayed96 is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 5, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

docs – ./apps/docs

🔍 Inspect: https://vercel.com/cal/docs/9xhTruzRTJagGHEKF4xoj9L3oDFL
✅ Preview: Canceled

[Deployment for 5b6f9ee canceled]

calendso – ./apps/web

🔍 Inspect: https://vercel.com/cal/calendso/Fi2q2T3YwMfCuuETx26D9dDHxuJV
✅ Preview: Failed

[Deployment in progress for 5b6f9ee]

@vercel vercel Bot temporarily deployed to Preview – docs April 5, 2022 20:06 Inactive
useEffect(() => {
user && setRedirecting(shouldShowOnboarding(user));
}, [router, user]);
const isRedirectingToOnboarding = user && shouldShowOnboarding(user);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe state is unnecessary here as any change in query will cause a rerender and isRedirectingToOnboarding can be considered a derived or computed state from query.data

Comment thread apps/web/components/Shell.tsx Outdated
@denik1981
Copy link
Copy Markdown
Contributor

@alannnc @zomars
Please check #2337 which provides more tests for the login/logout flow and normalizes the usage of the user fixture to decouple tests from the seed data. This won't help to test code changes in this PR but it will help assure everything is still working

Copy link
Copy Markdown
Member

@alishaz-polymath alishaz-polymath left a comment

Choose a reason for hiding this comment

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

Minor change requested, and additional information requested. It is an improvement on the current state.

Comment thread apps/web/components/Shell.tsx Outdated
Comment thread apps/web/components/Shell.tsx Outdated
Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com>
@vercel vercel Bot temporarily deployed to Preview – docs April 6, 2022 10:28 Inactive
Copy link
Copy Markdown
Contributor

@joeauyeung joeauyeung left a comment

Choose a reason for hiding this comment

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

Hey, great PR! The transitions are now smooth. Just building off of @alishaz-polymath's question about why some of the class names have changed.

Comment thread apps/web/components/Shell.tsx Outdated
@vercel vercel Bot temporarily deployed to Preview – docs April 6, 2022 16:29 Inactive
@vercel vercel Bot temporarily deployed to Preview – docs April 6, 2022 16:31 Inactive
Copy link
Copy Markdown
Contributor

@zomars zomars left a comment

Choose a reason for hiding this comment

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

Reverted unnecessary diffs. Other than that code looks good and tested. Thank you for your contribution 🙏

@vercel vercel Bot temporarily deployed to Preview – calendso April 6, 2022 16:47 Inactive
@vercel vercel Bot temporarily deployed to Preview – docs April 6, 2022 16:48 Inactive
@zomars zomars requested a review from alishaz-polymath April 6, 2022 16:49
Copy link
Copy Markdown
Member

@alishaz-polymath alishaz-polymath left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. Tested, works! 🙏

@vercel vercel Bot temporarily deployed to Preview – calendso April 6, 2022 16:57 Inactive
@zomars zomars enabled auto-merge (squash) April 6, 2022 16:57
@zomars zomars merged commit d340ee6 into calcom:main Apr 6, 2022
@afzalsayed96
Copy link
Copy Markdown
Contributor Author

@zomars @alishaz-polymath thanks for the review and merging. Good call on the early return 🙌

I usually view diffs in GitHub with the hide whitespaces option checked for the same reason.

Screenshot 2022-04-06 at 11 00 35 PM

@zomars
Copy link
Copy Markdown
Contributor

zomars commented Apr 6, 2022

@zomars @alishaz-polymath thanks for the review and merging. Good call on the early return 🙌

I usually view diffs in GitHub with the hide whitespaces option checked for the same reason.

Screenshot 2022-04-06 at 11 00 35 PM

Thanks for the tip, although locally we don't have that option unfortunately.

@denik1981
Copy link
Copy Markdown
Contributor

@afzalsayed96 Thank you for this contribution. Quite helpful!

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.

6 participants