Skip to content

Commit

Permalink
Merge pull request #2693 from MTES-MCT/fix-dashboard-user-permissions
Browse files Browse the repository at this point in the history
Dashboard refonte: fix user permissions qui n'affiche plus les dossier dans la side bar quand on refresh
  • Loading branch information
JulianaJM authored Sep 7, 2023
2 parents 09cde7d + 7404e10 commit 718374b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 13 additions & 1 deletion front/src/Apps/Dashboard/DashboardRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";

Expand All @@ -58,6 +59,7 @@ export const GET_ME = gql`
function DashboardRoutes() {
const { siret } = useParams<{ siret: string }>();
const { data } = useQuery<Pick<Query, "me">>(GET_ME);
const { updatePermissions } = usePermissions();

const history = useHistory();

Expand All @@ -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 <Loader />;
}
Expand Down
14 changes: 1 addition & 13 deletions front/src/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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`
{
Expand All @@ -64,7 +63,6 @@ export const GET_ME = gql`
`;

export default function Dashboard() {
const { updatePermissions } = usePermissions();
const { siret } = useParams<{ siret: string }>();
const { data } = useQuery<Pick<Query, "me">>(GET_ME);

Expand All @@ -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 <Loader />;
}
Expand Down

0 comments on commit 718374b

Please sign in to comment.