Skip to content

Commit

Permalink
Merge pull request #466 from nickgros/SWC-6552
Browse files Browse the repository at this point in the history
SWC-6552 - Fix UserOrTeamBadge showing stale data
  • Loading branch information
jay-hodgson authored Sep 11, 2023
2 parents 85dc754 + abbd5f0 commit 883041a
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Skeleton } from '@mui/material'
import React, { useEffect, useState } from 'react'
import { useGetUserGroupHeader } from '../../synapse-queries/user/useUserGroupHeader'
import { useSynapseContext } from '../../utils/context/SynapseContext'
import React from 'react'
import { useGetUserGroupHeader } from '../../synapse-queries'
import { UserGroupHeader } from '@sage-bionetworks/synapse-types'
import TeamBadge from '../TeamBadge'
import { UserBadge } from '../UserCard/UserBadge'
Expand Down Expand Up @@ -29,23 +28,14 @@ export default function UserOrTeamBadge(props: UserOrTeamBadgeProps) {
principalId = providedUserGroupHeader?.ownerId
}

const { accessToken } = useSynapseContext()
const [userGroupHeader, setUserGroupHeader] = useState<
UserGroupHeader | undefined
>(providedUserGroupHeader)

const { data: fetchedUserGroupHeader } = useGetUserGroupHeader(
(principalId ?? '').toString(),
{
enabled: !providedUserGroupHeader,
},
)

useEffect(() => {
if (principalId && userGroupHeader == undefined && fetchedUserGroupHeader) {
setUserGroupHeader(fetchedUserGroupHeader)
}
}, [accessToken, principalId, userGroupHeader, fetchedUserGroupHeader])
const userGroupHeader = providedUserGroupHeader ?? fetchedUserGroupHeader

if (principalId == null && providedUserGroupHeader == null) {
console.error(
Expand Down

0 comments on commit 883041a

Please sign in to comment.