diff --git a/src/pages/TeamOverview/TeamOverview.tsx b/src/pages/TeamOverview/TeamOverview.tsx index 4281c2eb..a3355ab2 100644 --- a/src/pages/TeamOverview/TeamOverview.tsx +++ b/src/pages/TeamOverview/TeamOverview.tsx @@ -9,8 +9,9 @@ import PageSkeleton from '../../components/PageSkeleton/PageSkeleton' import { fetchTeamOverviewData, TeamOverviewData } from '../../services/teamOverview' import { formatDisplayName } from '../../utils/utils' -import { ApiError, fetchUserInformationFromAuthToken } from '../../utils/services' +import { ApiError, fetchUserInformationFromAuthToken, isDaplaAdmin } from '../../utils/services' import FormattedTableColumn from '../../components/FormattedTableColumn/FormattedTableColumn' +import { User } from '../../services/userProfile' const MY_TEAMS_TAB = { title: 'Mine team', @@ -24,6 +25,7 @@ const ALL_TEAMS_TAB = { const TeamOverview = () => { const [activeTab, setActiveTab] = useState(MY_TEAMS_TAB) + const [isSectionManager, SetIsSectionManager] = useState(false) const [teamOverviewData, setTeamOverviewData] = useState() const [teamOverviewTableData, setTeamOverviewTableData] = useState() const [teamOverviewTableTitle, setTeamOverviewTableTitle] = useState(MY_TEAMS_TAB.title) @@ -64,6 +66,27 @@ const TeamOverview = () => { fetchData() }, []) + useEffect(() => { + const userProfileItem = localStorage.getItem('userProfile') + if (!userProfileItem) return + + const user = JSON.parse(userProfileItem) as User + if (!user) return + + const allowViewCreateTeamButton = async () => { + const isAdmin = await isDaplaAdmin(user.principal_name) + if (isAdmin) { + SetIsSectionManager(true) + return + } + if (user.job_title.toLowerCase() === 'seksjonssjef') { + SetIsSectionManager(true) + } + } + + allowViewCreateTeamButton() + }, []) + useEffect(() => { if (teamOverviewData) { if (teamTab === MY_TEAMS_TAB.path) { @@ -138,9 +161,13 @@ const TeamOverview = () => { title='Teamoversikt' content={renderContent()} button={ - + <> + {teamOverviewData && isSectionManager && ( + + )} + } /> ) diff --git a/src/services/userProfile.ts b/src/services/userProfile.ts index e0cebaaf..85a75ce6 100644 --- a/src/services/userProfile.ts +++ b/src/services/userProfile.ts @@ -30,10 +30,11 @@ interface TeamManager { principal_name: string } -interface User { +export interface User { display_name: string principal_name: string section_name: string + job_title: string azure_ad_id?: string first_name?: string last_name?: string @@ -57,6 +58,7 @@ export const getUserProfile = async (principalName: string): Promise