Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
82bae0f0
Unverified
Commit
82bae0f0
authored
2 years ago
by
Douglas Fabris
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: Unauthorized Toast Message when accessing a channel's team that user are not a member (#28670)
parent
a08a702d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/meteor/client/views/room/Header/ParentTeam.tsx
+35
-26
35 additions, 26 deletions
apps/meteor/client/views/room/Header/ParentTeam.tsx
with
35 additions
and
26 deletions
apps/meteor/client/views/room/Header/ParentTeam.tsx
+
35
−
26
View file @
82bae0f0
import
type
{
IRoom
}
from
'
@rocket.chat/core-typings
'
;
import
{
TEAM_TYPE
}
from
'
@rocket.chat/core-typings
'
;
import
{
Header
}
from
'
@rocket.chat/ui-client
'
;
import
{
useUserId
}
from
'
@rocket.chat/ui-contexts
'
;
import
{
useUserId
,
useEndpoint
}
from
'
@rocket.chat/ui-contexts
'
;
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
type
{
ReactElement
}
from
'
react
'
;
import
React
,
{
useMemo
}
from
'
react
'
;
import
React
from
'
react
'
;
import
{
AsyncStatePhase
}
from
'
../../../hooks/useAsyncState
'
;
import
{
useEndpointData
}
from
'
../../../hooks/useEndpointData
'
;
import
{
goToRoomById
}
from
'
../../../lib/utils/goToRoomById
'
;
type
ParentTeamProps
=
{
room
:
IRoom
;
};
type
APIErrorResult
=
{
success
:
boolean
;
error
:
string
};
const
ParentTeam
=
({
room
}:
ParentTeamProps
):
ReactElement
|
null
=>
{
const
ParentTeam
=
({
room
}:
{
room
:
IRoom
}
):
ReactElement
|
null
=>
{
const
{
teamId
}
=
room
;
const
userId
=
useUserId
();
...
...
@@ -25,16 +22,26 @@ const ParentTeam = ({ room }: ParentTeamProps): ReactElement | null => {
throw
new
Error
(
'
invalid uid
'
);
}
const
{
value
,
phase
}
=
useEndpointData
(
'
/v1/teams.info
'
,
{
params
:
useMemo
(()
=>
({
teamId
}),
[
teamId
])
});
const
teamsInfoEndpoint
=
useEndpoint
(
'
GET
'
,
'
/v1/teams.info
'
);
const
userTeamsListEndpoint
=
useEndpoint
(
'
GET
'
,
'
/v1/users.listTeams
'
);
const
{
value
:
userTeams
,
phase
:
userTeamsPhase
}
=
useEndpointData
(
'
/v1/users.listTeams
'
,
{
params
:
useMemo
(()
=>
({
userId
}),
[
userId
]),
const
{
data
:
teamInfoData
,
isLoading
:
teamInfoLoading
,
isError
:
teamInfoError
,
}
=
useQuery
([
'
teamId
'
,
teamId
],
async
()
=>
teamsInfoEndpoint
({
teamId
}),
{
refetchOnWindowFocus
:
false
,
keepPreviousData
:
true
,
retry
:
(
_
,
error
)
=>
(
error
as
APIErrorResult
)?.
error
===
'
unauthorized
'
&&
false
,
});
const
belongsToTeam
=
userTeams
?.
teams
?.
find
((
team
)
=>
team
.
_id
===
teamId
)
||
false
;
const
isTeamPublic
=
value
?.
teamInfo
.
type
===
TEAM_TYPE
.
PUBLIC
;
const
{
data
:
userTeams
,
isLoading
:
userTeamsLoading
}
=
useQuery
([
'
userId
'
,
userId
],
async
()
=>
userTeamsListEndpoint
({
userId
}));
const
userBelongsToTeam
=
userTeams
?.
teams
?.
find
((
team
)
=>
team
.
_id
===
teamId
)
||
false
;
const
isTeamPublic
=
teamInfoData
?.
teamInfo
.
type
===
TEAM_TYPE
.
PUBLIC
;
const
teamMainRoomHref
=
():
void
=>
{
const
rid
=
value
?.
teamInfo
.
roomId
;
const
rid
=
teamInfoData
?.
teamInfo
.
roomId
;
if
(
!
rid
)
{
return
;
...
...
@@ -43,27 +50,29 @@ const ParentTeam = ({ room }: ParentTeamProps): ReactElement | null => {
goToRoomById
(
rid
);
};
if
(
phase
===
AsyncStatePhase
.
LOADING
||
userTeamsPhase
===
AsyncStatePhase
.
LOADING
)
{
if
(
teamInfoLoading
||
userTeamsLoading
)
{
return
<
Header
.
Tag
.
Skeleton
/>;
}
if
(
phase
===
AsyncStatePhase
.
REJECTED
||
!
value
?.
teamInfo
)
{
if
(
teamInfo
Error
)
{
return
null
;
}
return
(
<
Header
.
Tag
>
{
isTeamPublic
||
belongsToTeam
?
(
if
(
isTeamPublic
||
userBelongsToTeam
)
{
return
(
<
Header
.
Tag
>
<
Header
.
Link
onClick
=
{
teamMainRoomHref
}
>
<
Header
.
Tag
.
Icon
icon
=
{
{
name
:
isTeamPublic
?
'
team
'
:
'
team-lock
'
}
}
/>
{
value
.
teamInfo
.
name
}
{
teamInfoData
?
.
teamInfo
.
name
}
</
Header
.
Link
>
)
:
(
<>
<
Header
.
Tag
.
Icon
icon
=
{
{
name
:
isTeamPublic
?
'
team
'
:
'
team-lock
'
}
}
/>
{
value
.
teamInfo
.
name
}
</>
)
}
</
Header
.
Tag
>
);
}
return
(
<
Header
.
Tag
>
<
Header
.
Tag
.
Icon
icon
=
{
{
name
:
isTeamPublic
?
'
team
'
:
'
team-lock
'
}
}
/>
{
teamInfoData
?.
teamInfo
.
name
}
</
Header
.
Tag
>
);
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment