diff --git a/src/pages/TeamDetail/TeamDetail.tsx b/src/pages/TeamDetail/TeamDetail.tsx index a78b2abb..cbdbc13d 100644 --- a/src/pages/TeamDetail/TeamDetail.tsx +++ b/src/pages/TeamDetail/TeamDetail.tsx @@ -6,7 +6,7 @@ import { useCallback, useContext, useEffect, useState } from 'react' import PageLayout from '../../components/PageLayout/PageLayout' import { TeamDetailData, getTeamDetail, Team, SharedBuckets, Group } from '../../services/teamDetail' import { useParams, useNavigate } from 'react-router-dom' -import { ApiError, TokenData, fetchUserInformationFromAuthToken } from '../../utils/services' +import { ApiError, TokenData, fetchUserInformationFromAuthToken, isDaplaAdmin } from '../../utils/services' import { DaplaCtrlContext } from '../../provider/DaplaCtrlProvider' import Table, { TableData } from '../../components/Table/Table' @@ -73,6 +73,7 @@ const TeamDetail = () => { const [loadingUsers, setLoadingUsers] = useState(false) const [teamDetailData, setTeamDetailData] = useState() const [userData, setUserData] = useState() + const [isManager, setIsManager] = useState(false) const [teamDetailTableTitle, setTeamDetailTableTitle] = useState(TEAM_USERS_TAB.title) const [teamDetailTableHeaderColumns, setTeamDetailTableHeaderColumns] = useState( TEAM_USERS_TAB.columns @@ -157,9 +158,25 @@ const TeamDetail = () => { [activeTab] ) - const isTeamManager = useCallback(() => { - const teamManagers = (teamDetailData && (teamDetailData.team as Team).managers) ?? [] - return teamManagers?.some((manager) => manager.principal_name.toLowerCase() === tokenData?.email.toLowerCase()) + useEffect(() => { + const checkIsTeamManager = async () => { + const teamManagers = (teamDetailData && (teamDetailData.team as Team).managers) ?? [] + if (tokenData) { + const isAdmin = await isDaplaAdmin(tokenData.email.toLowerCase()) + if (isAdmin) { + setIsManager(true) + return + } + const isManagerResult = teamManagers.some( + (manager) => manager.principal_name.toLowerCase() === tokenData.email.toLowerCase() + ) + setIsManager(isManagerResult) + } else { + setIsManager(false) + } + } + + checkIsTeamManager() }, [tokenData, teamDetailData]) useEffect(() => { @@ -208,7 +225,7 @@ const TeamDetail = () => { }, [refreshData]) useEffect(() => { - if (isTeamManager()) { + if (isManager) { setTeamDetailTableHeaderColumns([ ...TEAM_USERS_TAB.columns, { @@ -219,7 +236,7 @@ const TeamDetail = () => { }, ]) } - }, [isTeamManager]) + }, [isManager]) useEffect(() => { if (teamDetailData) { @@ -228,7 +245,7 @@ const TeamDetail = () => { setTeamDetailTableHeaderColumns(SHARED_BUCKETS_TAB.columns) } else { setTeamDetailTableTitle(TEAM_USERS_TAB.title) - if (isTeamManager()) { + if (isManager) { setTeamDetailTableHeaderColumns([ ...TEAM_USERS_TAB.columns, { @@ -361,7 +378,7 @@ const TeamDetail = () => { } content={renderContent()} button={ - isTeamManager() && teamDetailData ? ( + isManager && teamDetailData ? ( ) : undefined }