Skip to content

Commit

Permalink
Fix infinite loop on studio (#4617)
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw authored Aug 10, 2023
1 parent d5a03e7 commit 4f6aceb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/atlas/src/providers/user/user.provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export const UserProvider: FC<PropsWithChildren> = ({ children }) => {
},
},
{
onCompleted: (data) => {
const activeMembership =
(currentUser?.membershipId &&
data.memberships?.find((membership) => membership.id === currentUser?.membershipId)) ||
null
if (activeMembership) {
setChannelId(activeMembership.channels[0].id)
}
},
skip: !currentUser,
onError: (error) =>
SentryLogger.error('Failed to fetch user memberships', 'UserProvider', error, { user: currentUser ?? {} }),
Expand Down Expand Up @@ -69,10 +78,6 @@ export const UserProvider: FC<PropsWithChildren> = ({ children }) => {
? activeMembership?.channels.find((channel) => channel.id === channelId)
: activeMembership?.channels[0]) || null

useEffect(() => {
if (!channelId) setChannelId(activeMembership?.channels[0]?.id ?? null)
}, [activeMembership?.channels, channelId])

const contextValue: UserContextValue = useMemo(
() => ({
memberships: memberships || [],
Expand Down

0 comments on commit 4f6aceb

Please sign in to comment.