jwplayer / ott-web-app

Reference implementation for JWP-powered apps
Apache License 2.0
70 stars 52 forks source link

Fix: redirect when no integration is configured #474

Closed ChristiaanScheermeijer closed 6 months ago

ChristiaanScheermeijer commented 6 months ago

Description

When navigating directly to a user page (/u/payments) when no integration is configured, an infinite spinner shows, this is caused by the AccountStore#loading state being set to true initially, but this is never reset to false when no integration is initialized.

CC: @langemike (can't assign as a reviewer)

github-actions[bot] commented 6 months ago

Visit the preview URL for this PR (updated for commit 966d38f):

https://ottwebapp--pr474-fix-redirect-user-wh-5c4441md.web.app

(expires Sun, 28 Apr 2024 10:11:23 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: c198f8a3a199ba8747819f7f1e45cf602b777529

ChristiaanScheermeijer commented 6 months ago

Thanks @langemike, the redirect logic is already in place in the User.tsx page:

https://github.com/jwplayer/ott-web-app/blob/71433abfca80431243effc246afdbe8c6901521e/packages/ui-react/src/pages/User/User.tsx#L70-L74

But the condition is never met because of the loading state permanently being set to true.

ChristiaanScheermeijer commented 6 months ago

I also have an alternative solution by inversing the logic.

  1. We set the AccountStore#loading property to false
  2. When we call UserService#initialize we first set the loading state to true

Because the app defers rendering the route until the AccountStore is initialized, the result should be the same...

AntonLantukh commented 6 months ago

@ChristiaanScheermeijer I think I would prefer having false by default. It is just intuitively clear.

ChristiaanScheermeijer commented 6 months ago

@AntonLantukh updated the PR. We already set the loading state to true in the AccountController#initialize, so only the default state had to be updated 😄

AntonLantukh commented 6 months ago

@ChristiaanScheermeijer thank you!