diff --git a/front/src/Apps/Dashboard/DashboardRoutes.tsx b/front/src/Apps/Dashboard/DashboardRoutes.tsx index 945fd0d1c4..0f6ecd4351 100644 --- a/front/src/Apps/Dashboard/DashboardRoutes.tsx +++ b/front/src/Apps/Dashboard/DashboardRoutes.tsx @@ -11,7 +11,7 @@ import { BsdasriSignatureType, Query } from "generated/graphql/types"; import { filter } from "graphql-anywhere"; import { Location } from "history"; import DashboardPage from "Pages/Dashboard"; -import React, { useCallback } from "react"; +import React, { useCallback, useEffect } from "react"; import { generatePath, Redirect, @@ -35,6 +35,7 @@ import { } from "../../dashboard/detail"; import Exports from "../../dashboard/exports/Exports"; import DashboardTabs from "./Components/DashboardTabs/DashboardTabs"; +import { usePermissions } from "common/contexts/PermissionsContext"; import "./dashboard.scss"; @@ -58,6 +59,7 @@ export const GET_ME = gql` function DashboardRoutes() { const { siret } = useParams<{ siret: string }>(); const { data } = useQuery>(GET_ME); + const { updatePermissions } = usePermissions(); const history = useHistory(); @@ -84,6 +86,16 @@ function DashboardRoutes() { }); }, [history, siret]); + useEffect(() => { + if (data) { + const companies = data.me.companies; + const currentCompany = companies.find(company => company.orgId === siret); + if (currentCompany) { + updatePermissions(currentCompany.userPermissions); + } + } + }, [updatePermissions, data, siret]); + if (data?.me == null) { return ; } diff --git a/front/src/dashboard/Dashboard.tsx b/front/src/dashboard/Dashboard.tsx index 6b38cb1beb..b7a79bd301 100644 --- a/front/src/dashboard/Dashboard.tsx +++ b/front/src/dashboard/Dashboard.tsx @@ -1,6 +1,6 @@ import { useQuery, gql } from "@apollo/client"; import { filter } from "graphql-anywhere"; -import React, { useEffect } from "react"; +import React from "react"; import { generatePath, Redirect, @@ -44,7 +44,6 @@ import { RouteBsddRequestRevision } from "./components/RevisionRequestList/bsdd/ import { DashboardTabs } from "./DashboardTabs"; import SideMenu from "common/components/SideMenu"; import { RouteBsdaRequestRevision } from "./components/RevisionRequestList/bsda/request"; -import { usePermissions } from "common/contexts/PermissionsContext"; export const GET_ME = gql` { @@ -64,7 +63,6 @@ export const GET_ME = gql` `; export default function Dashboard() { - const { updatePermissions } = usePermissions(); const { siret } = useParams<{ siret: string }>(); const { data } = useQuery>(GET_ME); @@ -82,16 +80,6 @@ export default function Dashboard() { }), }; - useEffect(() => { - if (data) { - const companies = data.me.companies; - const currentCompany = companies.find(company => company.orgId === siret); - if (currentCompany) { - updatePermissions(currentCompany.userPermissions); - } - } - }, [updatePermissions, data, siret]); - if (data?.me == null) { return ; }